Cause of delay in CAN

I am dealing with a differential drive robot that interacts with several motors and actuators, all through the Jetson Xavier. I use Python3 for programming all actions of the robot that go through a microcontroller via CAN bus.

Now, there are multiple parts of the robot that we need to program; chiefly navigation and arm-movement. Right now, the robot does only either of them, i.e., it can either move or perform some arm-movement. All the actions are based on the same 1D LiDAR sensor.
enter image description here
To boost its speed, I thought of performing both these functions in parallel, as they are almost independent of the other. Python provides two wonderful options for this: multi-processing and threading. Both of them seem equally good options with the caveat that threads cannot be killed and prove negligible improvement when compared to multi-processing. So, I am staying with multi-processing for the time-being.

Now, the way I use the sensor or lidar values is, to get them via a thread and continuously dump them as global variables.

t = Thread(target=dump_lidar_data,args=())

Various functions defined in the same file, use these values as:

def fun():
    global lidar1
    print(f'Look, I too can access lidar 1 values: {lidar1}')

The main process or the parent process detects when its show time and spawns two child processes: p_navigation and p_arm. Both these process start together and have their own instance of dump_lidar working in their respective processors. Both terminate on the basis of the same condition. In the meantime, the parent process does nothing.
enter image description here

I notice that there is a considerable delay (upto 1s) between the data procured by the dump_lidar in the parent process as compared to the ones in the child processes. It is also possible that the CAN bus is giving the data after a certain delay.

Is there a possibility that the CAN or the circuit involved in getting the data to the Jetson, cause this delay ? or the system being non-RTOS, may be the culprit ?

Hi pradan,
Since you connected MCU and then sensor, are you saying, receiving data from Jetson CAN to MCU is delaying by 1sec? Did you check when the data reaches in MCU (if possible).
Also, I would like to know which transceiver have you connected?


Actually, as indicated in the diagram, the data flow from the sensor to the Jetson is as follows:
sensor -> MCU -> transceiver -> Jetson

So, the delay is observed in Jetson. I am not sure if I will be able to check when the MCU receives the CAN message (if thats what you mean).

I will share the transceiver in some time.

Ok understood, no need to check MCU side timing. Please share transceiver, also the Jetson CAN bitrate you have set to?

I got it done by checking that all the data was being reported as incorrect format by using dmesg | grep "can" and then asking jetson to take in all values irrespective of their potential error in format.

$ sudo ifconfig can0 down
$ sudo ip link set can0 up type can bitrate 500000 sjw 127 dbitrate 2000000 dsjw 15 berr-reporting on fd on

And now every sensor gives data :)