Class FinderMath

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

public final class FinderMath extends Object
The arithmetic behind the finders, kept apart so it can be tested on a laptop. Every method is plain math: no hardware. Docs: docs/modules/finders.md
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    correctedDiameter(double oldDiameter, double asked, double measured)
    A corrected wheel diameter after a drive test: the robot was asked for asked inches and really went measured.
    static double
    correctedStrafe(double oldCorrection, double asked, double measured)
    A corrected strafe correction after a sideways test: asked for asked inches, really went measured.
    static double[]
    flywheelPidf(double topTicksPerSec)
    Starting speed-control gains for a flywheel from its top speed (the hub's velocity PIDF).
    static double[]
    limits(double lowEndTicks, double highEndTicks)
    Turns two marked encoder counts ("low end" and "high end") into limits for a mechanism whose code counts UP as it goes UP.
    static double
    pushTicks(int[] deltas)
    The wheel count of a push test from each wheel's change in counts.
    static double
    servoPosition(double position)
    Keeps a servo position inside 0..1, the only range a servo accepts.
    static double
    ticksPerSecToRpm(double ticksPerSec, double countsPerRev)
    Counts per second to RPM (turns per minute), for this many counts per turn.
    static double
    wheelDiameterFromPush(double ticks, double inches, double ticksPerRev, double gearRatio)
    The wheel diameter that matches a "push" test: the robot was pushed inches and the wheels counted ticks.

    Methods inherited from class java.lang.Object

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

    • flywheelPidf

      public static double[] flywheelPidf(double topTicksPerSec)
      Starting speed-control gains for a flywheel from its top speed (the hub's velocity PIDF). F makes the motor send the right power for a speed by itself: the hub's full power is 32767, so F = 32767 / (top speed in counts per second). P = F / 10 and I = P / 10 fix what is left; D = 0. A common starting point for REV hubs; fine-tune F with the flywheel finder.
      Parameters:
      topTicksPerSec - the speed at full power, encoder counts per second (sign ignored)
      Returns:
      {P, I, D, F}, or all zeros if the top speed is 0
    • ticksPerSecToRpm

      public static double ticksPerSecToRpm(double ticksPerSec, double countsPerRev)
      Counts per second to RPM (turns per minute), for this many counts per turn.
    • wheelDiameterFromPush

      public static double wheelDiameterFromPush(double ticks, double inches, double ticksPerRev, double gearRatio)
      The wheel diameter that matches a "push" test: the robot was pushed inches and the wheels counted ticks. One wheel turn = pi x diameter inches = ticksPerRev x gearRatio ticks.
      Returns:
      the diameter in inches, or NaN if the numbers cannot give one
    • correctedDiameter

      public static double correctedDiameter(double oldDiameter, double asked, double measured)
      A corrected wheel diameter after a drive test: the robot was asked for asked inches and really went measured. Went too far = the wheels are really bigger than the setting.
      Returns:
      the new diameter, or NaN if the numbers cannot give one
    • correctedStrafe

      public static double correctedStrafe(double oldCorrection, double asked, double measured)
      A corrected strafe correction after a sideways test: asked for asked inches, really went measured. Went too short = the correction must be bigger.
      Returns:
      the new correction, or NaN if the numbers cannot give one
    • limits

      public static double[] limits(double lowEndTicks, double highEndTicks)
      Turns two marked encoder counts ("low end" and "high end") into limits for a mechanism whose code counts UP as it goes UP. If the high end has the smaller count, the motor counts down as it goes up: then it needs .reversed(), and every count changes sign.
      Returns:
      {min, max, reversed (1 or 0)}
    • pushTicks

      public static double pushTicks(int[] deltas)
      The wheel count of a push test from each wheel's change in counts. All wheels must agree: the same sign, and none less than half of the biggest (a wheel turning the wrong way, or not counting, would spoil the average).
      Returns:
      the average count (negative if every wheel counted down), or NaN if the wheels disagree
    • servoPosition

      public static double servoPosition(double position)
      Keeps a servo position inside 0..1, the only range a servo accepts. NaN becomes 0.5.