Is it possible to receive a msg on a certain topic by calling a service?
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;
pose_pub.publish(next_pose);
/*
read sensor measurements
*/
/*
processing
*/
++it
ros::spinOnce();
loop_rate.sleep();
}
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!!!
Thanks.
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.
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?
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.