clean up code

This commit is contained in:
ryleu
2026-04-07 22:16:08 -05:00
parent bc9183d59a
commit ec7f272934
3 changed files with 7 additions and 8 deletions

View File

@@ -175,7 +175,7 @@ class Anchor(Node):
self.mock_mcu_sub_ = self.create_subscription(
String,
"/anchor/from_vic/mock_mcu",
self.on_mock_fromvic,
self.relay_fromvic,
20,
)
self.tovic_string_sub_ = self.create_subscription(
@@ -206,7 +206,9 @@ class Anchor(Node):
self.connector.write(msg)
self.tovic_debug_pub_.publish(msg)
@deprecated("Use /anchor/to_vic/relay or /anchor/to_vic/relay_string instead of /anchor/relay")
@deprecated(
"Use /anchor/to_vic/relay or /anchor/to_vic/relay_string instead of /anchor/relay"
)
def write_connector_legacy(self, msg: String):
"""Write to the connector by first attempting to convert String to VicCAN"""
# please do not reference this code. ~riley
@@ -229,10 +231,6 @@ class Anchor(Node):
elif msg.mcu_name == "citadel" or msg.mcu_name == "digit":
self.fromvic_bio_pub_.publish(msg)
def on_mock_fromvic(self, msg: VicCAN):
"""Relay a message as if it came from the MCU"""
self.relay_fromvic(msg)
def main(args=None):
try:

View File

@@ -372,7 +372,7 @@ class CANConnector(Connector):
case 2:
data_type = 1
data = struct.pack(">ff", *msg.data)
case 3 | 4: # 3 gets padded and is treated as 4
case 3 | 4: # 3 gets padded and is treated as 4
data_type = 2
# pad till we have 4 otherwise struct.pack will freak out
msg.data = (msg.data + [0])[:4]

View File

@@ -58,7 +58,8 @@ def string_to_viccan(
def viccan_to_string(viccan: VicCAN) -> str:
"""Converts a ROS2 VicCAN message to the serial string VicCAN format."""
# make sure we accept 3 digits and treat it as 4
if len(viccan.data) == 3: viccan.data.append("0")
if len(viccan.data) == 3:
viccan.data.append("0")
# go from [ w, x, y, z ] -> ",w,x,y,z" & round to 7 digits max
data = "".join([f",{round(val,7)}" for val in viccan.data])
return f"can_relay_tovic,{viccan.mcu_name},{viccan.command_id}{data}\n"