Turtlebot3 Odometry not updating correctly

asked 2019-07-17 00:57:11 -0500

DoublXpresso gravatar image

Hello, I'm a beginner with ROS, and I'm trying to use a Turtlebot3. My main goal is to move the robot to a certain position. I wrote my code to do that, and it worked pretty fine on the simulation (using Gazebo), but when I tried it on the Turtlebot, it didn't work at all. I figured out the problem came from the Odometry callback, it wasn't updating fast enough.

So I tried to write a simple code to try and see where the problem was; this one to get the current position :

import rospy
from nav_msgs.msg import Odometry

def callback(msg):
     print msg.pose.pose.position

sub=rospy.Subscriber('/odom', Odometry, callback)

and then I simply make the Turtlebot go straight ahead slowly with this:

import rospy
from geometry_msgs.msg import Twist

pub=rospy.Publisher('/cmd_vel', Twist, queue_size=1)
vel_msg = Twist()
rate = rospy.Rate(10)
vel_msg.linear.x = 0.02

while not rospy.is_shutdown():
    print 'sent'

And then when I launch them both on a different terminal, the turtlebot is indeed moving straight ahead but the Odometry message I get is not updating at a constant frequency; I first get something near 0, and then something like four messages of almost the same position, then nothing though the robot is still moving, then a position 40cm further... I really have no clue of what's happening, and nobody seems to have this sort of problem... If someone could help I would be really thankful !

edit retag flag offensive close merge delete