Quote:
Originally Posted by Dpurry23
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.