Skip to content
learnFRC.org
programminglesson35 min

Position Closed-Loop & Motion Magic

Gravity compensation (kG) for arms and elevators, cruise velocities, accelerations, jerk-limited S-curves, and position hold in Tuner X.

What you will learn

  • Calculate and verify gravity feedforward (kG) for elevators and pivoting arms.
  • Configure Motion Magic cruise velocity, acceleration, and jerk-limiting in Tuner X.
  • Tune proportional (kP) and derivative (kD) gains for zero steady-state position error.

Prerequisites:Velocity Closed-Loop Tuning

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 kGkG and generate smooth, jerk-limited trajectories using Motion Magic in Phoenix Tuner X.

Interactive Simulator

To see how gravity feedforward (kGkG) prevents position droop without requiring excessive kPkP or unstable integral gain, explore the PID & Feedforward Simulator with the Tuned Elevator preset.


Before tuning PID feedback, software must provide the baseline holding voltage that supports the mechanism’s mass against 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

  1. Support the carriage with a hand.
  2. In Tuner X Control tab, select Duty Cycle.
  3. Slowly increase voltage until the carriage floats stationary without rising or falling when you remove your hand.
  4. Record this value as kGkG (typically 0.30V to 0.60V depending on rigging friction and gearing).

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(θ)

  1. Move the arm to exactly horizontal (0° relative to ground).
  2. Command Duty Cycle voltage until the arm balances horizontally without drifting downward.
  3. Record this voltage as kGkG (typically 0.40V to 0.90V).

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:

  1. Motion Magic Cruise Velocity: Maximum steady speed during travel.
    • Start conservatively: 30.0 rot/s for an elevator, 20.0 rot/s for an arm.
  2. Motion Magic Acceleration: Maximum rate of velocity change.
    • Set to approximately 2x cruise velocity: 60.0 rot/s².
  3. 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.

With gravity and trajectory parameters defined, tune the feedback gains in Config -> Slot 0:

  1. Set Gravity Type:
    • For an elevator: GravityType = Elevator_Static.
    • For an arm: GravityType = Arm_Cosine.
  2. Enter kGkG: Input the holding voltage measured in Step 1.
  3. Tune Proportional Gain (kPkP):
    • 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 kP in steps of 1.0 until the mechanism tracks the trajectory profile closely.
  4. Add Derivative Damping (kDkD):
    • If the mechanism overshoots slightly upon arriving at the destination, add a small derivative gain (kD = 0.10 to 0.25) to eliminate oscillation.
Never Rely on kI for Gravity

If an elevator stops 0.5 inches short of its target, do not add integral gain (kIkI). An elevator stopping short indicates that kGkG is slightly low or kSkS (static friction) was omitted. Add feedforward rather than integral gain.


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_Static instead of Arm_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.
  • Symptom: Mechanism arrives at target and shudders or buzzes violently.
  • Cause: kP is too high, or kD is amplifying sensor measurement noise.
  • Fix: Decrease kD to 0, reduce kP by 40%, and ensure the gearbox has no mechanical binding.

  1. Command the mechanism to move between minimum and maximum setpoints three times in Tuner X.
  2. 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

Evergreen Standard Verified: Sep 25, 2026