Operating a PIDSubsystem from a command in Java
A PIDSubsystem will automatically control the operation of an actuator with sensor feedback. To actually set the setpoints for the subsystem use a command since commands can be controlled over time and put together to make more complex commands. In this example we move the Elevator subsystem to the pickup (BOTTOM) position. To create the PIDSubsystem for the elevator see: Making a subsystem with feedback from sensors and Writing the code for a PIDSubystem in Java
Create the Elevator pickup command
The elevator pickup command moves the elevator to the pickup (BOTTOM) position. Notice that the Command requires the Elevator subsystem. By requiring the elevator, the command scheduler will automatically stop any "in progress" elevator commands when the Elevator pickup command is scheduled.
Export to Java to generate code for the robot program including the new Elevator pickup command.
Add the methods to finish the command
There are two changes that need to be made to make the Command work properly:
- Set the setpoint on the Subsystem PID controller so that it starts the elevator moving to the right position.
- Add code to the isFinished() method so the command can finish when the elevator has moved to its target position. This way, other commands that run after this command will start when the elevator has reached its target position.