mirror of
https://github.com/SHC-ASTRA/rover-ros2.git
synced 2026-04-20 11:51:16 -05:00
Compare commits
3 Commits
410d3706ed
...
b09b55bee0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b09b55bee0 | ||
|
|
ec7f272934 | ||
|
|
bc9183d59a |
@@ -84,7 +84,7 @@ $ ros2 topic pub /anchor/to_vic/relay astra_msgs/msg/VicCAN '{mcu_name: "core",
|
|||||||
To emulate receiving data from a microcontroller, publish to the dedicated topic:
|
To emulate receiving data from a microcontroller, publish to the dedicated topic:
|
||||||
|
|
||||||
```bash
|
```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"}'
|
$ ros2 topic pub /anchor/from_vic/mock_mcu astra_msgs/msg/VicCAN '{mcu_name: "arm", command_id: 55, data: [0.0, 450.0, 900.0, 0.0]}'
|
||||||
```
|
```
|
||||||
|
|
||||||
### Testing Serial
|
### Testing Serial
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ class Anchor(Node):
|
|||||||
|
|
||||||
Subscribers:
|
Subscribers:
|
||||||
* /anchor/from_vic/mock_mcu
|
* /anchor/from_vic/mock_mcu
|
||||||
- For testing without an actual MCU, publish strings here as if they came from an MCU
|
- For testing without an actual MCU, publish ViCAN messages here as if they came from an MCU
|
||||||
* /anchor/to_vic/relay
|
* /anchor/to_vic/relay
|
||||||
- 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
|
||||||
@@ -175,7 +175,7 @@ class Anchor(Node):
|
|||||||
self.mock_mcu_sub_ = self.create_subscription(
|
self.mock_mcu_sub_ = self.create_subscription(
|
||||||
String,
|
String,
|
||||||
"/anchor/from_vic/mock_mcu",
|
"/anchor/from_vic/mock_mcu",
|
||||||
self.on_mock_fromvic,
|
self.relay_fromvic,
|
||||||
20,
|
20,
|
||||||
)
|
)
|
||||||
self.tovic_string_sub_ = self.create_subscription(
|
self.tovic_string_sub_ = self.create_subscription(
|
||||||
@@ -206,7 +206,9 @@ 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 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):
|
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
|
||||||
@@ -229,17 +231,6 @@ class Anchor(Node):
|
|||||||
elif msg.mcu_name == "citadel" or msg.mcu_name == "digit":
|
elif msg.mcu_name == "citadel" or msg.mcu_name == "digit":
|
||||||
self.fromvic_bio_pub_.publish(msg)
|
self.fromvic_bio_pub_.publish(msg)
|
||||||
|
|
||||||
def on_mock_fromvic(self, msg: String):
|
|
||||||
"""Relay a message as if it came from the MCU"""
|
|
||||||
viccan = string_to_viccan(
|
|
||||||
msg.data,
|
|
||||||
"mock",
|
|
||||||
self.get_logger(),
|
|
||||||
self.get_clock().now().to_msg(),
|
|
||||||
)
|
|
||||||
if viccan:
|
|
||||||
self.relay_fromvic(viccan)
|
|
||||||
|
|
||||||
|
|
||||||
def main(args=None):
|
def main(args=None):
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -372,10 +372,11 @@ 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 3 | 4: # 3 gets padded and is treated as 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
|
# pad till we have 4 otherwise struct.pack will freak out
|
||||||
msg.data = (msg.data + [0])[:4]
|
msg.data.append(0)
|
||||||
|
msg.data = msg.data[: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(
|
||||||
|
|||||||
@@ -58,7 +58,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
|
# 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
|
# 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"
|
||||||
|
|||||||
Reference in New Issue
Block a user