Expand description
Differential (tank-style) drivetrain implementation.
This module provides DifferentialDrive, a controller for robots with independent
left and right motor groups. It supports multiple drive modes (tank, arcade, curvature)
and provides velocity estimation from motor encoders (IME) for odometry fallback.
§Overview
A differential drivetrain has motors on the left and right sides that can be driven independently. By varying the speeds of each side, the robot can move forward, turn, or spin in place.
§Drive Modes
- Tank Drive: Direct left/right control (
drive_tank) - Arcade Drive: Forward/turn control with expo scaling (
drive_arcade) - Curvature Drive: Throttle + curvature for smooth driving (
drive_curvature)
§IME Velocity Estimation
When no tracking rig is available, DifferentialDrive can estimate linear and angular
velocity from motor encoder readings using the wheel size, gear ratio, and track width:
- Linear velocity:
(left_vel + right_vel) / 2 - Angular velocity:
(right_vel - left_vel) / track_width
§Example
use kernelvex::{DifferentialDrive, MotorGroup, OmniWheel, QLength};
use kernelvex::dt::differential::ExpoDrive;
let left = MotorGroup::new([left_motor1, left_motor2]);
let right = MotorGroup::new([right_motor1, right_motor2]);
let expo = ExpoDrive::new(2.0, 1.0);
let drivetrain = DifferentialDrive::new(
left,
right,
expo,
OmniWheel::Omni4,
QLength::from_inches(12.0), // track width
0.6, // gear ratio
);
// Tank drive: left at 50%, right at 50%
drivetrain.drive_tank(0.5, 0.5).await?;
// Curvature drive: 80% throttle, slight right turn
drivetrain.drive_curvature(0.8, 0.2).await?;Structs§
- Differential
Drive - A differential (tank-style) drivetrain with left and right motor groups.
- Expo
Drive - Exponential drive scaling for smoother joystick control.