2 Commits

Author SHA1 Message Date
ryleu
410d3706ed update README with mock connector instructions 2026-04-02 19:49:07 -05:00
ryleu
89b3194914 update documentation and accept 3-value VicCAN messages 2026-04-02 19:43:10 -05:00
4 changed files with 22 additions and 2 deletions

View File

@@ -74,6 +74,19 @@ You can see all data sent to it in a string format with this command:
$ ros2 topic echo /anchor/to_vic/debug $ ros2 topic echo /anchor/to_vic/debug
``` ```
To send data to it, use the normal topic:
```bash
$ ros2 topic pub /anchor/to_vic/relay astra_msgs/msg/VicCAN '{mcu_name: "core", command_id: 50, data: [0.0, 2.0, 0.0, 1.0]}'
```
To emulate receiving data from a microcontroller, publish to the dedicated topic:
```bash
$ ros2 topic pub /anchor/from_vic/mock_mcu std_msgs/msg/String '{data: "can_relay_fromvic,arm,55,0.0,450.0,900.0,0.0"}'
```
### Testing Serial ### Testing Serial
You can fake the presence of a Serial device (i.e., MCU) by using the following command: You can fake the presence of a Serial device (i.e., MCU) by using the following command:

View File

@@ -42,6 +42,9 @@ class Anchor(Node):
- Core, Arm, and Bio publish VicCAN messages to this topic to send to the MCU - Core, Arm, and Bio publish VicCAN messages to this topic to send to the MCU
* /anchor/to_vic/relay_string * /anchor/to_vic/relay_string
- Send raw strings to connectors. Does not work for connectors that require conversion (like CANConnector) - 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 connector: Connector
@@ -203,7 +206,7 @@ class Anchor(Node):
self.connector.write(msg) self.connector.write(msg)
self.tovic_debug_pub_.publish(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): def write_connector_legacy(self, msg: String):
"""Write to the connector by first attempting to convert String to VicCAN""" """Write to the connector by first attempting to convert String to VicCAN"""
# please do not reference this code. ~riley # please do not reference this code. ~riley

View File

@@ -372,8 +372,10 @@ class CANConnector(Connector):
case 2: case 2:
data_type = 1 data_type = 1
data = struct.pack(">ff", *msg.data) data = struct.pack(">ff", *msg.data)
case 4: case 3 | 4: # 3 gets padded and is treated as 4
data_type = 2 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]) data = struct.pack(">hhhh", *[int(x) for x in msg.data])
case _: case _:
self.logger.error( self.logger.error(

View File

@@ -57,6 +57,8 @@ def string_to_viccan(
def viccan_to_string(viccan: VicCAN) -> str: def viccan_to_string(viccan: VicCAN) -> str:
"""Converts a ROS2 VicCAN message to the serial string VicCAN format.""" """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 # 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]) data = "".join([f",{round(val,7)}" for val in viccan.data])
return f"can_relay_tovic,{viccan.mcu_name},{viccan.command_id}{data}\n" return f"can_relay_tovic,{viccan.mcu_name},{viccan.command_id}{data}\n"