Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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!

Socketcan publish rate

Hi,

I am having this programming question:

int main() { ... main()

{

...

s = socket(PF_CAN, SOCK_RAW, CAN_RAW): CAN_RAW):

ros::Rate loop_rate(20.83333); while(ros::ok()) { 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();
  }
}

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!

Socketcan publish rate

Hi,

I am having this programming question:

int main()

main() {

{

...

...

s = socket(PF_CAN, SOCK_RAW, CAN_RAW):

CAN_RAW): ros::Rate loop_rate(20.83333);

ros::Rate loop_rate(20.83333);

while(ros::ok()) {

while(ros::ok())

{

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

 ... (data process)

   msg.publish(data);

   ros::spin();

   loop_rate.sleep();

  }

}

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!