mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-24 01:31:46 +00:00
[wpilib] Absolute Encoder API and behavior fixes (#4052)
SetPositionOffset was added. Been requested multiple times, and easy to implement. The javadocs mentioned GetPositionInRotation. It has tripped up many people how to get the absolute position from the encoder (You currently have to have precreated the DutyCycle object). Add this method (as GetAbsolutePostition) to make this easier to do. The checks for making sure a matching set of values was read was doing direct double comparisions. This worked ok in the DutyCycle case, but has problems in the analog case. Solve this by using an epsilon comparison. And finally, scale AnalogEncoders analog input to 0-1 instead of 0-5. This was reported a few years ago, but the issue was missed. This caused the encoder to count from 0-5, then 1-6, then 2-7 etc. This is solved and now works correctly. Closes #3188 Closes #4046 Closes #4051 And fixes the following issue on CD https://www.chiefdelphi.com/t/wpilib-analogencoder-java/372649
This commit is contained in:
@@ -71,10 +71,24 @@ class AnalogEncoder : public wpi::Sendable,
|
||||
*/
|
||||
units::turn_t Get() const;
|
||||
|
||||
/**
|
||||
* Get the absolute position of the analog encoder.
|
||||
*
|
||||
* <p>GetAbsolutePosition() - GetPositionOffset() will give an encoder
|
||||
* absolute position relative to the last reset. This could potentially be
|
||||
* negative, which needs to be accounted for.
|
||||
*
|
||||
* <p>This will not account for rollovers, and will always be just the raw
|
||||
* absolute position.
|
||||
*
|
||||
* @return the absolute position
|
||||
*/
|
||||
double GetAbsolutePosition() const;
|
||||
|
||||
/**
|
||||
* Get the offset of position relative to the last reset.
|
||||
*
|
||||
* GetPositionInRotation() - GetPositionOffset() will give an encoder absolute
|
||||
* GetAbsolutePosition() - GetPositionOffset() will give an encoder absolute
|
||||
* position relative to the last reset. This could potentially be negative,
|
||||
* which needs to be accounted for.
|
||||
*
|
||||
@@ -82,6 +96,15 @@ class AnalogEncoder : public wpi::Sendable,
|
||||
*/
|
||||
double GetPositionOffset() const;
|
||||
|
||||
/**
|
||||
* Set the position offset.
|
||||
*
|
||||
* <p>This must be in the range of 0-1.
|
||||
*
|
||||
* @param offset the offset
|
||||
*/
|
||||
void SetPositionOffset(double offset);
|
||||
|
||||
/**
|
||||
* Set the distance per rotation of the encoder. This sets the multiplier used
|
||||
* to determine the distance driven based on the rotation value from the
|
||||
@@ -131,5 +154,6 @@ class AnalogEncoder : public wpi::Sendable,
|
||||
|
||||
hal::SimDevice m_simDevice;
|
||||
hal::SimDouble m_simPosition;
|
||||
hal::SimDouble m_simAbsolutePosition;
|
||||
};
|
||||
} // namespace frc
|
||||
|
||||
Reference in New Issue
Block a user