Ask Your Question

# 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?

edit retag close merge delete

## Comments

@joq How would I check that it's reached the desired heading though? That's the part I'm having trouble with.

( 2012-08-15 17:23:47 -0500 )edit

@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?

( 2012-08-16 04:28:03 -0500 )edit

Because while (currentAngle != desiredHeading) does not work since the angular velocity can cause it to overshoot it.

( 2012-08-16 04:33:24 -0500 )edit

It probably will overshoot. You need a feedback control loop, something like a PID controller: http://en.wikipedia.org/wiki/PID_controller

( 2012-08-16 12:11:25 -0500 )edit

@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?

( 2012-08-16 17:59:36 -0500 )edit

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

( 2012-08-17 09:32:12 -0500 )edit

Did you find solution?

( 2019-08-11 05:41:47 -0500 )edit

## 2 Answers

Sort by ยป oldest newest most voted

Duplicate of this question.

more

## Comments

( 2012-08-16 04:23:40 -0500 )edit

This should help.

more

## Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

## Stats

Asked: 2012-08-15 16:53:09 -0500

Seen: 7,791 times

Last updated: Aug 16 '12