This example shows how tank drive works using a gamepad as a controller. Tank drive allows the driver to control the left and right motors independently of each other. Since each side needs to be controlled separately, one must use two inputs/joysticks to control it. A gamepad is a good choice as it has two joysticks on a single device.
Some gamepads have the ability to disable analog mode, which sets the secondary joystick to read as a button rather than a pair of axes. Be sure that analog mode is enabled when using tank drive.
The code below works by opening a reference to each motor and to the gamepad. In this code the motors are controlled by CAN controllers, but it can be easily modified for another controller type. Because the gamepad has both joysticks on it, only one joystick reference is necessary. The axis position of each stick can be fetched using the JoystickGetValues.vi. The Axes output returns the values of the desired axes (in this case Axis 1 and Axis 3). These values can then be applied to the motors after negating one side since the motor(s) should have an opposite orientation.
This Training Module discusses the basic concepts of motor control. These same concepts are applied in the code below.