Introduction
Pure Pursuit is a path following algorithm that calculates a target point along the path at a fixed “lookahead” distance from the robot. The robot then steers toward this point, creating smooth curved motion along the path.Pure Pursuit is particularly effective for following paths with curves because it naturally generates smooth arcs rather than sharp corrections.
Algorithm Overview
ThemoveToPurePursuit function implements Pure Pursuit path following:
Key Concepts
- Lookahead Circle: A circle centered on the robot with radius
lookAhead - Path Segments: Lines connecting consecutive waypoints
- Intersection Point: Where the lookahead circle intersects the path
- Target Point: The intersection point closest to the end of the path
Core Algorithm: targetPoint
The heart of Pure Pursuit is finding where the lookahead circle intersects the path.Line-Circle Intersection
The algorithm uses the mathematical formula for line-circle intersection. For each path segment:Mathematical Background
The intersection formula comes from the parametric line equation and circle equation: Circle: Parametric Line: Discriminant: Where:- = lookahead radius
- = line segment length
- = cross product
Why use discriminant?
Why use discriminant?
The discriminant tells us about intersections:
- : No intersection (circle misses line)
- : One intersection (circle tangent to line)
- : Two intersections (circle crosses line)
Target Point Selection
When multiple intersections exist, Pure Pursuit must choose the best target point:Selection Strategy
-
Validity Check: Point must lie on the line segment (within min/max bounds)
- Closest to Goal: Choose the intersection point closest to the path’s end
-
Last Line Detection: Special handling when reaching the final segment
TargetPoint Enum
The algorithm uses an enum to track when to advance to the next path segment:Last point is found, the lineIndex increments:
Line Lookahead
ThelineLookAhead parameter controls how many segments ahead to search:
Integration with PID
Pure Pursuit finds the target point, then uses PID control to drive toward it:The linear controller (lCont) has higher P gain (0.05) than the angular controller (0.015), making forward motion more aggressive than turning.
Final Point Handling
When approaching the path end:Lookahead Distance Tuning
Effects of Lookahead Radius
Small lookahead (e.g., 10-30)
Small lookahead (e.g., 10-30)
Pros:
- Follows path very closely
- Minimal cutting of corners
- Good for paths requiring precision
- Choppy motion on curves
- Oscillation around path
- Slower overall speed
Medium lookahead (e.g., 30-60)
Medium lookahead (e.g., 30-60)
Pros:
- Balanced smoothness and accuracy
- Good for most applications
- Stable performance
- May cut some corners
- Requires tuning for specific paths
Large lookahead (e.g., 60+)
Large lookahead (e.g., 60+)
Pros:
- Very smooth motion
- Fast traversal
- Excellent for wide, sweeping curves
- Significant corner cutting
- May miss fine path details
- Can become unstable on tight turns
Adaptive Lookahead
While not implemented in the current Mars-RS code, adaptive lookahead can improve performance:Algorithm Complexity
For each control loop iteration:- Time Complexity: O(n) where n =
lineLookAhead - Space Complexity: O(1) - only stores current best point
- Update Frequency: 100Hz (10ms sleep)
Comparison with Other Algorithms
| Feature | Pure Pursuit | Boomerang | pidMTP |
|---|---|---|---|
| Path accuracy | High | Medium | N/A (point-to-point) |
| Motion smoothness | Very High | High | Medium |
| Computational cost | Medium | Low | Low |
| Corner cutting | Some | Moderate | None |
| Best for | Complex paths | Goal poses | Simple movements |
Practical Example
Creating a Pure Pursuit path follower:Related Topics
Movement Algorithms
Compare Pure Pursuit with other algorithms
PID Control
Tune the PID controllers for Pure Pursuit
Robot Physics
Understand the robot’s motion model