ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Best practices working with isolated CAN devices using socketCAN?

asked 2022-10-05 00:54:32 -0500

Klaus Lex gravatar image

updated 2022-10-05 00:59:59 -0500

Hey there! :)

I'm currently working with 2 CAN-devices controlled via ROS & socketCAN & would like to keep them separate, albeit being controlled from one machine running each corresponding control node. What would be a viable approach to this?

Since socketCAN uses a single CAN instance (vcan0) with 2 topics (sent_messages & received_messages) - wouldn't that require launching a 2nd modified socketCAN instance to work with a new vcan1, bridging 2 new topics (sent_messages_1 & received_messages_1) to the 2nd control node to keep them separate?

While this seems like an obvious solution, this also doesn't feel quite right, hence I wonder if there is a better solution to this?

Thanks a bunch!

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2022-10-09 04:57:54 -0500

sgvandijk gravatar image

I think @bjv-capra provided good points about the physical side of things. From your question though it looks like you are already using socketcan_bridge, and your question may boil down to how to run two copies of it without them publishing on the same topic.

If so, that can be done using remapping of the topics. It may be that you are already referring to that, and in that case then the simple answer is: yes, that's exactly the right solution for running 2 separate instances of the same driver for multiple devices.

If you are not fully familiar with remapping, have a look at the documentation on Remapping Arguments.

For your specific case, I would choose to do something like this:


# Run first instance of socket bridge for vcan0
rosrun socketcan_bridge socketcan_bridge_node \
  _can_device:="vcan0" \
  sent_messages:=vcan0/sent_messages \
  received_messages:=vcan0/received_messages

# In another terminal, run second instance of socket bridge for vcan1
rosrun socketcan_bridge socketcan_bridge_node \
  _can_device:="vcan1" \
  sent_messages:=vcan1/sent_messages \
  received_messages:=vcan1/received_messages

Now you have 2 pairs of sent/received message topics, with their names prefixed with the respective CAN device. So a bit nicer than sent_messages_1 and sent_messages_2.

For your controllers you can pass the same mapping arguments to have them work with the correct topics of the device they are supposed to control.

If you use launch files to launch your nodes, you can use the <remap> tag to achieve the same.

edit flag offensive delete link more
0

answered 2022-10-08 16:17:03 -0500

bjv-capra gravatar image

I may be lacking some understanding of your setup, however, if you have 2 CAN devices and they don't talk to each other, it would imply each device is on its own physical BUS. If this is the case, and depending on the CAN adapter you use, I'd agree you would have

  • 1 interface socketCan interface per BUS
  • 1 Node that would use some socketcan library (python or C++)

However, do the devices need to be on a different bus? I.e. a physical requirement, each device has different configurations for transmitting, they can't be configured to transmit on different IDs and the traffic would collide?

If you want to keep the control of CAN on a different node, then you could simply have a node that converts from socketCAN to some ROS topic (I believe there's some ROS industrial package that could do it). And then you could have each control node, talk to this node to send messages over CAN. Hope it makes sense :)

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2022-10-05 00:54:32 -0500

Seen: 376 times

Last updated: Oct 09 '22