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

Is it possible to receive a msg on a certain topic by calling a service?

asked 2017-11-14 03:57:30 -0600

schizzz8 gravatar image

updated 2017-11-14 04:18:26 -0600

Hi all,

I'm working with gazebo, where I created an indoor environment and a mobile robot. The robot is equipped with an RGB-D camera and a logical_camera. Now, I would like to write a node that, given an array of poses, does the following:

  • publishes a msg on /gazebo/set_model_state to position the robot at the current desired pose

  • acquires sensors measurements (i.e. rgb, depth and logical_camera images)

  • does the required processing

  • does the same for the next poses

So far, I wrote a subscriber using a message filter (with approximate time sync policy) to read the required messages but I'm not so sure on how to go on. By considering the operations highlighted in the bullets, I think that in pseudocode the node should be something like:

while(nh.ok() && it!=pose_array.end()){ 
  gazebo_msgs::ModelState next_pose;

    read sensor measurements



So my question is the following: is it possible to call a service (or something similar) to receive the sensor messages on demand (instead of using callbacks) in the while loop?

Of course, I'd be very glad even if someone can point me out a better solution to this problem!!!


EDIT: @jayess This is because I need to acquire a dataset to train a classifier, so I just need a set of images in certain positions of the environment. I could do this by teleoperating the robot and triggering the storage of the images with the joystick. But since I need to acquire a lot of image, I was thinking of an automated way to do this! So, if I subscribe to a topic, the callback that does the processing will be called for each sensor measurement. Instead I need to read the sensors output only when the robot is in the desired position.

edit retag flag offensive close merge delete


You could use a service to get the sensor messages but the driver/node publishing that information would have to have a service server implemented. Can you explain why you want to do it this way vs. subscribing to a topic with callbacks?

jayess gravatar image jayess  ( 2017-11-14 04:10:20 -0600 )edit

I'm not sure I fully understand what you're looking for, but you could create some kind of intermediary node that subscribes to the image topic and implements a service server that will just serve what ever image it has when requested.

jayess gravatar image jayess  ( 2017-11-14 04:23:44 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2017-11-14 04:22:16 -0600

gvdhoorn gravatar image

It's not exactly a service, but I believe you're really just asking for a way to receive a single message at a certain time of your choosing.

See #q270298, #q264490 and #q231320 for similar questions (and answers).

edit flag offensive delete link more


Thanks! It's exactly what I was looking for! I just have one last question: using ros::topic::waitformessage() is it possible to receive msgs from different topics with approximately equal timestamps (i.e. like message_filters)?

schizzz8 gravatar image schizzz8  ( 2017-11-14 04:32:50 -0600 )edit

No, not in the default implementation.

You could perhaps create something that does similar things, using waitForMessage(..) as inspiration.

gvdhoorn gravatar image gvdhoorn  ( 2017-11-14 04:41:07 -0600 )edit

Question Tools



Asked: 2017-11-14 03:57:30 -0600

Seen: 1,542 times

Last updated: Nov 14 '17