Overview
Mars-RS implements several sophisticated movement algorithms for differential drive robots. These algorithms combine PID control, geometric path following, and motion profiling to achieve smooth and accurate robot movement.Core Movement Functions
pidMTP (PID Move-to-Point)
The fundamental movement algorithm that drives the robot to a target position using PID control for both linear and angular velocity.The
pidMTP function uses separate PID controllers for left and right wheel velocities, allowing independent control of linear and angular motion.- Calculates linear error (distance to target)
- Computes rotation error (heading difference)
- Scales velocity based on rotation error using cosine function
- Minimum velocity threshold to prevent stalling
Velocity Calculation
The velocity calculation inpidMTPVel uses a clever scaling approach:
Boomerang
The boomerang algorithm creates a smooth curved path to the target point with a specified final heading. It uses a “carrot” point that leads the robot along a natural arc.dLead: Distance multiplier (typically 0-1)thetaEnd: Desired final heading angleh: Current distance to target
Why is it called 'Boomerang'?
Why is it called 'Boomerang'?
The algorithm creates a curved path that resembles a boomerang shape, especially when the final heading differs significantly from the direct line to the target. This allows the robot to approach the target from a specific direction.
followPath
Follows a sequence of waypoints using the boomerang approach for each segment, automatically transitioning between waypoints.- Automatically advances to next waypoint when within 40 units
- Calculates heading angle between consecutive waypoints
- Uses boomerang-style carrot points for smooth transitions
eulerTurn
Performs curved turns with gradually increasing curvature, creating smooth and natural rotation movements.- Gradually increases curvature over time
- Calculates wheel velocity ratio from curvature
- Applies PID control to the rotation error
- Returns final curvature for chaining multiple turns
The
15.0 constant represents half the track width (wheelbase) in the curvature calculation, affecting how sharply the robot can turn.Algorithm Comparison
| Algorithm | Use Case | Path Shape | Heading Control |
|---|---|---|---|
| pidMTP | Simple point-to-point | Direct line | Automatic |
| Boomerang | Approach with specific heading | Smooth curve | Explicit final angle |
| followPath | Multi-waypoint navigation | Piecewise curves | Between waypoints |
| eulerTurn | In-place or curved rotation | Spiral | Explicit target |
| moveToPurePursuit | Smooth path following | Follows exact path | Along path tangent |
Control Loop Timing
All movement algorithms use a 10ms control loop:Related Topics
PID Control
Learn about PID tuning and constants
Pure Pursuit
Deep dive into pure pursuit algorithm
Robot Physics
Understand differential drive kinematics