|
Re: Multiple PID Loops - Java
Quote:
Originally Posted by tomy
So you would do something like this with more sensors?
|
Do you intend to use the sensors independently or coupled together? For example, would you like a drive-to-distance-PID that uses encoders for distance + a gyro to help go straight? Or perhaps you are looking to drive straight until the ultrasonic sensor trips? Some of these cases are easily handled by the default WPILib PID implementation, others not so much.
For theses cases, we typically use a separate control loop thread and switch between modes. The update method might look something like this:
Code:
public void controlLoopUpdate() {
if (controlMode == DriveTrainControlMode.JOYSTICK) {
driveWithJoystick();
}
else if (!isFinished) {
if (controlMode == DriveTrainControlMode.MP_STRAIGHT) {
isFinished = mpStraightController.controlLoopUpdate(getGyroAngleDeg());
}
else if (controlMode == DriveTrainControlMode.MP_TURN) {
isFinished = mpTurnController.controlLoopUpdate(getGyroAngleDeg());
}
else if (controlMode == DriveTrainControlMode.PID_TURN) {
isFinished = pidTurnController.controlLoopUpdate(getGyroAngleDeg());
}
}
}
For more detail, you can look at the Drivetrain subsystem in our 2016 code: https://github.com/Team3310/FRC-2016
__________________
2016 Curie Quarter-Finalist (5803, 3310, 2168, 5940), Lubbock Regional Winner (3310, 4063, 4301), Arkansas Regional Winner (16, 3310, 6055)
2015 Newton Quarter-Finalist (3130, 2468, 3310, 537), Lubbock Regional Winner (2468, 3310, 4799)
2014 Galileo Quarter-Finalist (2052, 70, 3310, 3360), Colorado Regional Winner (1138, 3310, 2543)
2013 Archimedes Semi-Finalist (126, 3310, 1756), Texas Robot Roundup Winner (3310, 624, 2848), Dallas Regional Winner (148, 3310, 4610)
2012 Dallas West Regional Winner (935, 3310, 4206)
|