Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
FastAtan2.h@3:3f469f0aa3b4, 2016-06-15 (annotated)
- Committer:
- Cotzo
- Date:
- Wed Jun 15 13:19:26 2016 +0000
- Revision:
- 3:3f469f0aa3b4
- Parent:
- 2:8bff2a7afea1
Documentation doxygen
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Cotzo | 3:3f469f0aa3b4 | 1 | /**@file FastAtan2.h |
| Cotzo | 3:3f469f0aa3b4 | 2 | * |
| Cotzo | 3:3f469f0aa3b4 | 3 | * Computes the arctangent using Lagrange polynomial approximation with fixed-point arithmetic. |
| Cotzo | 3:3f469f0aa3b4 | 4 | * |
| Cotzo | 3:3f469f0aa3b4 | 5 | * |
| Cotzo | 3:3f469f0aa3b4 | 6 | */ |
| Cotzo | 1:9110a3da84c9 | 7 | |
| Cotzo | 0:88345d07348b | 8 | #include "mbed.h" |
| Cotzo | 0:88345d07348b | 9 | |
| Cotzo | 1:9110a3da84c9 | 10 | #ifndef FASTATAN2_H_ |
| Cotzo | 1:9110a3da84c9 | 11 | #define FASTATAN2_H_ |
| Cotzo | 0:88345d07348b | 12 | |
| Cotzo | 0:88345d07348b | 13 | #define QFORMAT 15 |
| Cotzo | 1:9110a3da84c9 | 14 | |
| Cotzo | 1:9110a3da84c9 | 15 | /******************* Constant Q15 ********************/ |
| Cotzo | 1:9110a3da84c9 | 16 | |
| Cotzo | 1:9110a3da84c9 | 17 | #define PI_Q15 0x19220 // Pi |
| Cotzo | 1:9110a3da84c9 | 18 | #define PI2_Q15 0xC910 // Pi/2 |
| Cotzo | 1:9110a3da84c9 | 19 | #define PI4_Q15 0x6488 // Pi/4 |
| Cotzo | 1:9110a3da84c9 | 20 | #define PIx2_Q15 0x32440 // 2*Pi |
| Cotzo | 1:9110a3da84c9 | 21 | #define C1 0x1F52 // constante c1 = 0.2447 |
| Cotzo | 1:9110a3da84c9 | 22 | #define C2 0x819 // constante c2 = 0.0663 |
| Cotzo | 1:9110a3da84c9 | 23 | |
| Cotzo | 1:9110a3da84c9 | 24 | /*************** Fixed-point operations ****************/ |
| Cotzo | 0:88345d07348b | 25 | |
| Cotzo | 0:88345d07348b | 26 | #define FSUBI(a,b,q) ((a)-((b)<<(q))) |
| Cotzo | 0:88345d07348b | 27 | #define FMUL(a,b,q) (((a)*(b))>>(q)) |
| Cotzo | 0:88345d07348b | 28 | |
| Cotzo | 1:9110a3da84c9 | 29 | /************** Fixed-point conversions ****************/ |
| Cotzo | 1:9110a3da84c9 | 30 | |
| Cotzo | 0:88345d07348b | 31 | #define TOFIX(d,q) ((int32_t)( (d)*(float)(1<<(q)) )) |
| Cotzo | 0:88345d07348b | 32 | #define TOFLT(a,q) ((float)(a)/(float)(1<<(q))) |
| Cotzo | 1:9110a3da84c9 | 33 | |
| Cotzo | 0:88345d07348b | 34 | #define RAD_Q15_TODEG(rad) ((rad*57)+0x25DC) |
| Cotzo | 0:88345d07348b | 35 | |
| Cotzo | 2:8bff2a7afea1 | 36 | /** Calculates the arc tangent using fixed point q15 |
| Cotzo | 2:8bff2a7afea1 | 37 | * @param x Coordinate |
| Cotzo | 3:3f469f0aa3b4 | 38 | * @param y Coordinate |
| Cotzo | 2:8bff2a7afea1 | 39 | * @returns |
| Cotzo | 2:8bff2a7afea1 | 40 | * The function returns the principal arc tangent of y/x, in the interval [0,+pi/2] radians in format Q15 |
| Cotzo | 2:8bff2a7afea1 | 41 | */ |
| Cotzo | 0:88345d07348b | 42 | |
| Cotzo | 0:88345d07348b | 43 | int32_t atan_q15(uint32_t x,uint32_t y); |
| Cotzo | 2:8bff2a7afea1 | 44 | |
| Cotzo | 2:8bff2a7afea1 | 45 | /** Calculates the arc tangent using fixed point q15 |
| Cotzo | 2:8bff2a7afea1 | 46 | * @param x Coordinate |
| Cotzo | 2:8bff2a7afea1 | 47 | * @param y Coordinate |
| Cotzo | 2:8bff2a7afea1 | 48 | * @returns |
| Cotzo | 2:8bff2a7afea1 | 49 | * The function returns the principal arc tangent of y/x, with the correct quadrant in the interval [-pi,+pi] radians in format Q15 |
| Cotzo | 2:8bff2a7afea1 | 50 | */ |
| Cotzo | 2:8bff2a7afea1 | 51 | |
| Cotzo | 0:88345d07348b | 52 | int32_t atan2_q15(int32_t x,int32_t y); |
| Cotzo | 0:88345d07348b | 53 | |
| Cotzo | 3:3f469f0aa3b4 | 54 | #endif /* FASTATAN2_H_ */ |
| Cotzo | 0:88345d07348b | 55 | |
| Cotzo | 3:3f469f0aa3b4 | 56 | /** |
| Cotzo | 3:3f469f0aa3b4 | 57 | * |
| Cotzo | 3:3f469f0aa3b4 | 58 | */ |