summaryrefslogtreecommitdiff
path: root/n/asserv/src/dsp.c
diff options
context:
space:
mode:
authorschodet2005-03-27 18:44:56 +0000
committerschodet2005-03-27 18:44:56 +0000
commita46c224de1a250472b476eac28f1854a689d8b11 (patch)
tree8c9b9aae537bed533d6b8fabe402d10a3d0e0cf5 /n/asserv/src/dsp.c
parent14217b088f68687076529d78bacb7feebab43a66 (diff)
Renomage de fonctions DSP.
Nouveaux modes de déplacement. Grands travaux sur le protocol.
Diffstat (limited to 'n/asserv/src/dsp.c')
-rw-r--r--n/asserv/src/dsp.c39
1 files changed, 35 insertions, 4 deletions
diff --git a/n/asserv/src/dsp.c b/n/asserv/src/dsp.c
index 5bbcf65..2c6b21f 100644
--- a/n/asserv/src/dsp.c
+++ b/n/asserv/src/dsp.c
@@ -39,7 +39,7 @@
*
* Angles are mapped from [0, 2pi) to [0,1). */
-/** Add two signed words (i16) and saturate. UNTESTED. */
+/** Add two signed words (i16) and saturate. UNUSED and UNTESTED. */
extern inline int16_t
dsp_add_sat_i16i16 (int16_t a, int16_t b)
{
@@ -315,7 +315,7 @@ dsp_cos_dli (int32_t a)
/** Compute cosinus, angle f8.24, result f8.24. */
int32_t
-dsp_cos (int32_t a)
+dsp_cos_f824 (int32_t a)
{
a &= (1L << 24) - 1;
uint8_t z = ((uint32_t) a >> 16) & 0xc0;
@@ -331,7 +331,7 @@ dsp_cos (int32_t a)
/** Compute sinus, angle f8.24, result f8.24. */
int32_t
-dsp_sin (int32_t a)
+dsp_sin_f824 (int32_t a)
{
a &= (1L << 24) - 1;
uint8_t z = ((uint32_t) a >> 16) & 0xc0;
@@ -347,7 +347,7 @@ dsp_sin (int32_t a)
/** Compute square root, uf24.8. */
uint32_t
-dsp_sqrt (uint32_t x)
+dsp_sqrt_f248 (uint32_t x)
{
uint32_t root, bit, test;
root = 0;
@@ -368,3 +368,34 @@ dsp_sqrt (uint32_t x)
return root << 4;
}
+/** Compute square root, ui32 -> ui16. */
+uint16_t
+dsp_sqrt_ui32 (uint32_t x)
+{
+ uint32_t root, bit, test;
+ root = 0;
+ bit = 1L << 30;
+ do
+ {
+ test = root + bit;
+ //printf ("test = 0x%x, root = 0x%x, bit = 0x%x\n", test, root, bit);
+ if (x >= test)
+ {
+ x -= test;
+ root = test + bit;
+ //printf ("x = 0x%x, root = 0x%x\n", x, root);
+ }
+ root >>= 1;
+ bit >>= 2;
+ } while (bit);
+ return root;
+}
+
+/** Compute hypothenuse, f24.8 -> ui16. Input limited to +-65535 */
+uint16_t
+dsp_hypot (int32_t dx, int32_t dy)
+{
+ dx >>= 8;
+ dy >>= 8;
+ return dsp_sqrt_ui32 (dx * dx + dy * dy);
+}