How do I turn an exact angle using Twist messages?
I want to turn a position model in stageros a set angle. So I would need to publish Twist messages with an angular velocity to make it turn.
Say I want to turn a robot 180 degrees (or pi radians). How would I write something in C++ to make it stop turning with angular velocity after it turns 180 degrees. I know that I need to send the Twist messages in a loop but I don't know what the condition would be.
How would I check that the robot has reached the desired heading?
@joq How would I check that it's reached the desired heading though? That's the part I'm having trouble with.
@joq I already have the heading of the robot and the heading it needs to reach. I have a while loop that sends Twist messages with angular velocity. How do I get out of that loop once it reaches the desired heading or what should the condition for the while loop be?
Because
while (currentAngle != desiredHeading)
does not work since the angular velocity can cause it to overshoot it.It probably will overshoot. You need a feedback control loop, something like a PID controller: http://en.wikipedia.org/wiki/PID_controller
@joq I'm sorry I'm not that familiar with PID controllers and using feedback control loops. I've read through the Wikipedia page but don't really understand what I need to do. Is there an example somewhere for roscpp?
I think a PID controller is a little to advanced for this problem, basically you need a feedback loop; i.e. the robot needs to look at its orientation first from odom, then start turning, while its turning continually keep checking odom for the new orientation until you have turned the desired angle
Did you find solution?