Skip to content

Commit

Permalink
Fixed orientation wrapping
Browse files Browse the repository at this point in the history
  • Loading branch information
gabryelreyes committed Nov 6, 2023
1 parent d6dfbbd commit 6de173c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
4 changes: 4 additions & 0 deletions doc/architecture/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ Base equations:
Orientation:
* $alpha [rad] = \frac{distanceRight [mm] - distanceLeft [mm]}{wheelBase [mm]}$
* $orientation' [rad] = orientation [rad] + alpha [rad]$
* $orientation' [rad] = orientation [rad]~\%~2\pi$
* $-2\pi < Orientation < 2\pi$
* After wrapping on the positive limit $2\pi$, the orientation remains positive and starts from 0 again.
* After wrapping on the negative limit $2\pi$, the orientation remains negative and starts from 0 again.

Position:
* $dX [mm] = -distanceCenter [mm] \cdot sin(orientation' [rad])$ <- Approximation for performance reason
Expand Down
15 changes: 1 addition & 14 deletions lib/Service/Odometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,20 +197,7 @@ int32_t Odometry::calculateOrientation(int32_t orientation, int16_t stepsLeft, i

/* Calculate orientation */
orientation += alpha;

/* -2*PI < alpha < +2*PI */
if (FP_2PI() < orientation)
{
orientation = orientation - FP_4PI();
}
else if (-FP_2PI() > orientation)
{
orientation = orientation + FP_4PI();
}
else
{
;
}
orientation %= FP_2PI(); /* -2*PI < orientation < +2*PI */

return orientation;
}
Expand Down

0 comments on commit 6de173c

Please sign in to comment.