YAMS
Yet Another Mechanism System
Loading...
Searching...
No Matches
Public Member Functions | List of all members
yams::units::EasyCRT Class Reference

#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
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ EasyCRT()

yams::units::EasyCRT::EasyCRT ( int  sharedGearTeeth,
int  encoderATeeth,
int  encoderBTeeth 
)

Create a solver from the tooth counts of the three gears.

Parameters
sharedGearTeethTeeth on the gear both encoder pinions mesh with. The solved angle is the angle of this gear.
encoderATeethTeeth on the pinion of encoder A.
encoderBTeethTeeth on the pinion of encoder B.
Exceptions
std::invalid_argumentif any tooth count is zero or negative.

Member Function Documentation

◆ GetUniqueRange()

wpi::units::turn_t yams::units::EasyCRT::GetUniqueRange ( ) const

Get how far the shared gear can turn before the pair of encoder readings repeats.

Returns
The unique range of the shared gear.

◆ Solve() [1/2]

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.

Parameters
encoderAEncoder A reading.
encoderBEncoder B reading.
Returns
The angle of the shared gear, or std::nullopt if the two readings do not agree on one.

◆ Solve() [2/2]

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.

Parameters
encoderAEncoder A reading.
encoderBEncoder B reading.
minAngleLowest angle the shared gear can be at.
maxAngleHighest angle the shared gear can be at.
Returns
The angle of the shared gear, or std::nullopt if the two readings do not agree on one.
Exceptions
std::invalid_argumentif the travel is longer than GetUniqueRange(), or maxAngle is below minAngle.

The documentation for this class was generated from the following file: