Skip to content

4. Control Theory Crash Course

If you tell an elevator motor, “Go up at 6 Volts,” when does it know to stop? If it reaches the target and instantly cuts voltage to zero, gravity will pull the heavy elevator right back down. We need Closed-Loop Control.

1. PID Control

The standard algorithm for reaching a target is PID (Proportional, Integral, Derivative).

  • kP (Proportional): This measures your “Error” (Target minus Current Position). The further you are from the target, the harder it pushes. If the target is 10 meters away, push with 12 Volts. If it’s 1 meter away, push gently with 1 Volt.
  • kD (Derivative): Think of this as the “Brakes.” It slows the mechanism down as you approach the target so you don’t aggressively overshoot it.

2. FeedForward (FF)

PID is reactive. It only applies voltage if there is an existing Error. Why is this bad? If an elevator needs 1 Volt just to hold its heavy weight against gravity, a pure PID loop will droop down, generate Error, push up, reach the target, cut power, droop down… bouncing forever!

Instead, we proactively “Feed Forward” physics math into the motor before PID even calculates. We use the WPILib Feedforward classes to model these behaviors:

  • kS (Static Friction): Motors are sticky. It might take 0.5 Volts just to overcome the friction of the physical gears before movement even begins.
  • kG (Gravity): We calculate the physical weight of the arm/elevator and permanently apply exactly enough voltage to make it weightless in the air.
  • kV (Velocity): How much voltage is mathematically required to move precisely 1 meter per second?

3. The MARSLib Native Advantage

Tuning kP and kV correctly on a 150lb physical robot is inherently dangerous. A typo in a kP constant could command an elevator to punch through the robot’s own chassis frame.

This is where MARSLib steps in. MARSLib abstracts these mathematical concepts. You write your control loops and tune your kP values, but MARSLib intercepts the voltage and pipes it into a highly-accurate virtual physics engine (Dyn4j / AdvantageScope) instead. You can tune your mechanisms, watch them oscillate or break gracefully on your laptop screen, and perfect your constants before we ever place the robot on the FRC carpet.

Ready to leverage the framework? Start the MARSLib Setup Guide, or dive into complex state space modeling and Continuous SysId in our Advanced Control Theory Architecture guide.




📖 Further Reading & External Resources