-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated cordic trig function to extend input range from angles of [-1…
…80, 180]
- Loading branch information
1 parent
8e476bf
commit 91e5d25
Showing
4 changed files
with
34 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,28 @@ | ||
#include <math/cordic.hpp> | ||
#include <iostream> | ||
#include <iostream> | ||
|
||
CORDIC::Trig CORDIC::trig(int angle) | ||
CORDIC::Trig CORDIC::trig(int32_t angle) | ||
{ | ||
int8_t quadAdj = 1; | ||
//Shift angle to be in range -90 to 90 | ||
if (angle > 16384) { | ||
angle = angle - 32768; | ||
quadAdj = -1; | ||
} | ||
else if (angle < -16384) { | ||
angle = angle + 32768; | ||
quadAdj = -1; | ||
} | ||
int32_t atan2[14] = { 8192, 4836, 2555, 1297, 651, 325, 162, 81, 40, 20, 10, 5, 2, 1 }; | ||
int32_t x = 9949, y = 0, theta = 0, sigma, nx; | ||
int32_t x = 9949, y = 0, theta = 0; | ||
for (int32_t i = 0; i < 14; i++) | ||
{ | ||
sigma = (theta < angle) ? 1 : -1; | ||
int8_t sigma = (angle > theta) ? 1 : -1; | ||
theta = theta + sigma * atan2[i]; | ||
if (theta == angle) break; | ||
nx = x - sigma * (y >> i); | ||
int32_t nx = x - sigma * (y >> i); | ||
y = y + sigma * (x >> i); | ||
x = nx; | ||
} | ||
return { y, x }; | ||
return { quadAdj*x, quadAdj*y }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters