|
YAMS
Yet Another Mechanism System
|
#include <EasyCRT.hpp>
Public Member Functions | |
| EasyCRT (int sharedGearTeeth, int encoderATeeth, int encoderBTeeth) | |
| std::optional< wpi::units::turn_t > | Solve (wpi::units::turn_t encoderA, wpi::units::turn_t encoderB) const |
| std::optional< wpi::units::turn_t > | Solve (wpi::units::turn_t encoderA, wpi::units::turn_t encoderB, wpi::units::turn_t minAngle, wpi::units::turn_t maxAngle) const |
| wpi::units::turn_t | GetUniqueRange () const |
Finds the absolute angle of a gear that turns more than once, from two absolute encoders on pinions with different tooth counts that both mesh with it.
Each encoder only knows its angle within one of its own rotations, but the two readings together are unique over GetUniqueRange(), which is lcm(encoderATeeth, encoderBTeeth) / sharedGearTeeth rotations of the shared gear.
Both encoders must be zeroed with the mechanism at zero, and both must read increasing angles when the mechanism moves in its positive direction. Set the offset and inversion on the encoders themselves, or adjust the readings before passing them in.
This is not a textbook Chinese Remainder Theorem solve. Every angle consistent with encoder A is tried, and the one whose predicted encoder B reading is closest to the real one wins, which stays stable with backlash and sensor noise. Created by team 6911.
| yams::units::EasyCRT::EasyCRT | ( | int | sharedGearTeeth, |
| int | encoderATeeth, | ||
| int | encoderBTeeth | ||
| ) |
Create a solver from the tooth counts of the three gears.
| sharedGearTeeth | Teeth on the gear both encoder pinions mesh with. The solved angle is the angle of this gear. |
| encoderATeeth | Teeth on the pinion of encoder A. |
| encoderBTeeth | Teeth on the pinion of encoder B. |
| std::invalid_argument | if any tooth count is zero or negative. |
| wpi::units::turn_t yams::units::EasyCRT::GetUniqueRange | ( | ) | const |
Get how far the shared gear can turn before the pair of encoder readings repeats.
| std::optional< wpi::units::turn_t > yams::units::EasyCRT::Solve | ( | wpi::units::turn_t | encoderA, |
| wpi::units::turn_t | encoderB | ||
| ) | const |
Solve for the angle of the shared gear, assuming its travel is centered on zero. The result is within half of GetUniqueRange() either side of zero.
| encoderA | Encoder A reading. |
| encoderB | Encoder B reading. |
| std::optional< wpi::units::turn_t > yams::units::EasyCRT::Solve | ( | wpi::units::turn_t | encoderA, |
| wpi::units::turn_t | encoderB, | ||
| wpi::units::turn_t | minAngle, | ||
| wpi::units::turn_t | maxAngle | ||
| ) | const |
Solve for the angle of the shared gear when its travel is not centered on zero.
| encoderA | Encoder A reading. |
| encoderB | Encoder B reading. |
| minAngle | Lowest angle the shared gear can be at. |
| maxAngle | Highest angle the shared gear can be at. |
| std::invalid_argument | if the travel is longer than GetUniqueRange(), or maxAngle is below minAngle. |