|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
Re: Use Gyro to turn 90 Degrees
Alright I will be testing that tomorrow. I was curious about the value range because we had the bot set up with the following code:
Code:
float angle = gyro.GetAngle() + 90; myRobot.Drive(-0.2, -angle / 30); The result when running this was that the robot would turn right at a medium rate and continue turning after passing 90 degrees. The other result that seemed odd was that changing "/ 30" to "/ 1" caused a slower turn rate while changing it to "/ 60" caused a faster turn rate. |
|
#2
|
||||
|
||||
|
Re: Use Gyro to turn 90 Degrees
If you just want a simple turn, don't use myRobot.Drive, just use ArcadeDrive, like this:
Code:
#define TURN_TOLERANCE 0.5
void Turn(float angle)
{
float targetHeading = gyro.GetAngle() + angle;
while (fabs(targetHeading - gyro.GetAngle()) > TURN_TOLERANCE)
{
myRobot.ArcadeDrive(0.0, (angle < 0.0)? -0.5: 0.5);
}
}
BTW, you should really fix your signs by calling myRobot->SetInvertedMotor(), you will benefit from it in the long run. Last edited by mikets : 28-02-2012 at 21:46. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|