Class CharacterizeMath
java.lang.Object
com.crossbotics.ftchelper.finders.CharacterizeMath
The math behind the Characterizer: from a log of power, battery voltage and speed, it finds the
motor's feedforward numbers (see control/Feedforward): power = kS x sign(speed) + kV x speed +
kA x acceleration (+ kG for a lift). It is a "least squares" fit: the numbers that make the formula
miss the logged powers by the least, over every moment the motor was moving.
Pure math, no hardware: the OpMode, the simulator's fit tool and the tests all use it. Docs: docs/modules/finders.md ("Characterizer")
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final doubleBattery voltage the numbers are for (a full battery). -
Method Summary
Modifier and TypeMethodDescriptionstatic double[]accelerations(double[] t, double[] v) Speeds-up (acceleration) at each moment, counts per second per second: the slope of a straight line through the speeds within WINDOW_SEC each side (a least-squares slope: it smooths the noise).static doublecoastSec(double[] t, double[] power, double[] v) How long a coasting motor (power 0, FLOAT) takes to slow down: the time for its speed to drop to about 37% (one "time constant"), seconds.static CharacterizeMath.Fitfit(double[] t, double[] volts, double[] power, double[] measured, boolean gravity) Fits kS, kV, kA (and kG whengravity) to a log.static double[]leastSquares(double[][] x, double[] y) The b that makes x b closest to y (least squares).static double[]smoothed(double[] t, double[] v) Speeds averaged over WINDOW_SEC each side (the same window as the speeds-up).static doubleturnDegPerCount(double[] turnCountsPerSec, double[] yawRateDeg) Degrees the robot turns for each wheel count of turning (from the IMU and the wheels), so the simulator turns like the real robot (wheels slip a little when a robot turns).static double[]yawRates(double[] t, double[] headingDeg) Turning speed from headings (degrees per second), with the jump at +-180 taken out.
-
Field Details
-
NOMINAL_VOLTS
public static final double NOMINAL_VOLTSBattery voltage the numbers are for (a full battery).- See Also:
-
-
Method Details
-
accelerations
public static double[] accelerations(double[] t, double[] v) Speeds-up (acceleration) at each moment, counts per second per second: the slope of a straight line through the speeds within WINDOW_SEC each side (a least-squares slope: it smooths the noise). -
smoothed
public static double[] smoothed(double[] t, double[] v) Speeds averaged over WINDOW_SEC each side (the same window as the speeds-up). -
fit
public static CharacterizeMath.Fit fit(double[] t, double[] volts, double[] power, double[] measured, boolean gravity) Fits kS, kV, kA (and kG whengravity) to a log.- Parameters:
t- secondsvolts- battery volts at each momentpower- the power the motor was given (-1..1)measured- its speed, counts per secondgravity- true for a lift (adds kG, the power that holds it against gravity)
-
coastSec
public static double coastSec(double[] t, double[] power, double[] v) How long a coasting motor (power 0, FLOAT) takes to slow down: the time for its speed to drop to about 37% (one "time constant"), seconds. NaN if the log has no coasting. -
turnDegPerCount
public static double turnDegPerCount(double[] turnCountsPerSec, double[] yawRateDeg) Degrees the robot turns for each wheel count of turning (from the IMU and the wheels), so the simulator turns like the real robot (wheels slip a little when a robot turns).- Parameters:
turnCountsPerSec- the wheels' turning speed: (left - right) / 2, counts per secondyawRateDeg- the IMU's turning speed, degrees per second, counterclockwise = +
-
yawRates
public static double[] yawRates(double[] t, double[] headingDeg) Turning speed from headings (degrees per second), with the jump at +-180 taken out. -
leastSquares
public static double[] leastSquares(double[][] x, double[] y) The b that makes x b closest to y (least squares). Null if the columns do not tell the numbers apart.
-