Socketcan publish rate

asked 2019-04-22 16:56:34 -0600

roskinetic gravatar image

updated 2019-04-23 01:16:09 -0600

gvdhoorn gravatar image


I am having this programming question:

int main()



s = socket(PF_CAN, SOCK_RAW, CAN_RAW):

  ros::Rate loop_rate(20.83333);



    nbytes = read(s, &frame, sizeof(struct can_frame));

    ... (data process)






I am receiving a data through CAN every 48ms and trying to publish the data.

Instead of setting the rate to be 48ms, is there a better way of programming which represents like

whenever it receives CAN data, process the data and then publish it?

Because the above code involves data process, the loop rate may not be the same as the CAN data rate which is 48ms.

Any help will be appreciated!

edit retag flag offensive close merge delete