Tuning feedforward gains by trial and error is tedious and error-prone. If is too low, the PID controller must accumulate integral error to overcome steady-state drag. If is omitted, the mechanism lags behind fast trapezoidal motion profiles.
WPILib’s SysId (System Identification) tool automates parameter extraction. By applying controlled voltage waveforms and logging position and velocity, SysId fits ordinary least-squares regression lines to calculate the exact physical coefficients of your mechanism.
1. What to Learn First
Section titled “1. What to Learn First”Before running SysId routines:
- Ensure physical mechanism travel limits, limit switches, and hard stops are mechanically secure.
- Enable binary flight logging via
DataLogManager.start()inRobot.javaas covered in Telemetry Logging.
2. Instrumenting Subsystems with SysIdRoutine
Section titled “2. Instrumenting Subsystems with SysIdRoutine”In your mechanism subsystem (for example, ElevatorSubsystem), declare and configure a SysIdRoutine:
package frc.robot.subsystems;
import edu.wpi.first.wpilibj2.command.SubsystemBase;import edu.wpi.first.wpilibj2.command.Command;import edu.wpi.first.wpilibj2.command.sysid.SysIdRoutine;import edu.wpi.first.units.measure.Voltage;import static edu.wpi.first.units.Units.*;import com.ctre.phoenix6.hardware.TalonFX;import com.ctre.phoenix6.controls.VoltageOut;
public class ElevatorSubsystemWithSysId extends SubsystemBase { private final TalonFX m_motor = new TalonFX(11, "rio"); private final VoltageOut m_voltReq = new VoltageOut(0.0);
// Create the SysIdRoutine helper private final SysIdRoutine m_sysIdRoutine = new SysIdRoutine( new SysIdRoutine.Config( VoltsPerSecond.of(1.0), // Voltage ramp rate: 1.0 V/s for quasistatic test Volts.of(7.0), // Step voltage: 7.0 V for dynamic test Seconds.of(4.0) // Test timeout: 4.0 seconds ), new SysIdRoutine.Mechanism( // Voltage consumer: sends commanded voltage to hardware (Voltage volts) -> m_motor.setControl(m_voltReq.withOutput(volts.in(Volts))), // Telemetry log callback: records position and velocity log -> { log.motor("elevator-motor") .voltage(Volts.of(m_motor.getMotorVoltage().getValueAsDouble())) .linearPosition(Meters.of(m_motor.getPosition().getValueAsDouble() * 0.05)) .linearVelocity(MetersPerSecond.of(m_motor.getVelocity().getValueAsDouble() * 0.05)); }, this ) );
// Expose SysId command factories: public Command sysIdQuasistatic(SysIdRoutine.Direction direction) { return m_sysIdRoutine.quasistatic(direction); }
public Command sysIdDynamic(SysIdRoutine.Direction direction) { return m_sysIdRoutine.dynamic(direction); }}3. Running the Four Characterization Tests
Section titled “3. Running the Four Characterization Tests”SysId requires four distinct tests to isolate static friction, velocity drag, and mass acceleration:
- Quasistatic Forward:
- Slowly ramps voltage (1.0 V/s) upward.
- Measures static friction breakaway () and velocity feedforward ().
- Quasistatic Reverse:
- Slowly ramps voltage downward in the opposite direction.
- Checks directional friction symmetry and isolates gravity bias ().
- Dynamic Forward:
- Applies an instantaneous voltage step (e.g., 7.0 V).
- Measures acceleration feedforward () by capturing the slope of the initial velocity response.
- Dynamic Reverse:
- Applies an instantaneous negative voltage step.
- Measures reverse acceleration dynamics.
On mechanisms with limited travel (arms and elevators), release the test button before the mechanism reaches its physical travel stop! Hitting hard stops at full voltage will corrupt regression data and risk stripping gearbox teeth.
4. Analyzing Data in the SysId Application
Section titled “4. Analyzing Data in the SysId Application”- Connect laptop to the robot and open the SysId tool from VS Code (WPILib: Start Tool -> SysId).
- Click Open Data Log and select the
.wpilogfile downloaded from/u/logs/. - In the analysis window:
- Select your mechanism type (
Elevator,Arm, orSimple). - Inspect the velocity vs. voltage scatter plot.
- Verify that data points form a linear line. If the plot curves upward, mechanical binding or motor current saturation was reached.
- Select your mechanism type (
- Read the calculated constants:
- : Static friction voltage (typically 0.15 to 0.30 V).
- : Velocity feedforward (typically 0.10 to 0.25 V/(rad/s)).
- : Acceleration feedforward (typically 0.01 to 0.05 V/(rad/s²)).
- : Constant holding voltage against gravity.
How Success is Checked
Section titled “How Success is Checked”- Statistical Fit Quality ():
- The linear regression value in the SysId tool must be . An indicates excessive mechanical slop, loose sensor couplings, or hitting travel stops during the run.
- Feedforward Verification:
- Command the mechanism to move at a steady velocity using pure feedforward (
V = kS * sgn(v) + kV * v + kG). - The mechanism must maintain steady velocity within of the target with zero closed-loop PID feedback active.
- Command the mechanism to move at a steady velocity using pure feedforward (
Where to Go Next
Section titled “Where to Go Next”With measured physical constants in hand, proceed to the final lesson: State-Space Modeling, LQR & Kalman Filters to formulate optimal closed-loop controllers.
Verified Sources & Standards
- WPILib SysId Routine Documentationdocs.wpilib.orgWPILib Standard
- WPILib Feedforward Constants Definitiondocs.wpilib.orgWPILib Standard