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

# Rotate turtlebot 10 degrees about its axis

Hi all. How are you? How can I turn turtlebot2 10 degrees about its axis and then pause. Note: The robot will not move, it will just rotate 10 degrees once every say 20 seconds. I tried setting the Twist() object's angular velocity in the Z direction but only one wheel moves and ultimately the robot is displaced.

below is my code:

            angular_velocity = radians(10) #10 degs / s

r = rospy.Rate(5) #5Hz
while not rospy.is_shutdown():
new_angle = (angle + new_angle) % 360
real_angle = real_angle + angle
#real_angle = rea1_angle + 5
new_angle =  real_angle % 360

turn_cmd.angular.z = angular_velocity #turns 10 degrees a second
#turn at 10 degrees a second for 1 second
for i in range(5):
self.cmd_vel.publish(turn_cmd)
r.sleep()
#r.sleep()


The above is my logic. But not only does the robot move, it also does not turn 10 degrees as I expect. What am i doing wrong? Thank you very much. Am using ROS indigo kobuki and turtlebot2

That being said - on slightly different note - what would be the favorable values for the rospy.Rate() function and the inner for loop to achieve the 10 or even 30 degree rotation at a relative higher angular velocity, say 25 degrees per second. Because it seems the robot does not work well with low velocities such as 10 degs/s. Some it does not move at all when low velocities are given. Eitherway, thanks.

edit retag close merge delete

Sort by ยป oldest newest most voted

Basically you need to implement an algorithm for robot control. It could be an open-loop controller, where you command your robot to turn for a certain amount of time and then stop the motion, this will not be precise, but if error is not an issue it will certainly be the easiest way of implementing what you described. All you need in that case is a publisher for applying control signals (velocity commands) and logic for generating the stop command based on a timer.

A better way of doing it is with closed loop (feedback) control.
If you have a way to input your goal you will need at least the following three components:

• A publisher for applying control signals (velocity commands)
• A subscriber for measuring the results (the robot's odometry)
• Logic for comparing the results with the goal and generate new control signals if required

As a start you can take a look at this video:

[ROS Q&A] 053 - How to Move a Robot to a Certain Point Using Twist

more

oh I even forgot to update this. Thanks Robert, indeed I already did solve it using the former logic. I just had trouble calculating the right amount of time for rotating and stopping. But somehow I got down the time. I have yet to formulate it and make it general for any desired angle now. Thanks for the suggestion though. Ultimately I will definitely implement a closed loop as well for comparison. However a closed loop seemed like an over kill for that at first, but it may be the only sure way of actually implementing it according to what my digging has yielded. Though I still feel with the ROS control paradigim achieving this with well calculated rosRates and how often the robot turns and stops should suffice to achieve a satisfactorily accurate (about 0.3-0.5 degree error) result. whats your take on that?

( 2020-09-01 07:24:07 -0500 )edit

I am glad to hear it is working now! Unfortunately I have no clue if the open loop approach is enough for your requirements.
If you are able to find time to implement a closed loop approach, I definitely recommend it. You will learn a lot during the process.

( 2020-09-01 10:05:14 -0500 )edit

I totally agree. Just implementing what I have now taught me a lot about the turtlebot. Most of which I presumed I knew and turned out to be wrong xd. So definitely Yes. Am gonna manually try to implement a closed loop as well. And for what its worth, I will accept your answer since it came before I could actually write what I used :). Thanks.

( 2020-09-01 10:18:27 -0500 )edit