TankDriveTrain

The TankDriveTrain class provides a tank-style drive control system for robotics applications. It manages left and right motor groups, including lead motors and optional additional motors

Tank Drive Train Documentation

Overview

The Tank Drive Train class provides differential drive control for robots with left and right side motors. It supports simple two-motor setups and complex configurations with up to 3 motors per side.

Method
Description

TankDriveTrain(controller, leftLead, rightLead, ...)

Creates a tank drive system with specified motor IDs

drive(x, y)

Controls robot movement with directional and turning inputs

setBrake()

Enables brake mode on all motors for precise stopping

setCoast()

Enables coast mode on all motors for free-wheeling


Quick Start Example

#include <EchoLib.h>

MotorControllers motors;
TankDriveTrain drive(motors, 1, 2);  // Use motor IDs 1 and 2

void setup() {
  Serial.begin(115200);
  drive.setBrake();
}

void loop() {
  // Move forward
  drive.drive(0, 50);
  delay(1000);
  
  // Turn right
  drive.drive(30, 0);
  delay(1000);
  
  // Arc right while moving forward
  drive.drive(20, 40);
  delay(1000);
}

Method Details

Constructor

TankDriveTrain(MotorControllers& controller, uint8_t leftLead, uint8_t rightLead, uint8_t* extraLeftIDs = nullptr, uint8_t extraLeftCount = 0, uint8_t* extraRightIDs = nullptr, uint8_t extraRightCount = 0)

Creates a tank drive system using the specified motor controller and motor IDs.

Parameters:

  • controller: Reference to the MotorControllers instance

  • leftLead: Motor ID for the left lead motor

  • rightLead: Motor ID for the right lead motor

  • extraLeftIDs: (Optional) Array of additional left side motor IDs

  • extraLeftCount: (Optional) Number of additional left motors

  • extraRightIDs: (Optional) Array of additional right side motor IDs

  • extraRightCount: (Optional) Number of additional right motors

Simple Setup (2 motors):

Multi-Motor Setup (6 motors total):


Movement Control

void drive(int x, int y)

Controls robot movement with two parameters: forward/backward and turning.

Parameters:

  • x: Turning speed (-100 to 100). Positive = turn right, negative = turn left

  • y: Forward/backward speed (-100 to 100). Positive = forward, negative = backward


Brake Control

void setBrake()

Enables brake mode on all motors. Motors resist movement when stopped, providing precise positioning.

void setCoast()

Enables coast mode on all motors. Motors spin freely when stopped, reducing power consumption but allowing drift.


Complete Example

This example demonstrates various tank drive movement patterns.


Multi-Motor Configuration

For heavy-duty applications requiring multiple motors per side (up to 3 motors per side):

Available Motor IDs: 1, 2, 3, 4, 5, 6 (pre-configured in MotorControllers)


Tank Drive Kinematics Explained

Basic Formula

The tank drive system uses simple differential kinematics:

Left Motor Speed = Y + X Right Motor Speed = Y - X

Where:

  • Y: Forward/backward component

  • X: Turning component


Movement Analysis

Forward: X=0, Y>0 → Both sides move forward at same speed

Backward: X=0, Y<0 → Both sides move backward at same speed

Turn Right: X>0, Y=0 → Left side faster than right side

Turn Left: X<0, Y=0 → Right side faster than left side

Arc Movements: X≠0, Y≠0 → Curved paths combining forward motion with turning


Best Practices

Hardware Considerations

Motor Matching: Use identical motors for each side to ensure straight movement

Wheel Alignment: Proper wheel alignment prevents unwanted drag and turning

Weight Distribution: Center weight between the drive wheels for optimal traction

Gear Ratios: Choose appropriate gear ratios for your application's speed vs torque requirements


Troubleshooting

Movement Issues

Robot turns while going straight: Check motor calibration and wheel alignment

Weak turning: Verify motor power and check for mechanical binding

Inconsistent movement: Ensure battery voltage is adequate and motors are matched

Robot moves in wrong direction: Check motor wiring polarity


Control Issues

Jerky movement: Implement acceleration ramping or reduce input sensitivity

Delayed response: Check for delays in control loop and reduce unnecessary processing

Lost control: Implement connection monitoring and safety timeouts

Erratic behavior: Verify input parsing and value constraints


Multi-Motor Issues

Uneven power distribution: Check individual motor connections and controller settings

Motor synchronization problems: Verify all motors on same side receive identical commands

Overheating: Distribute load evenly and monitor individual motor temperatures

Current overload: Check total current draw and power supply capacity


Important Notes

Multi-Motor Synchronization

When using multiple motors per side, ensure all motors on the same side have identical specifications and are mechanically aligned to prevent binding.


Motor ID Consistency

Use motor IDs 1-6 which are pre-configured in the MotorControllers class. Each motor ID corresponds to a specific motor label which can be found on the Echo itself


Conclusion

The TankDriveTrain class provides a robust and flexible foundation for differential drive robot control. Its support for both simple two-motor setups and complex multi-motor configurations makes it suitable for a wide range of applications, from lightweight rovers to heavy-duty industrial robots. The straightforward x,y control interface abstracts the underlying motor calculations while maintaining the characteristic advantages of tank drive systems: simplicity, reliability, and excellent traction. Whether you're building autonomous vehicles, remote-controlled robots, or educational platforms, this class provides essential tools for effective tank drive control.

Last updated