Input Shaping & Jerk Limiting
Executive Summary
Input Shaping (often called "S-Curves" in the CNC world) transforms a square-wave pilot input into a smooth, kinematically feasible curve. This prevents the "jerk" (derivative of acceleration) from exceeding physical limits, which protects the airframe from stress and the camera from vibration.
In ArduPilot, this is split into Attitude Input Shaping (Pilot Feel) and Position Input Shaping (Navigation Smoothness).
Theory & Concepts
1. The Time Constant (ATC_INPUT_TC)
This parameter defines the "softness" of the pilot's stick inputs.
- Low TC (0.1): Crisp, robotic response. The drone stops instantly when the stick is released.
- High TC (0.3): Organic, fluid response. The drone decelerates smoothly to a stop.
- Math: It acts as a low-pass filter on the request, not the output.
2. Jerk Limiting
Jerk ($m/s^3$) is the rate of change of acceleration.
- Infinite Jerk: Instant acceleration (Bang-Bang control). Impossible physically, causes overshoot.
- Limited Jerk: Ramps acceleration up linearly. Resulting velocity profile looks like an "S".
Codebase Investigation
1. Attitude Shaping: input_shaping_angle()
Located in libraries/AC_AttitudeControl/AC_AttitudeControl.cpp.
- Uses a square-root controller to calculate the velocity needed to close the angle error.
- Logic:
desired_ang_vel += sqrt_controller(error_angle, 1.0f / MAX(input_tc, 0.01f), accel_max, dt);
2. Position Shaping: shape_pos_vel_accel_xy()
Located in libraries/AC_AttitudeControl/AC_PosControl.cpp.
- Used in Auto and Guided modes.
- It calculates a valid kinematic path that respects WPNAV_SPEED, WPNAV_ACCEL, and WPNAV_JERK.
- Output: Generates a "Leash" that the position controller follows.
Source Code Reference
- Attitude Shaper:
libraries/AC_AttitudeControl/AC_AttitudeControl.cpp - Position Shaper:
libraries/AC_AttitudeControl/AC_PosControl.cpp
Practical Guide: Tuning for Feel
1. Cinematic Flying
- Goal: Smooth stops, no "bobble" on stick release.
- Set: ATC_INPUT_TC = 0.25 or 0.30.
- Set: LOIT_ACC_MAX = 300 cm/s/s (Gentle braking).
2. FPV Racing / Acro
- Goal: Instant response.
- Set: ATC_INPUT_TC = 0.10 or 0.05.
- Warning: Too low makes the drone feel robotic and exposes P-gain oscillation.
3. Waypoint Mission Smoothness
- Parameter: WPNAV_JERK.
- Default: 1.0 m/s/s/s.
- Tuning: Reducing this to 0.5 makes corners incredibly smooth but increases lap time.