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.
Optimize/Optimize.cpp@31:ebe42589ab9d, 2016-11-10 (annotated)
- Committer:
- bwang
- Date:
- Thu Nov 10 14:43:25 2016 +0000
- Revision:
- 31:ebe42589ab9d
- Child:
- 32:b31423041c4e
added IPM optimization code, commented out decoupling
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| bwang | 31:ebe42589ab9d | 1 | #include <math.h> |
| bwang | 31:ebe42589ab9d | 2 | |
| bwang | 31:ebe42589ab9d | 3 | #include "config_motor.h" |
| bwang | 31:ebe42589ab9d | 4 | #include "Optimize.h" |
| bwang | 31:ebe42589ab9d | 5 | #include "optimize_constants.h" |
| bwang | 31:ebe42589ab9d | 6 | |
| bwang | 31:ebe42589ab9d | 7 | void get_ipm_dq(float tau, float *d, float *q) { |
| bwang | 31:ebe42589ab9d | 8 | float tau2 = tau * tau; |
| bwang | 31:ebe42589ab9d | 9 | float alpha = val_alpha(tau, tau2); |
| bwang | 31:ebe42589ab9d | 10 | float u = fastsqrtf(cA * tau2 / alpha + cB * alpha); |
| bwang | 31:ebe42589ab9d | 11 | float v = fastsqrtf(cC * tau2 / alpha + cD * alpha + cE * tau / u); |
| bwang | 31:ebe42589ab9d | 12 | *q = cU * u + cV * v; |
| bwang | 31:ebe42589ab9d | 13 | *d = (-3 * *q * POLE_PAIRS * FLUX_LINKAGE + 2 * tau) / (3 * *q * Lx * POLE_PAIRS); |
| bwang | 31:ebe42589ab9d | 14 | } |
| bwang | 31:ebe42589ab9d | 15 | |
| bwang | 31:ebe42589ab9d | 16 | float val_alpha(float tau, float tau2) { |
| bwang | 31:ebe42589ab9d | 17 | float tau23 = fastcubertf(tau2); |
| bwang | 31:ebe42589ab9d | 18 | if (tau < TAU0) { |
| bwang | 31:ebe42589ab9d | 19 | return tau23 * K1_13 * (c0 + c2 * tau2 + c4 * tau2 * tau2); |
| bwang | 31:ebe42589ab9d | 20 | } |
| bwang | 31:ebe42589ab9d | 21 | else { |
| bwang | 31:ebe42589ab9d | 22 | return s0 + s1 * (tau - TAU0); |
| bwang | 31:ebe42589ab9d | 23 | } |
| bwang | 31:ebe42589ab9d | 24 | |
| bwang | 31:ebe42589ab9d | 25 | } |
| bwang | 31:ebe42589ab9d | 26 | |
| bwang | 31:ebe42589ab9d | 27 | float fastsqrtf(float x) { |
| bwang | 31:ebe42589ab9d | 28 | return sqrtf(x); |
| bwang | 31:ebe42589ab9d | 29 | } |
| bwang | 31:ebe42589ab9d | 30 | |
| bwang | 31:ebe42589ab9d | 31 | float fastcubertf(float x) { |
| bwang | 31:ebe42589ab9d | 32 | return powf(x, 1 / 3.f); |
| bwang | 31:ebe42589ab9d | 33 | } |