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

Rotate turtlebot 10 degrees about its axis

asked 2020-08-20 05:40:57 -0600

lxg gravatar image

updated 2020-08-20 15:43:54 -0600

jayess gravatar image

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
            #rospy.loginfo("starting loop")
            while not rospy.is_shutdown():
                    rospy.loginfo("in loop")
                    new_angle = (angle + new_angle) % 360
                    real_angle = real_angle + angle
                    #real_angle = rea1_angle + 5
                    rospy.loginfo("after addition")
                    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 flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2020-09-01 06:48:09 -0600

Roberto Z. gravatar image

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

edit flag offensive delete link more

Comments

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?

lxg gravatar image lxg  ( 2020-09-01 07:24:07 -0600 )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.

Roberto Z. gravatar image Roberto Z.  ( 2020-09-01 10:05:14 -0600 )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.

lxg gravatar image lxg  ( 2020-09-01 10:18:27 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2020-08-20 05:40:57 -0600

Seen: 1,361 times

Last updated: Sep 01 '20