Lab 9: Measured Tuning and Discretization

Goal: measure our drivetrain instead of guessing, and fix the "drifting in an arc" when driving while spinning.

Part A: SysId

In Lab 6 we guessed kS and kV and adjusted until it looked right. SysId measures them (it works in simulation too; the simulator's friction shows up as kS): it applies known voltages, records speeds, and fits the line volts = kS + kV·v + kA·a.

  1. Read the current WPILib SysId docs. The API changes between seasons.
  2. Create a SysIdRoutine that drives all four modules pointed forward with the same voltage, and logs voltage, distance, and velocity.
  3. Bind its four tests (quasistatic forward/back, dynamic forward/back) to buttons. Run each one.
  4. Load the log in the SysId tool and read kS, kV, kA.
Our Lab 6 guess SysId Difference
kS
kV
kA n/a

Measure top speed: full stick, straight line, read the max DriveVelocityMps. Compare to MAX_THEORETICAL_SPEED. In sim it's a bit lower because of friction. On a real robot expect ~80–90%: why even less?

Part B: Discretization

The problem. We send new ChassisSpeeds every 20 ms, and the robot moves in a straight line at that speed until the next update. But when the robot is spinning, "forward" for the robot keeps turning during those 20 ms. The result: driving straight while spinning, the robot drifts sideways in an arc, always in the direction of the spin.

asked for:  ────────────►          got:  ────────╮
            (spinning)                           ╰─► drifts toward the spin

The fix. ChassisSpeeds.discretize(speeds, 0.02) works out the straight-line speeds that, combined with the rotation over 20 ms, land the robot where we actually wanted it. It uses a twist: the math for "move along an arc". You don't need the formula; the idea is "aim a little ahead of the turn".

if (Tunable.toggle("Drive/UseDiscretize", true)) {
  speeds = ChassisSpeeds.discretize(speeds, 0.02);   // 20 ms loop; check current WPILib docs for the signature
}

Experiments

Change Predict What you'll see
Field-relative, drive straight across the room at 1.5 m/s while spinning fast, UseDiscretize off The path curves toward the spin direction
Same, on Much straighter
Spin the other way The arc flips sides
Plug SysId's kS/kV into Lab 6's tunables Speed tracking better with less kP

Checkpoint

Summary: SysId measures feedforward gains from data. Discretization corrects the skew from translating while rotating.

Quiz

  1. What does SysId's quasistatic test measure? The dynamic test?
  2. Why is real top speed lower than theoretical?
  3. Why does the arc curve toward the spin direction?
  4. Change Sim/DriveFrictionVolts and re-run SysId. Which gain changes?

What could go wrong in the real world: running SysId on a different surface than you compete on; a low battery during SysId giving wrong gains; not enough room, so the dynamic test gets cut short.