Quote:
Originally Posted by microbuns
I was thinking about somehow trying to minimize the difference between the two sides' encoders, but I'm not exactly sure what/how to go about that. Do you just have some speed factor you add to one side and subtract to the other that scales off the difference of the two sides?
|
This is a good approach. I've seen the following work pretty well:
Code:
// Set up drivePID as a PIDController with a custom PIDSource that
// calculates the distance between the encoders and outputs the result
// in PIDGet(). The PIDOutput doesn't matter and should be a dummy.
// In AutonomousInit
drivePID.Enable();
// In AutonomousPeriodic
drivePID.SetSetpoint(0);
double movement = someConstant;
double rotation = drivePID.Get();
drive.ArcadeDrive(movement, rotation, /*SquaredInputs=*/ false);
This is where drivePID is an instance of the PIDController class. The PIDController class is pretty obnoxious in that its source and output have to be of the types PIDSource and PIDOutput, respectively. This means that you (the FRC team) have to create a class that inherits from PIDSource which calculates the difference between two encoders and returns that in the virtual function PIDGet().
Gotta say, sometimes the flow of information in C++ is really hard to follow.