Turtlebot3 Odometry not updating correctly
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
rospy.init_node("check_odometry")
sub=rospy.Subscriber('/odom', Odometry, callback)
rospy.spin()
and then I simply make the Turtlebot go straight ahead slowly with this:
import rospy
from geometry_msgs.msg import Twist
rospy.init_node("velocity_controller")
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():
pub.publish(vel_msg)
print 'sent'
rate.sleep()
rospy.spin()
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 !