Class EasyCRTConfig
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordRepresents a candidate CRT gear pair. -
Constructor Summary
ConstructorsConstructorDescriptionEasyCRTConfig(Supplier<Angle> absoluteEncoder1AngleSupplier, Supplier<Angle> absoluteEncoder2AngleSupplier) Creates a configuration with suppliers for both absolute encoders. -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturns true when the unique coverage meets or exceeds the configured maximum mechanism range.static EasyCRTConfig.CrtGearPairfindSmallestCrtGearPair(int stage1GearTeeth, double stage2Ratio, Angle maxMechanismAngle, double coverageMargin, int minTeeth, int maxTeeth, int maxIterationsLimit) Finds the smallest gear pair that satisfies coverage and iteration limits.Returns the current angle for absolute encoder 1.Builds a MechanismGearing for encoder 1 from the configured chain or stages.Returns the configured offset for encoder 1 in rotations.Returns the current angle for absolute encoder 2.Builds a MechanismGearing for encoder 2 from the configured chain or stages.Returns the configured offset for encoder 2 in rotations.doubleReturns encoder 1 rotations per mechanism rotation (includes inversion if enabled).doubleReturns encoder 2 rotations per mechanism rotation (includes inversion if enabled).Returns the maximum allowed modular error between predicted and measured encoder 2.Returns the maximum allowed mechanism rotations.Allowed mechanism travel in rotations (max - min).Returns the minimum allowed mechanism rotations.Returns a recommended CRT gear pair if gear-search inputs are configured.Returns unique coverage in mechanism angle, if prime teeth + common scale are set.static booleanisCoprime(int a, int b) Checks whether two integers are coprime.static doubleratioFromChain(int... teethChain) Computes ratio from a simple meshed gear chain (driver/gear/.../encoder).static doubleratioFromCommonDrive(double commonRatio, int driveGearTeeth, int encoderTeeth) Computes ratio from a shared drive stage: commonRatio * (driveGear / encoderGear).static doubleratioFromDriverDrivenPairs(int... driverDrivenPairs) Computes ratio from explicit (driver, driven) stage pairs.withAbsoluteEncoder1Gearing(int... teethChain) Defines a meshed gear chain for encoder 1, ordered from mechanism drive gear to encoder.withAbsoluteEncoder1GearingStages(int... driverDrivenPairs) Defines explicit mesh stages for encoder 1 as (driverTeeth, drivenTeeth) pairs.withAbsoluteEncoder1Inverted(boolean inverted) If true, flips encoder 1 ratio sign (use when the sensor is mounted reversed).withAbsoluteEncoder2Gearing(int... teethChain) Defines a meshed gear chain for encoder 2, ordered from mechanism drive gear to encoder.withAbsoluteEncoder2GearingStages(int... driverDrivenPairs) Defines explicit mesh stages for encoder 2 as (driverTeeth, drivenTeeth) pairs.withAbsoluteEncoder2Inverted(boolean inverted) If true, flips encoder 2 ratio sign (use when the sensor is mounted reversed).withAbsoluteEncoderInversions(boolean encoder1Inverted, boolean encoder2Inverted) Sets inversion for both encoders in one call.withAbsoluteEncoderOffsets(Angle encoder1Offset, Angle encoder2Offset) Sets encoder offsets added to raw absolute readings before wrap (in rotations).withCommonDriveGear(double commonRatio, int driveGearTeeth, int absoluteEncoder1PinionTeeth, int absoluteEncoder2PinionTeeth) Sets ratios using a shared drive gear stage.withCrtGearRecommendationConstraints(double coverageMargin, int minTeeth, int maxTeeth, int maxIterationsLimit) Sets CRT gear recommendation constraints (coverage margin + search bounds).withCrtGearRecommendationInputs(int stage1GearTeeth, double stage2Ratio) Sets the stage1 gear teeth and stage2 ratio inputs used for gear recommendations.withEncoderRatios(double encoder1RotPerMechanismRot, double encoder2RotPerMechanismRot) Sets encoder rotations per mechanism rotation directly for encoder 1 and encoder 2.withMatchTolerance(Angle tolerance) Sets the match tolerance for encoder 2 modular error (in rotations).withMechanismRange(Angle minAngle, Angle maxAngle) Sets the allowed mechanism angle range (in rotations).
-
Constructor Details
-
EasyCRTConfig
public EasyCRTConfig(Supplier<Angle> absoluteEncoder1AngleSupplier, Supplier<Angle> absoluteEncoder2AngleSupplier) Creates a configuration with suppliers for both absolute encoders.- Parameters:
absoluteEncoder1AngleSupplier- supplier that returns the angle for encoder 1absoluteEncoder2AngleSupplier- supplier that returns the angle for encoder 2
-
-
Method Details
-
withEncoderRatios
public EasyCRTConfig withEncoderRatios(double encoder1RotPerMechanismRot, double encoder2RotPerMechanismRot) Sets encoder rotations per mechanism rotation directly for encoder 1 and encoder 2.Use this when you already know the ratios and do not want to describe the gear train. Positive ratios mean the encoder increases with positive mechanism rotation. If an encoder is mounted in reverse, and you cannot set inversion on-device, use
withAbsoluteEncoder1Inverted(boolean)orwithAbsoluteEncoder2Inverted(boolean)to flip the sign.- Parameters:
encoder1RotPerMechanismRot- rotations per mechanism rotation for encoder 1encoder2RotPerMechanismRot- rotations per mechanism rotation for encoder 2- Returns:
- this configuration for chaining
-
withCommonDriveGear
public EasyCRTConfig withCommonDriveGear(double commonRatio, int driveGearTeeth, int absoluteEncoder1PinionTeeth, int absoluteEncoder2PinionTeeth) Sets ratios using a shared drive gear stage.Formula per encoder: ratio = commonRatio * (driveGearTeeth / encoderPinionTeeth). This assumes both encoders are driven off the same drive gear after the shared reduction.
Example: turret gearbox is 12:50 -> 10:110 and the encoders are driven by 30t and 31t gears The common ratio is 110/10, the drive gear is 50T.
If the encoder gears are driven by the turret gear itself, the common ratio is 1, and the drive gear is the turret gear teeth.
Also seeds CRT gear recommendation inputs (stage1 gear teeth + stage2 ratio) so you can call
withCrtGearRecommendationConstraints(double, int, int, int)afterward.- Parameters:
commonRatio- ratio between mechanism and drive geardriveGearTeeth- tooth count on the gear that drives both encoder pinionsabsoluteEncoder1PinionTeeth- tooth count on encoder 1 pinionabsoluteEncoder2PinionTeeth- tooth count on encoder 2 pinion- Returns:
- this configuration for chaining
-
withAbsoluteEncoderOffsets
Sets encoder offsets added to raw absolute readings before wrap (in rotations).If your encoder supports on device zeroing/offsets, configure it there and keep these offsets at zero to avoid double-offsetting.
- Parameters:
encoder1Offset- offset to apply to encoder 1 readingencoder2Offset- offset to apply to encoder 2 reading- Returns:
- this configuration for chaining
-
withMechanismRange
Sets the allowed mechanism angle range (in rotations).- Parameters:
minAngle- minimum allowed mechanism anglemaxAngle- maximum allowed mechanism angle- Returns:
- this configuration for chaining
-
withMatchTolerance
Sets the match tolerance for encoder 2 modular error (in rotations).Lower values are reasonable when backlash and sensor noise are low, but too small can yield no solution; high backlash mechanisms may need larger values. When backlash is the main source of error and not noise, the tolerance can often be close to the backlash.
Experimenting with always pushing the mechanism to one side of the backlash can allow a reduced tolerance, but teams should validate this to ensure it will always solve with their specified tolerance. Tune based on
getLastErrorRotations().Example: mechanism backlash to the encoders is about 1 degree. commonRatio = 11, driveGearTeeth = 50, and encoder2PinionTeeth = 30. Ratio = 18.3333. 1 degree of mechanism backlash is about 0.0509 rotations of the encoder. A tolerance of 0.06 rotations corresponds to about 1.18 degrees at the mechanism (0.06 / 18.33333 * 360), which is only slightly higher than the backlash.
- Parameters:
tolerance- allowable modular error for encoder 2- Returns:
- this configuration for chaining
-
withAbsoluteEncoder1Inverted
If true, flips encoder 1 ratio sign (use when the sensor is mounted reversed).If your encoder supports on-device direction/inversion, configure it there and keep this false to avoid double-inversion.
- Parameters:
inverted- whether encoder 1 should be inverted- Returns:
- this configuration for chaining
-
withAbsoluteEncoder2Inverted
If true, flips encoder 2 ratio sign (use when the sensor is mounted reversed).If your encoder supports on-device direction/inversion, configure it there and keep this false to avoid double-inversion.
- Parameters:
inverted- whether encoder 2 should be inverted- Returns:
- this configuration for chaining
-
withAbsoluteEncoderInversions
public EasyCRTConfig withAbsoluteEncoderInversions(boolean encoder1Inverted, boolean encoder2Inverted) Sets inversion for both encoders in one call.- Parameters:
encoder1Inverted- whether encoder 1 should be invertedencoder2Inverted- whether encoder 2 should be inverted- Returns:
- this configuration for chaining
-
withCrtGearRecommendationInputs
Sets the stage1 gear teeth and stage2 ratio inputs used for gear recommendations.Call
withCrtGearRecommendationConstraints(double, int, int, int)to configure coverage and search bounds.stage1GearTeethis the gear that drives both encoder pinions, andstage2Ratiois the shared "common ratio" between the mechanism and that drive gear.- Parameters:
stage1GearTeeth- tooth count on the gear that drives both encodersstage2Ratio- common ratio between mechanism and drive gear- Returns:
- this configuration for chaining
-
withCrtGearRecommendationConstraints
public EasyCRTConfig withCrtGearRecommendationConstraints(double coverageMargin, int minTeeth, int maxTeeth, int maxIterationsLimit) Sets CRT gear recommendation constraints (coverage margin + search bounds).Call this after
withCommonDriveGear(double, int, int, int)orwithCrtGearRecommendationInputs(int, double).No-op when not running in simulation to avoid extraneous calculations on a real robot.
- Parameters:
coverageMargin- additional coverage margin multiplierminTeeth- minimum tooth count to searchmaxTeeth- maximum tooth count to searchmaxIterationsLimit- maximum iterations per gear to consider valid- Returns:
- this configuration for chaining
-
withAbsoluteEncoder1Gearing
Defines a meshed gear chain for encoder 1, ordered from mechanism drive gear to encoder.Example:
withAbsoluteEncoder1Gearing(50, 20, 40)means 50T drives 20T, which drives 40T on encoder 1, for a ratio of (50/20) * (20/40) = 50/40. A simpler one-stage chain would bewithAbsoluteEncoder1Gearing(72, 24)for a 3:1 reduction.Not valid for compound same-shaft trains; use
withAbsoluteEncoder1GearingStages(int...)instead.- Parameters:
teethChain- ordered teeth counts from mechanism gear to encoder 1 pinion- Returns:
- this configuration for chaining
-
withAbsoluteEncoder2Gearing
Defines a meshed gear chain for encoder 2, ordered from mechanism drive gear to encoder.Example:
withAbsoluteEncoder2Gearing(50, 20, 40)means 50T drives 20T, which drives 40T on encoder 2, for a ratio of (50/20) * (20/40) = 50/40. A single mesh could bewithAbsoluteEncoder2Gearing(60, 20)for a 3:1 reduction.Not valid for compound same-shaft trains; use
withAbsoluteEncoder2GearingStages(int...)instead.- Parameters:
teethChain- ordered teeth counts from mechanism gear to encoder 2 pinion- Returns:
- this configuration for chaining
-
withAbsoluteEncoder1GearingStages
Defines explicit mesh stages for encoder 1 as (driverTeeth, drivenTeeth) pairs.Use this for compound trains or when you need same-shaft gears represented by separate stages. Example:
withAbsoluteEncoder1GearingStages(12, 36, 18, 60)means 12T drives 36T, then 18T drives 60T. A single stage would bewithAbsoluteEncoder1GearingStages(12, 60).- Parameters:
driverDrivenPairs- alternating driver and driven teeth counts for each stage- Returns:
- this configuration for chaining
-
withAbsoluteEncoder2GearingStages
Defines explicit mesh stages for encoder 2 as (driverTeeth, drivenTeeth) pairs.Use this for compound trains or when you need same-shaft gears represented by separate stages. Example:
withAbsoluteEncoder2GearingStages(12, 36, 18, 60)means 12T drives 36T, then 18T drives 60T.- Parameters:
driverDrivenPairs- alternating driver and driven teeth counts for each stage- Returns:
- this configuration for chaining
-
getAbsoluteEncoder1Gearing
Builds a MechanismGearing for encoder 1 from the configured chain or stages.- Returns:
- gearing representation for encoder 1
-
getAbsoluteEncoder2Gearing
Builds a MechanismGearing for encoder 2 from the configured chain or stages.- Returns:
- gearing representation for encoder 2
-
getAbsoluteEncoder1Angle
Returns the current angle for absolute encoder 1.- Returns:
- angle for encoder 1, or NaN rotation if supplier returns null
-
getAbsoluteEncoder2Angle
Returns the current angle for absolute encoder 2.- Returns:
- angle for encoder 2, or NaN rotation if supplier returns null
-
getAbsoluteEncoder1Offset
Returns the configured offset for encoder 1 in rotations.- Returns:
- offset applied to encoder 1
-
getAbsoluteEncoder2Offset
Returns the configured offset for encoder 2 in rotations.- Returns:
- offset applied to encoder 2
-
getMinMechanismAngle
Returns the minimum allowed mechanism rotations.- Returns:
- minimum rotations for the mechanism
-
getMaxMechanismAngle
Returns the maximum allowed mechanism rotations.- Returns:
- maximum rotations for the mechanism
-
getMechanismRange
Allowed mechanism travel in rotations (max - min).- Returns:
- range of allowed mechanism motion
-
getMatchTolerance
Returns the maximum allowed modular error between predicted and measured encoder 2.- Returns:
- tolerance in rotations
-
getEncoder1RotationsPerMechanismRotation
public double getEncoder1RotationsPerMechanismRotation()Returns encoder 1 rotations per mechanism rotation (includes inversion if enabled).- Returns:
- ratio for encoder 1
-
getEncoder2RotationsPerMechanismRotation
public double getEncoder2RotationsPerMechanismRotation()Returns encoder 2 rotations per mechanism rotation (includes inversion if enabled).- Returns:
- ratio for encoder 2
-
ratioFromChain
public static double ratioFromChain(int... teethChain) Computes ratio from a simple meshed gear chain (driver/gear/.../encoder).Returns encoder rotations per mechanism rotation.
- Parameters:
teethChain- ordered tooth counts from mechanism to encoder- Returns:
- encoder rotations per mechanism rotation
-
ratioFromDriverDrivenPairs
public static double ratioFromDriverDrivenPairs(int... driverDrivenPairs) Computes ratio from explicit (driver, driven) stage pairs.Returns encoder rotations per mechanism rotation.
- Parameters:
driverDrivenPairs- alternating driver and driven teeth counts for each stage- Returns:
- encoder rotations per mechanism rotation
-
ratioFromCommonDrive
public static double ratioFromCommonDrive(double commonRatio, int driveGearTeeth, int encoderTeeth) Computes ratio from a shared drive stage: commonRatio * (driveGear / encoderGear).Returns encoder rotations per mechanism rotation.
- Parameters:
commonRatio- ratio between mechanism and drive geardriveGearTeeth- tooth count on the gear that drives encoder pinionsencoderTeeth- tooth count on the encoder pinion- Returns:
- encoder rotations per mechanism rotation
-
getUniqueCoverage
Returns unique coverage in mechanism angle, if prime teeth + common scale are set.- Returns:
- optional coverage range for the mechanism
-
coverageSatisfiesRange
public boolean coverageSatisfiesRange()Returns true when the unique coverage meets or exceeds the configured maximum mechanism range.Returns false if coverage inputs are missing or non-finite.
- Returns:
- whether coverage satisfies the configured mechanism travel
-
isCoprime
public static boolean isCoprime(int a, int b) Checks whether two integers are coprime.- Parameters:
a- first integerb- second integer- Returns:
- true when the numbers share no common factors beyond 1
-
getRecommendedCrtGearPair
Returns a recommended CRT gear pair if gear-search inputs are configured.- Returns:
- optional gear pair recommendation
-
findSmallestCrtGearPair
public static EasyCRTConfig.CrtGearPair findSmallestCrtGearPair(int stage1GearTeeth, double stage2Ratio, Angle maxMechanismAngle, double coverageMargin, int minTeeth, int maxTeeth, int maxIterationsLimit) Finds the smallest gear pair that satisfies coverage and iteration limits.- Parameters:
stage1GearTeeth- tooth count on the gear that drives both encodersstage2Ratio- ratio between mechanism and drive gearmaxMechanismAngle- maximum mechanism rotations to covercoverageMargin- multiplier to ensure enough unique coverageminTeeth- minimum teeth to considermaxTeeth- maximum teeth to considermaxIterationsLimit- maximum iterations allowed for a gear- Returns:
- gear pair that meets the criteria, or null if none found
-