Publishing messages at 10ms rate
Hi,
I am using PCAN-USB Interface to communicate to CAN bus in the vehicle. I am using Ubuntu 16.04, ROS kinetic with Socketcan/socketcan_bridge. I can read CAN signals and also write to it in general. However, I am facing problems when I have to publish @10ms rate which is required for my application. When I publish, it fails to send the message.
My code is such that I am subscribing to a topic in a callback, then building a message of type can_msgs::Frame in the callback. Now, if I publish from within this callback on sent_messages topic, I see that the message is sent successfully to the bus.
However, I have to ensure the message should be sent at 10ms rate and hence I have created a timer in ROS (ros::Timer) and then publishing the message I want (which is a global variable in my class definition) from the timercallback. When I do this, the message is not sent and the console output is as above. Please suggest
Hi,
Can you provide any code or output. In general, to achieve what you want it is better to publish out of callbacks since you do not have any control over the rate at witch callbacks are called, hence you will not have any control over the rate of your publisher.
Did you try to implement two different nodes:
can_reader
andcan_writer
and sync them with a heartbeat?@Weasfas, thank you. i have to publish this message at 10ms for an actuation to happen in the vehicle. Publishing within subscribe callback will have no control on the publish rate and hence i am using timercallback only for publish. I guess you meant subscribe callback when you said there is no control over rate. With underlying resources permitting, i guess this timercallback should publish at the asked rate. pls let me know
@prj1508 As far as I understood your comment, a Timer can do the trick, publishing in the timer callback (AKA timer timeout), this code snipped maybe help you: