Package com.marslib.util
Class OnlineFeedforwardEstimator
java.lang.Object
com.marslib.util.OnlineFeedforwardEstimator
A Zero-GC, realtime Feedforward extractor that continuously monitors mechanism telemetry
(Voltage, Velocity, Acceleration) to compute empirical kV and kA values dynamically.
It uses a sliding-window Ordinary Least Squares (OLS) regression algorithm on a 2-variable system (Velocity & Acceleration) against Effective Voltage (Voltage - kS). By operating strictly over periods of contiguous movement (vel > threshold), it avoids static friction nonlinearities.
Students: You can use this to perfectly dial in your Feedforward models without running a formal SysId sequence.
-
Constructor Summary
ConstructorsConstructorDescriptionOnlineFeedforwardEstimator(String name, int windowSize, double ksVolts) Constructs the Online Estimator. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddMeasurement(double appliedVoltage, double velocity, double acceleration) Feeds the live telemetry into the sliding regression window.doubleRetrieves the latest fully-regressed Acceleration Feedforward constant.doubleRetrieves the latest fully-regressed Velocity Feedforward constant.
-
Constructor Details
-
OnlineFeedforwardEstimator
Constructs the Online Estimator.- Parameters:
name- The AdvantageScope logging namespace (e.g. "SwerveDrive" or "Shooter").windowSize- The number of contiguous 20ms ticks to calculate over (e.g. 500 = 10sec of data).ksVolts- Theoretical or empirical kS (static friction voltage) to subtract from the model.
-
-
Method Details
-
addMeasurement
public void addMeasurement(double appliedVoltage, double velocity, double acceleration) Feeds the live telemetry into the sliding regression window.- Parameters:
appliedVoltage- The total voltage passed to the motor.velocity- The velocity of the mechanism (m/s or rad/s).acceleration- The acceleration of the mechanism (m/s^2 or rad/s^2).
-
getEstimatedKV
public double getEstimatedKV()Retrieves the latest fully-regressed Velocity Feedforward constant. -
getEstimatedKA
public double getEstimatedKA()Retrieves the latest fully-regressed Acceleration Feedforward constant.
-