Linear elevators and pivoting arms cannot be controlled like simple flywheels. When power is removed, gravity pulls them toward the ground. Furthermore, commanding an unprofiled step jump in position causes severe mechanical shock that can bend aluminum tubes or snap cables.
This lesson teaches how to counteract gravity with and generate smooth, jerk-limited trajectories using Motion Magic in Phoenix Tuner X.
To see how gravity feedforward () prevents position droop without requiring excessive or unstable integral gain, explore the PID & Feedforward Simulator with the Tuned Elevator preset.
1. Gravity Compensation ()
Section titled “1. Gravity Compensation (kGkGkG)”Before tuning PID feedback, software must provide the baseline holding voltage that supports the mechanism’s mass against gravity.
Linear Elevators: Static Gravity
Section titled “Linear Elevators: Static Gravity”On a linear elevator, the downward force of gravity is constant regardless of whether the carriage is at the bottom or top of the mast:
V_gravity = kG
- Support the carriage with a hand.
- In Tuner X Control tab, select Duty Cycle.
- Slowly increase voltage until the carriage floats stationary without rising or falling when you remove your hand.
- Record this value as (typically
0.30Vto0.60Vdepending on rigging friction and gearing).
Single-Jointed Arms: Cosine Gravity
Section titled “Single-Jointed Arms: Cosine Gravity”On a rotating arm, gravity exerts maximum torque when the arm is horizontal (0°) and zero torque when the arm is vertical (90°):
V_gravity = kG · cos(θ)
- Move the arm to exactly horizontal (0° relative to ground).
- Command Duty Cycle voltage until the arm balances horizontally without drifting downward.
- Record this voltage as (typically
0.40Vto0.90V).
2. Configuring Motion Magic Parameters
Section titled “2. Configuring Motion Magic Parameters”Motion Magic replaces instantaneous setpoint jumps with a smooth trapezoidal or S-curve trajectory calculated onboard the Talon FX at 1,000 Hz.
Navigate to Config -> Motion Magic in Tuner X:
- Motion Magic Cruise Velocity: Maximum steady speed during travel.
- Start conservatively:
30.0 rot/sfor an elevator,20.0 rot/sfor an arm.
- Start conservatively:
- Motion Magic Acceleration: Maximum rate of velocity change.
- Set to approximately 2x cruise velocity:
60.0 rot/s².
- Set to approximately 2x cruise velocity:
- Motion Magic Jerk: Rate of acceleration change (derivative of acceleration).
- Set to
600.0 rot/s³to create an S-curve that eliminates mechanical lash in chain drives and gearboxes.
- Set to
3. Tuning Feedback Gains in Slot 0
Section titled “3. Tuning Feedback Gains in Slot 0”With gravity and trajectory parameters defined, tune the feedback gains in Config -> Slot 0:
- Set Gravity Type:
- For an elevator:
GravityType = Elevator_Static. - For an arm:
GravityType = Arm_Cosine.
- For an elevator:
- Enter : Input the holding voltage measured in Step 1.
- Tune Proportional Gain ():
- Start with
kP = 2.0. - In the Control tab, select Motion Magic Voltage, choose Slot 0, and command a target position (e.g.
10.0 rotations). - Increase
kPin steps of1.0until the mechanism tracks the trajectory profile closely.
- Start with
- Add Derivative Damping ():
- If the mechanism overshoots slightly upon arriving at the destination, add a small derivative gain (
kD = 0.10to0.25) to eliminate oscillation.
- If the mechanism overshoots slightly upon arriving at the destination, add a small derivative gain (
If an elevator stops 0.5 inches short of its target, do not add integral gain (). An elevator stopping short indicates that is slightly low or (static friction) was omitted. Add feedforward rather than integral gain.
Common Failure Modes
Section titled “Common Failure Modes”1. Arm Holds at One Angle but Drops at Another
Section titled “1. Arm Holds at One Angle but Drops at Another”- Symptom: Arm stays at 90°, but droops severely at 20°.
- Cause: Gravity type was set to
Elevator_Staticinstead ofArm_Cosine, or the zero angle was calibrated at vertical instead of horizontal. - Fix: Re-zero the sensor so that 0° aligns with true horizontal, and select
Arm_Cosine.
2. High-Frequency Shudder at Setpoint
Section titled “2. High-Frequency Shudder at Setpoint”- Symptom: Mechanism arrives at target and shudders or buzzes violently.
- Cause:
kPis too high, orkDis amplifying sensor measurement noise. - Fix: Decrease
kDto 0, reducekPby 40%, and ensure the gearbox has no mechanical binding.
Check Your Work
Section titled “Check Your Work”- Command the mechanism to move between minimum and maximum setpoints three times in Tuner X.
- Observe the following:
- Trajectory curves on the plot are smooth without velocity spikes.
- Position settles within 0.02 rotations of the target.
- When stationary at target, stator current is steady and the motor is silent.
Verified Sources & Standards
- CTRE Phoenix 6 Motion Magic Configurationv6.docs.ctr-electronics.comHardware Vendor
- WPILib ProfiledPIDController & TrapezoidProfiledocs.wpilib.orgWPILib Standard