View Single Post
  #5   Spotlight this post!  
Unread 31-01-2013, 18:01
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,062
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Gyro PID Programming

Quote:
Originally Posted by UriF View Post
Code:
/*
 * This fixes the Angle overflow problem, so the angle is always in the range
 * -360 to 360 
 */
float Gyro_FixAngle(float Angle)
{
   int Laps = Angle / 360;
   return (Angle - (Laps * 360));
}

double PIDGet()
{
   return GYRO_SCALE(Gyro_FixAngle(Gyro1->GetAngle()));
}
You don't want the (corrected) gyro angle in the range -360 to +360.

You want your robot to always take the shortest angle to get back to the zero position. For example, if your gyro angle is reading 359 degrees, you don't want to rotate the robot back 359 degrees to get to zero. You want to rotate it forward 1 degree to get back to zero.

So you want the corrected gyro angle in the range -180 to +180, with zero being your starting position.



Reply With Quote