ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Publishing a message in an interrupt

asked 2016-05-20 05:49:46 -0500

Loreno gravatar image

Hi,

I don't want to publish messages in while(ros::ok) loop, but rather when an interrupt is called. How can I do that? I'm completely new to ROS, so please try to answer, so that I could understand it correctly.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2016-05-20 07:21:55 -0500

The closest thing to an "interrupt" in ROS is that ROS uses callbacks that get called when particular ROS events happen. For example, when creating a subscriber you provide a callback function that executes every time a message on a particular topic is received. You could easily publish a topic in a subscriber callback. There are also callbacks for service providers (which could also contain a publish command).

One thing you may be interested in is a Timer (Python and CPP). These allow you to specify a callback and a time period (as a ros::Duration). The callback will then be executed at the frequency specified by the time period. You can, of course, publish messages in that timer callback as well.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2016-05-20 05:49:46 -0500

Seen: 1,745 times

Last updated: May 20 '16