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

Printing time values along with pose

asked 2019-04-24 07:43:06 -0500

kkulkarn gravatar image

I’m an absolute newbie and I got hold of someone’s simple program to navigate a robot by setting a goal position and including random obstacles. The python script uses ROS move_base and navigation packages, subscribes to nav_msgs and prints out pose and twist outputs to the terminal/a text file. Everything works fine but I’m not able to figure out the time values for each pose/twist output. How can I get the script to output time; or is it an output frequency parameter set in any of the yaml files. I tried searching and I could not figure out.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2019-04-24 08:04:31 -0500

Delb gravatar image

I guess your script subscribes to nav_msgs/Odometry messages since you said you have a twist output. If you check the documentation of the message you'll find that there are different fields :

std_msgs/Header header
string child_frame_id
geometry_msgs/PoseWithCovariance pose
geometry_msgs/TwistWithCovariance twist

Your script gets the info from the fields pose and twist, if you want to get the time you have to check in the field header , and within the header there is the field time.

So in your script you probably have a print function with something like data.pose.pose.position in it. You just have to add data.header.time somewhere in your print.

edit flag offensive delete link more

Comments

Yes, you are correct on the pose and twist. I tried including what I thought would be the correct syntax., which obviously not. Gave me an error saying bad call back. What am I doing wrong?

import roslib
roslib.load_manifest('anvel_2dnav')
import rospy
from nav_msgs.msg import Odometry
from std_msgs.msg import Header

def navCallback(data):
    print "---------------------------"
    print data.header.time
    print data.pose.pose
    print data.twist.twist
if __name__ == '__main__':

rospy.Subscriber("odom", Odometry, navCallback)
rospy.Subscriber("time", Header, navCallback)
kkulkarn gravatar image kkulkarn  ( 2019-04-24 13:01:36 -0500 )edit

Your error is because of the last line, just get rid of it. With a subscriber, you are supposed to give a topic name, the type of the topic and the name of the callback. The first subscriber already subscribe to the topic odom and you will deal with the Odometry message within the navCallback function. Since the data do have the header field there is no need to have another subscriber.

To go further on your issue : your last line try to subscribe to the topic time (which I feel it doesn't exist, if you do rostopic list there shouldn't be this topic) specifying that the topic is a Header msg (this type do exist but is usually used within another message, just like inside Odometry.msg) and you assign a callback that is already assigned to another message type.

I would recommand you to go through ...(more)

Delb gravatar image Delb  ( 2019-04-25 03:36:49 -0500 )edit

Got it. Noted on reviewing the tutorials. I was in a hurry and excited to see some initial results without really understanding all the communications between ROS and the dynamics solver. Thanks.

kkulkarn gravatar image kkulkarn  ( 2019-04-25 08:34:42 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2019-04-24 07:43:06 -0500

Seen: 991 times

Last updated: Apr 24 '19