Tank drive

Tank drive is a method of controlling the motors of a tank drive drivetrain using two axes of a controller, where each of the axes operate motors on one side of the robot (see image below, or this video).

Tank Drive

Robot CAD model, Controller image source

Implementation

Suppose that we have objects of the Motor class that set the speed of the motors that take values from -1 to 1. We also have a Joystick object that returns the values of the \(y_1\) and \(y_2\) axes.

Implementing tank drive is quite straightforward: set the left motor to the \(y_1\) axis value, and the right motor to the \(y_2\) axis value:

def tank_drive(l_motor_speed, r_motor_speed, left_motor, right_motor):
    """Drives the robot using tank drive."""
    left_motor(l_motor_speed)
    right_motor(r_motor_speed)

Examples

The following example demonstrates, how to make the robot drive using tank drive controlled by a joystick.

# initialize objects that control robot components
left_motor = Motor(1)
right_motor = Motor(2)
joystick = Joystick()

# repeatedly set motors to the values of the axes
while True:
    # get axis values
    y1 = joystick.get_y1()
    y2 = joystick.get_y2()

    # drive the robot using tank drive
    tank_drive(y1, y2, left_motor, right_motor)

Closing remarks

Tank drive is a very basic and easy way to control the robot. When it comes to FRC, it is a method used frequently for its simplicity, and because it is easier for some drivers to control the robot this way, compared to the other discussed methods.