Writing the C++ code for a subsystem

RobotBuilder representation of the Claw subsystem

RobotBuilder representation of the Claw subsystem

The claw at the end of a robot arm is a subsystem operated by a single Victor speed controller. There are three things we want the claw to do, start opening, start closing, and stop moving. This is the responsibility of the subsystem. The timing for opening and closing will be handled by a command later in this tutorial.

Adding capabilities to a simple subsystem

Adding capabilities to a simple subsystem

The subsystem generated by RobotBuilder has the code to create the Claw class that corresponds to the subsystem and the code to copy the reference to the generated Victor object into the class to make it easily referenced. To add the capabilities to the subsystem to actually operate the motor add 3 methods, Open(), Close(), and Stop() to start the motor moving in the open or close direction or stop the motor.

Adding the method declarations to the generated header file - Claw.h

Adding the method declarations to the generated header file - Claw.h

In addition to adding the methods to the class implementation file, Claw.cpp, the declarations for the methods need to be added to the header file, Claw.h. Those declarations that must be added are shown here.

To add the behavior to the claw subsystem to operate it to handle opening and closing you need to define commands.