View Single Post
  #4   Spotlight this post!  
Unread 24-04-2016, 01:54
Poseidon5817's Avatar
Poseidon5817 Poseidon5817 is offline
"Cool" Squad
AKA: Mitchel Stokes
FRC #5817 (Uni-Rex)
Team Role: Mentor
 
Join Date: Aug 2013
Rookie Year: 2014
Location: Clovis, CA
Posts: 337
Poseidon5817 is a splendid one to beholdPoseidon5817 is a splendid one to beholdPoseidon5817 is a splendid one to beholdPoseidon5817 is a splendid one to beholdPoseidon5817 is a splendid one to beholdPoseidon5817 is a splendid one to beholdPoseidon5817 is a splendid one to beholdPoseidon5817 is a splendid one to behold
Re: Using PID in autonomous to keep straight

Quote:
Originally Posted by Dpurry23 View Post
Sorry for not explaining, we are using a gyro as a source with the output being our drivetrain.
Ok thanks. At its simplest, you could do something like this:

Code:
double angle = robot.getAngle();
double angleError = AngleYouWantToBe - angle;
double output = constant * angleError;
myRobot.drive(output, 0);
Wait(2.0);
myRobot.drive(0, 0);
This is a simple P loop. It takes the angle error, multiplies it by a constant you specify, and applies that as the output for your drive. As you get closer, your output gets smaller because the error gets smaller, and it coasts to a stop. Note that due to the fact that a drive train needs a certain percentage to actually drive (e.g. 10%), it will never actually make it the whole way to where you want it to go with just a P loop, although you could make it where it gets pretty close, depending on how you tune your constant.

If you want to get more complex than that, you could use a PI loop, but that's another story.
__________________
My FRC History:

2014 - Team 1671: Central Valley Regional Finalist and Chairman's Award Winner, Sacramento Regional Finalist, Archimedes Quarterfinalist
2015 - Team 1671: Central Valley Regional Semifinalist, Sacramento Regional Semifinalist and Chairman's Award Winner, Newton Winner, Einstein Winner
2016 - Team 5817: Central Valley Regional Finalist and Rookie All-Star, Orange County Regional Quarterfinalist and Rookie All-Star, Newton Division



Last edited by Poseidon5817 : 24-04-2016 at 01:56.
Reply With Quote