Robotics StackExchange | Archived questions

Socketcan publish rate

Hi,

I am having this programming question:

int main()

{

...

s = socket(PF_CAN, SOCK_RAW, CAN_RAW):

  ros::Rate loop_rate(20.83333);

 while(ros::ok())

  {

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

    ... (data process)

   msg.publish(data);

   ros::spin();

   loop_rate.sleep();

  }

}

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!

Asked by roskinetic on 2019-04-22 16:56:34 UTC

Comments

Answers