From 89b31949145c78295ab77914328e57a1f1779615 Mon Sep 17 00:00:00 2001 From: ryleu <69326171+ryleu@users.noreply.github.com> Date: Thu, 2 Apr 2026 19:41:05 -0500 Subject: [PATCH] update documentation and accept 3-value VicCAN messages --- src/anchor_pkg/anchor_pkg/anchor_node.py | 5 ++++- src/anchor_pkg/anchor_pkg/connector.py | 4 +++- src/anchor_pkg/anchor_pkg/convert.py | 2 ++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/anchor_pkg/anchor_pkg/anchor_node.py b/src/anchor_pkg/anchor_pkg/anchor_node.py index 8edc8b5..b9cf992 100644 --- a/src/anchor_pkg/anchor_pkg/anchor_node.py +++ b/src/anchor_pkg/anchor_pkg/anchor_node.py @@ -42,6 +42,9 @@ class Anchor(Node): - Core, Arm, and Bio publish VicCAN messages to this topic to send to the MCU * /anchor/to_vic/relay_string - Send raw strings to connectors. Does not work for connectors that require conversion (like CANConnector) + * /anchor/relay + - Legacy method for talking to connectors. Takes String as input, but does not send the raw strings to connectors. + Instead, it converts them to VicCAN messages first. """ connector: Connector @@ -203,7 +206,7 @@ class Anchor(Node): self.connector.write(msg) self.tovic_debug_pub_.publish(msg) - @deprecated("Use /anchor/to_vic/relay 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 diff --git a/src/anchor_pkg/anchor_pkg/connector.py b/src/anchor_pkg/anchor_pkg/connector.py index e9859bb..0e8fffe 100644 --- a/src/anchor_pkg/anchor_pkg/connector.py +++ b/src/anchor_pkg/anchor_pkg/connector.py @@ -372,8 +372,10 @@ class CANConnector(Connector): case 2: data_type = 1 data = struct.pack(">ff", *msg.data) - case 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] data = struct.pack(">hhhh", *[int(x) for x in msg.data]) case _: self.logger.error( diff --git a/src/anchor_pkg/anchor_pkg/convert.py b/src/anchor_pkg/anchor_pkg/convert.py index cfecfce..57b2c44 100644 --- a/src/anchor_pkg/anchor_pkg/convert.py +++ b/src/anchor_pkg/anchor_pkg/convert.py @@ -57,6 +57,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") # 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"