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).