Class FinderMath
java.lang.Object
com.crossbotics.ftchelper.finders.FinderMath
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 TypeMethodDescriptionstatic doublecorrectedDiameter(double oldDiameter, double asked, double measured) A corrected wheel diameter after a drive test: the robot was asked foraskedinches and really wentmeasured.static doublecorrectedStrafe(double oldCorrection, double asked, double measured) A corrected strafe correction after a sideways test: asked foraskedinches, really wentmeasured.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 doublepushTicks(int[] deltas) The wheel count of a push test from each wheel's change in counts.static doubleservoPosition(double position) Keeps a servo position inside 0..1, the only range a servo accepts.static doubleticksPerSecToRpm(double ticksPerSec, double countsPerRev) Counts per second to RPM (turns per minute), for this many counts per turn.static doublewheelDiameterFromPush(double ticks, double inches, double ticksPerRev, double gearRatio) The wheel diameter that matches a "push" test: the robot was pushedinchesand the wheels countedticks.
-
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 pushedinchesand the wheels countedticks. 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 foraskedinches and really wentmeasured. 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 foraskedinches, really wentmeasured. 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.
-