Rotating 90 degrees

Hi all,

I tried to control bb9 to turn 90 degrees by the following code:

import rospy
from geometry_msgs.msg import Twist, Vector3
from math import pi

rospy.init_node('move_square_bb8_service_client')
pub = rospy.Publisher('/cmd_vel', Twist, queue_size=1)
move = Twist()


move.linear.x = 0.0
move.linear.y = 0.0
duration = 10
move.angular.z = pi*2/4/duration

pub.publish(move)
rospy.sleep(duration)

move.angular.z = 0
pub.publish(move)

but it turned out that it rotated clearly far more than 90 degrees.

Can someone give a hint what is the problem here?
thank you so much!

Best regards,
Kailin

Hi @kailin.tong
I had the same problem. The issue is that if you turn too fast, things dont work. Also the robot has to accelerate to that speed and then decelerate, making it inaccurate. Try setting your angular speed to 0.2 and turning it for 4 seconds and adjust going from there.

Another tip: when implementing this later in a loop to move in a square path, make sure you use rospy.Rate(10).sleep()
If you send /cmd_vel commands too quickly, things get fucked.

summary:
use linear and angular speed smaller than 0.3
use a rate of 10hz for your loops

1 Like

Thank you very much for your tips!:+1:

1 Like