Skip to content

Commit

Permalink
Bugfix: Wrap around handling in the relative encoders is automaticall…
Browse files Browse the repository at this point in the history
…y applied, no extra algorithm is necessary.
  • Loading branch information
BlueAndi committed Nov 3, 2023
1 parent 90b962e commit 9788c94
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 28 deletions.
19 changes: 2 additions & 17 deletions lib/Service/RelativeEncoders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ void RelativeEncoders::clearRight()

int16_t RelativeEncoders::getCountsLeft() const
{
return calculate(m_absEncoders.getCountsLeft(), m_referencePointLeft);
return m_absEncoders.getCountsLeft() - m_referencePointLeft;
}

int16_t RelativeEncoders::getCountsRight() const
{
return calculate(m_absEncoders.getCountsRight(), m_referencePointRight);
return m_absEncoders.getCountsRight() - m_referencePointRight;
}

/******************************************************************************
Expand All @@ -92,21 +92,6 @@ int16_t RelativeEncoders::getCountsRight() const
* Private Methods
*****************************************************************************/

int16_t RelativeEncoders::calculate(int16_t absSteps, int16_t refPoint) const
{
int16_t diffSteps = absSteps - refPoint;

/* Wrap around in forward or backward direction?
* In both cases the difference must be multiplied with -1.
*/
if (((0 > absSteps) && (0 < refPoint)) || ((0 < absSteps) && (0 > refPoint)))
{
diffSteps *= -1;
}

return diffSteps;
}

/******************************************************************************
* External Functions
*****************************************************************************/
Expand Down
11 changes: 0 additions & 11 deletions lib/Service/RelativeEncoders.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,17 +132,6 @@ class RelativeEncoders
RelativeEncoders();
RelativeEncoders(const RelativeEncoders& relEncoder);
RelativeEncoders& operator=(const RelativeEncoders& relEncoder);

/**
* Calculate relative number of encoder steps between the reference point
* and the current absolute number of encoder steps.
*
* @param[in] absSteps Absolute number of encoder steps
* @param[in] refPoint Reference point
*
* @return Relative number of encoder steps
*/
int16_t calculate(int16_t absSteps, int16_t refPoint) const;
};

/******************************************************************************
Expand Down

0 comments on commit 9788c94

Please sign in to comment.