Class CharacterizeMath

java.lang.Object
com.crossbotics.ftchelper.finders.CharacterizeMath

public final class CharacterizeMath extends Object
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
    Modifier and Type
    Class
    Description
    static final class 
    One fit.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final double
    Battery voltage the numbers are for (a full battery).
  • Method Summary

    Modifier and Type
    Method
    Description
    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).
    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.
    fit(double[] t, double[] volts, double[] power, double[] measured, boolean gravity)
    Fits kS, kV, kA (and kG when gravity) 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 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).
    static double[]
    yawRates(double[] t, double[] headingDeg)
    Turning speed from headings (degrees per second), with the jump at +-180 taken out.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • NOMINAL_VOLTS

      public static final double NOMINAL_VOLTS
      Battery 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 when gravity) to a log.
      Parameters:
      t - seconds
      volts - battery volts at each moment
      power - the power the motor was given (-1..1)
      measured - its speed, counts per second
      gravity - 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 second
      yawRateDeg - 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.