Thread: Gyro Turning
View Single Post
  #5   Spotlight this post!  
Unread 09-10-2013, 09:31
otherguy's Avatar
otherguy otherguy is offline
sparkE
AKA: James
FRC #2168 (The Aluminum Falcons)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: CT
Posts: 431
otherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to behold
Re: Gyro Turning

No, Kp is the proportional gain term. It's a value which is multiplied by the measured error. Where "error" is your desired position (input into the PID controller) minus actual measured position.

I would suggest reading up on PID controllers, and learn at least at a high level how they operate before attempting to use one on your robot.
Some helpful links:
PID without a PHD (pdf) a good overview of how different controllers work
PID Tuning This one will help you choose your gains.

That said, you can turn x number of degrees using the gyro without a PID controller. A simple implementation is provided below.
If you have never used a PID controller before, it may be easier to implement a simple algorithm like what is below, then itterate on the design to improve the performance problems you identify.

Sudocode (this needs to be run in a loop in a simple robot project, or have supporting state variables in an itterative or command based robot project (to flag when you're finished)
Code:
//Positive angle is roatation clockwise
//currentAngle is the angle measured off the gyro
//destinationAngle is the desired angle to rotate to
//forwardSpeed and reverseSpeed are variables between 1.0 and -1.0, the larger they are the faster you will turn.
//    making one the negative of the other will 
if ( abs(currentAngle) >= abs(destinationAngle)) {
    //we're there, stop turning
    drivetrain.tankdrive(0,0)
} else if ( destinationAngle  > currentAngle) {
    //rotate clockwise
    drivetrain.tankDrive(reverseSpeed, forwardSpeed);
} else {
    //rotate counter-clockwise
    drivetrain.tankDrive(forwardSpeed, reverseSpeed)
}
Note, this code could (Read will) overshoot its destination. Depending on your intended applicaiton this may or may not be a desireable feature.
__________________
http://team2168.org
Reply With Quote