Ask Your Question

Publishing a message in an interrupt

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

Loreno gravatar image


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

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

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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


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

Seen: 987 times

Last updated: May 20 '16