View Single Post
  #8   Spotlight this post!  
Unread 28-02-2012, 21:42
mikets's Avatar
mikets mikets is offline
Software Engineer
FRC #0492 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Bellevue, WA
Posts: 667
mikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of light
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);
    }
}
However, if you want to adjust the turn power according to how far you are from your target, then you need to use PID.
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.
Reply With Quote