A Streamlit application for generating and comparing Trapezoidal and S-Curve trajectory profiles.
- Dual Trajectory Generation: Generate both trapezoidal and S-curve trajectories simultaneously
- Side-by-Side Comparison: Visualize both trajectory types on the same graphs
- Comprehensive Profiles: View position, velocity, acceleration, and jerk profiles
- Interactive Parameters: Adjust acceleration limits, jerk limits, cruise speed, and initial conditions
- Export Capability: Save trajectory comparisons as PNG images
- Acceleration Phase: Constant acceleration from initial to cruise velocity
- Cruise Phase: Constant velocity at cruise speed (may be zero duration)
- Deceleration Phase: Constant acceleration from cruise to final velocity
- Jerk Phase 1: Acceleration increases from initial acceleration towards max
- Constant Acceleration: Maintains maximum acceleration (zero jerk)
- Jerk Phase 2: Acceleration decreases to zero
- Cruise Phase: Constant velocity (zero jerk, zero acceleration)
- Jerk Phase 3: Deceleration begins (negative jerk)
- Constant Deceleration: Maintains minimum acceleration (zero jerk)
- Jerk Phase 4: Deceleration decreases to final acceleration
- Create a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies:
pip install -r requirements.txtstreamlit run trajectory_generator.pyThe app provides interactive sliders for:
- Acceleration Limits:
a_maxanda_min - Jerk Limits (S-Curve):
j_maxandj_min - Cruise Speed:
v_cruise - Initial State: Initial velocity and acceleration
- Final State: Final velocity and acceleration
- Distance: Total distance to travel
To validate the implementation with various parameter combinations:
python test_trajectories.pyThe test suite includes 10 test cases covering:
- Rest to rest motion
- Short and long distances
- Non-zero initial/final velocities
- Non-zero initial/final accelerations
- Asymmetric acceleration limits
- Various jerk settings
trajectory-generators/
├── trajectory_base.py # Shared base classes and data structures
├── trajectory_trapezoidal.py # Trapezoidal trajectory generator
├── trajectory_scurve.py # S-curve trajectory generator
├── trajectory_generator.py # Streamlit application
├── plotting.py # Visualization functions
├── test_trajectories.py # Test suite
├── requirements.txt # Python dependencies
└── README.md # This file
| Feature | Trapezoidal | S-Curve |
|---|---|---|
| Phases | 3 | 7 |
| Jerk | Infinite (discontinuous) | Limited by j_max/j_min |
| Smoothness | Step changes in acceleration | Smooth acceleration changes |
| Complexity | Simpler equations | More complex constraint system |
| Flexibility | May fail on short distances | More adaptable to constraints |
| Mechanical Stress | Higher | Lower (smoother motion) |
The trapezoidal trajectory uses symbolic equation solving with two constraint attempts:
- Three-phase solution: Assumes cruise phase reaches
v_cruise - Two-phase solution: If no cruise phase (t2 = 0), solves directly
The S-curve trajectory uses iterative constraint solving:
- Initial attempt: Solve with all 7 phases active
- Constraint relaxation: If phases have negative times, iteratively set them to zero:
- No cruise phase (t4 = 0)
- No constant acceleration phases (t2 = 0 or t6 = 0)
- Various combinations until a valid solution is found
- Validation: Verify final state matches constraints within tolerance
Distance: Δd = d1 + d2 + d3
where d1 = ½(v_i + v_mid)·t1 (acceleration)
d2 = v_mid·t2 (cruise)
d3 = ½(v_mid + v_f)·t3 (deceleration)
Velocity: v_f = v_i + a1·t1 + a3·t3
Peak velocity: v_mid = v_cruise (when t2 > 0)
Distance: Δd = Σ(i=1 to 7) di
where each phase contributes based on initial velocity, acceleration, and jerk
Velocity: v_f = v_i + ∫∫(jerk profile over all phases)
Acceleration: a_f = a_i + ∫(jerk profile over all phases)
Constraints:
- |a| ≤ a_max (or ≥ a_min)
- v ≤ v_cruise
- |j| ≤ j_max (or ≥ j_min)
- S-curve trajectories are more flexible and can handle cases where trapezoidal profiles fail (very short distances, high initial velocities with limited space)
- The "soft" default jerk limits (±1.0 m/s³) provide smooth motion suitable for robotics and automation
- All trajectory generators use SymPy for symbolic equation solving to ensure exact solutions
- The visualization uses high-resolution sampling (1000+ points) for smooth curves
This project is provided as-is for educational and research purposes.