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

Is there a way to subscribe to a topic without using a callback function?

asked 2017-07-27 05:23:16 -0500

Shubhayu Das gravatar image

I wish to subscribe to the trajectory topic published by hector_trajectory_server and save it's contents in a file. I understand that the topic is of type nav_msgs/Path which consists of a dynamic array of poses (ie geometry_msgs/poses), so the trajectory is updated as the bot moves around. Now, say I stop moving it around (ie stop the node that makes it move), at this point I want to be able to copy the entire structure - Path (consisting of poses[]) onto a file. I tried doing this with a callback function and it did not work. So my question is.. Is there a way of subscribing right at the end? (perhaps, declaring it in a shut-down method) or, Is there a way to subscribe without a callback function? and, I the it a problem because I am using a file instead of a message?(if so why?)

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-07-27 06:37:07 -0500

updated 2017-07-27 07:05:27 -0500

Hello,

If you have hector_trajectory_server, a node that control the robot and a node that save the file, you can do what you want with bond.

Bond allow you to make 2 nodes notified each other if one die. So your software flow will be like this :

Run Hector, Controller and Logger > Bond Logger and Controller > Wait > Controller Die and notify Logger > Logger Subscribe to Hector Path and save to a file > Logger die > ? > Profit.


Edit : Found a second possible solution :

For cpp : Subscribe to the path topic at the beginning but do nothing while a flag is false, then define a custom SIGINT handler (2.2.1), where you put the flag to true to save the path to a file and shutdown the node cleanly.

For Python : Do a callback where you subscribe to the topic and save it in a file and put this callback in : rospy.is_shutdown() , to do some work before shutting down (Documentation 2.2)

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-07-27 05:23:16 -0500

Seen: 1,324 times

Last updated: Jul 27 '17