0

I have a robot that is moving when it received the CAN message. So, on the robot side I have only one Port for CAN message receiving but I am giving the CAN message from two difference controller, one is from Arduino that receives message from a remote controller and the 2nd is from my laptop thatbconnect with a CAN to UsB cable. What i want to switch between these two messages. For now i am always changing the CAN cable manually. I want to know that is there any CAN switch available or any other way to switch???

Now I am trying to changing the port everytime.

1
  • 1
    It is not clear why all nodes can't co-exist on the same bus. That's trivial to achieve during CAN protocol design. What protocol are you using, something home made I assume? Commented Nov 26, 2024 at 9:06

1 Answer 1

0

Physical connection

All you need is to connect all devices in one CAN network. Note that only two terminators (resistors) shall be there. Your network should look like this:

+---------+--------+---------+--------+ CAN_H
[120Ω]    |        |         |     [120Ω]
+----------+--------+---------+-------+ CAN_L
          ||       ||        ||       
         Robot   Arduino   Laptop

Communication

Option 1

You might configure each device in a different way, for example:

  • Laptop sends frames with CAN ID = 0x100 (,0x101, 0x102, ... etc if you need more CAN IDs)
  • Arduino sends frames with CAN ID = 0x200 (,0x201, 0x202,...)
  • Robot listens to all CAN IDs transmitted by either node (Laptop and Arduino) and is programmed to act accordingly.

Option 2

  • Laptop and Arduino send the same frames (CAN IDs are the same) and simulating the same controlling CAN node.
  • Robot listens to all CAN IDs transmitted by controlling node (either Laptop or Arduino).
  • No need to update Robot code in this case.

Warning

If both Arduino and laptop would try to control your robot at the same time, it would get duplicated or requests in contradiction. Also it might cause errors on CAN network. I strongly recommend to avoid situations with two devices simulating the same CAN node at the same time as it might cause undefined behavior, CAN devices go to ERROR state or even damage to your robot.

Some Knowledge Sources

Other Comments

This question is not code related, so it does not belong to Stackoverflow (check other spaces for more suitable one).

Sign up to request clarification or add additional context in comments.

5 Comments

Two CAN nodes aren't allowed to send the same identifier at the same time. Apart from it likely being senseless on the application level, this will also lead to bus collisions. Therefore this should be considered when designing the CAN protocol.
Two different nodes are not supposed to sent CAN ID with the same Identifiers (cause you won't be able to distinguish them, but it won't affect the network itself), but what I described here is that you might simulate the same node from different device (either laptop or Arduino). In option 1 you have 3 nodes - 1 actuator (robot) and 2 controllers (Arduino and Laptop). In option 2 you have 2 nodes - 1 actuator (robot) and 1 controller (either Arduino or Laptop). Option 1 looks better on paper and might be safer, option 2 is easier to implement.
It's not about distinguishing - raw CAN traffic is data-based not node-based - but about not having physical CAN bus collisions because two nodes trying to pull the bus in different directions when sending the same message. CSMA/CA only works during the arbitration part of the frame. Once past the arbitration part with neither node yielding, because the messages were the same, you get collisions and then error frames which will affect the network itself.
@Lundin I bolded crucial part of the warning. If you want to be more precise, please edit the response. Right now you are just fixating and going into discussion (which leads to nowhere) on a part which is not important as OP is informed about potential danger.
I was mostly remarking on option 2 not being an option at all.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.