FRC-1250 / Team-1250-Crescendo2024

MIT License
0 stars 0 forks source link

RobotHelper.isWithingRangeOfTarget does not work for small targets. #31

Closed qwbmo closed 6 months ago

qwbmo commented 7 months ago

The present implementation cannot be satisfied for zero (or near-zero) targets.

public static boolean isWithinRangeOfTarget(double currentValue, double targetValue, double acceptancePercent) { var upperValue = targetValue + (targetValue * acceptancePercent); var lowerValue = targetValue - (targetValue * acceptancePercent); return currentValue >= lowerValue && currentValue <= upperValue; }

With a target value of zero, the upper and lower bounds will also be zero, resulting in a zero-width range to be satisfied. Also, it implies that larger targets get a larger range for the same acceptance percentage. E.g. the shoulder position for the AMP is a high value and needs a smaller acceptancePercentage, while the SPEAKER shot angle is small and therefore needs a larger acceptancePercent to get the same absolute allowed angle error.

Suggest changing acceptance criteria to an error band in the same units as the target.

Rodney-Lewis commented 7 months ago

We should just use the "IsNear" method from WPILib's MathUtil - https://github.wpilib.org/allwpilib/docs/release/java/edu/wpi/first/math/MathUtil.html#isNear(double,double,double)

It meets this static threshold criteria AND supports continuous inputs.

Rodney-Lewis commented 7 months ago

We'll need to test a few thresholds but replaced IsWithinRangeOfTarget with IsNear in relevant places - https://github.com/FRC-1250/Team-1250-Crescendo2024/commit/3ad776eedaf61e3cce18ff2a936a396a7e3e4fc2

Rodney-Lewis commented 6 months ago

Seemed to work for FireNote checks. Verify that this works again for ShoulderPosition after fixing #36.