Is it possible to use more than one PID controller for a subsystem like the drivetrain? Example: An encoder PID loop to drive to a distance setpoint, while a gyro PID loop keeps the robot going straight.
You could also substitute encoder with Ultrasonic sensor, etc.
If you can’t run them simultaneously, is there a way to switch between PID controllers to, say, drive forward 5 meters distance (via encoder), then turn 90 degrees (via gyro), then drive forward again, etc?
Yes. Feed the output of the PIDs into Arcade Drive. Use the output of the angle control PID as the joystick input that makes the robot turn, and use the output of the distance PID as the joystick input that makes the robot drive forward.
It gets a little tricky with the PIDController class, since it wants to write directly to a speed controller, which doesn’t work when you want to mix the results of multiple PID controllers and output to multiple speed controllers. What we did was create a class called DummyPIDOutput that implements PIDOutput but doesn’t output anything. We then read the DummyPIDOutput in our drive code and do the mixing there.
There’s probably an easier way, but this what worked for us. I’ve attached our DummyPIDOutput class.
I’ve spent alot of time looking at CD threads about using PIDController and picked up some useful tips about pid and java. Try searching and reading what others have posted.
We did not get a chance to finish testing this before having to bag the robot so I can’t say if it works. But based on the CD thread I found above plenty of teams are doing something like this.
If you extend PIDCommand and require() the subsystem, your PID will automatically be cancelled when another is started, allowing you to have different PID controls.