Writing the code for a subsystem in Java
Adding code to create an actual working subsystem is very straightforward. For simple subsystems that don't use feedback it turns out to be extremely simple. In this section we will look at an example of a Claw subsystem that operates the motor for some amount of time to open or close a claw on the robot arm.
Create the subsystem
Be sure that the subsystem is defined in the RobotBuilder robot description. The Claw subsystem has a single Victor and no sensors since the claw motor operates for one second in either direction to open or close the claw.
Generate code for the project
Re-generate the code for the project. See Generating Code for a project
Open the project in VS Code
Open the generated project in VS Code and notice the subystems package containing each of the subsystem files. Open the Claw.java file to add code that will open and close the claw.
Add methods to open, close, and stop the claw
Add methods to the claw.java that will open, close, and stop the claw from moving. Those will be used by commands that actually operate the claw. The comments have been removed from this file to make it easier to see the changes for this document. Notice that a member variable called "victor" is created by RobotBuilder so it can be used throughout the subsystem. Each of your dragged-in palette items will have a member variable with the name given in RobotBuilder.
See: Writing the code for a command in Java to see how to get this Claw subsystem to operate using commands. See: Writing the code for a PIDSubystem in Java to write the code for a more complex subsystem with feedback (PIDSubsystem).