Kitbot Programming Tutorial Part 2

2. Setting up the subsystem

The first thing you want to do when setting up a subsystem is to identify the electronic components that will be grouped together to make the subsystem.  For the kitbot drive subsystem we identify two TalonSRX motor controllers.  Other subsystems may have more motors, pistons, or sensors.  By grouping the hardware components you can organize your code and keep the direct control of the hardware restricted to the subsystem.

To begin right click on the subsystem package, create a new Subsystem, and name it Drive:

Next create two TalonSRX objects (Be sure to install the TalonSRX library packages found here) and name them rightDrive and leftDrive:

To keep all of our ids in one place we will be going into the RobotMap class to create two integers call RIGHT_DRIVE_TALON_ID and LEFT_DRIVE_TALON_ID:

Be sure to put in the ids for the talons found on the roborio web interface

After doing that go back to the Drive subsystem and create a constructor to initialize both the talon objects:

Now we will link the talons in a RobotDrive object to allow for more control over the driving:

Now we have to fill out the methods to control the subsystem.  The first methods we will write is the ability to drive the robot with a joystick input. So we create a method that takes in a Joystick as a parameter and use the joystick input to put it through the RobotDrive method for tank drive:

Check the axis that you want to use the first axis will control the left wheels and the second axis will control the right.

Next we will create some methods to help with Autonomous programming so we will create two methods to simulate joystick input and one to stop the entire subsystem:

Lastly we will add the subsystem to the Robot class to be used later:

That completes the setup for the subsystem for now.  The next tutorial will go over how to write the commands.

<-Previous TutorialNext Tutorial->