Ask Your Question
0

Reset Turtlebot odometry in a Python script

asked 2015-02-13 07:11:59 -0500

Elizaveta.Elagina gravatar image

I am using rostopic pub /mobile_base/commands/reset_odometry std_msgs/Empty to reset odometry on Turtlebot. It works fine but I want to do the same thing in a Python script. Here is my code:

import rospy
from std_msgs.msg import Empty

rospy.init_node('reset_odom')

pub = rospy.Publisher('/mobile_base/commands/reset_odometry', Empty, queue_size=10)
pub.publish(Empty())

It doesn't work. Could you point out what is wrong with it? Thanks!

edit retag flag offensive close merge delete

Comments

I have the same issue, did you get any response ??

AbdRenawi gravatar imageAbdRenawi ( 2016-10-04 08:17:05 -0500 )edit

In my initial explorations, if that command goes in the main control loop, it seems to work, but if it's only published a couple times, it fails to reset

haelannaleah gravatar imagehaelannaleah ( 2017-02-10 16:14:15 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2017-02-10 17:19:59 -0500

haelannaleah gravatar image

updated 2017-02-10 17:32:58 -0500

For whatever reason, it looks publishing information to the reset topic takes a bit of time to get through. I'm using the reset command in the initialization of a navigation class, so I was able to get away with a quarter second busy loop for it:

import rospy

from std_msgs.msg import Empty
from time import time

# set up node
rospy.init_node('reset_odom')

# set up the odometry reset publisher
reset_odom = rospy.Publisher('/mobile_base/commands/reset_odometry', Empty, queue_size=10)

# reset odometry (these messages take a few iterations to get through)
timer = time()
while time() - timer < 0.25:
    reset_odom.publish(Empty())

It probably makes sense to reset odom as part of an initialization step, in which case, a busy loop shouldn't affect normal robot function. However, if you want to be able to do this on the fly, you're probably going to want to come up with a non-blocking way to loop the command.

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

1 follower

Stats

Asked: 2015-02-13 07:11:59 -0500

Seen: 1,408 times

Last updated: Feb 10 '17