Bayley Wang / Mbed 2 deprecated foc-ed_in_the_bot_compact

Dependencies:   FastPWM3 mbed

Committer:
bwang
Date:
Sat Dec 03 17:49:02 2016 +0000
Revision:
39:80b38a8e1787
Parent:
38:07cb4ae6c1bd
lastest updates; loads of stubs for broken FW and optimization functions

Who changed what in which revision?

UserRevisionLine numberNew 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 38:07cb4ae6c1bd 5 #include "MathHelpers.h"
bwang 31:ebe42589ab9d 6 #include "optimize_constants.h"
bwang 31:ebe42589ab9d 7
bwang 32:b31423041c4e 8 void get_mtpa_dq(float tau, float *d, float *q) {
bwang 37:ba7ebf4f8a78 9 float is = get_mtpa_is(tau);
bwang 37:ba7ebf4f8a78 10 get_mtpa_is_dq(is, d, q);
bwang 31:ebe42589ab9d 11 }
bwang 31:ebe42589ab9d 12
bwang 32:b31423041c4e 13 void get_mtpf_dq(float tau, float w, float umax, float *d, float *q) {
bwang 32:b31423041c4e 14 float x = umax / w;
bwang 32:b31423041c4e 15 x = x * x;
bwang 32:b31423041c4e 16 x *= cH;
bwang 32:b31423041c4e 17 *d = cF - cG - sqrtf(cH * cH + 0.5f * x);
bwang 32:b31423041c4e 18 float y = cI - sqrtf(cI * cI + 0.5f * x);
bwang 32:b31423041c4e 19 *q = x + y * y;
bwang 32:b31423041c4e 20 }
bwang 32:b31423041c4e 21
bwang 37:ba7ebf4f8a78 22 float get_mtpa_is(float tau) {
bwang 37:ba7ebf4f8a78 23 float tau2 = tau * tau;
bwang 37:ba7ebf4f8a78 24 float alpha = val_alpha(tau, tau2);
bwang 37:ba7ebf4f8a78 25 float u = sqrtf(cA * tau2 / alpha + cB * alpha);
bwang 37:ba7ebf4f8a78 26 float v = sqrtf(cC * tau2 / alpha + cD * alpha + cE * tau / u);
bwang 37:ba7ebf4f8a78 27 float q = cU * u + cV * v;
bwang 37:ba7ebf4f8a78 28 float d = (-3 * q * POLE_PAIRS * FLUX_LINKAGE + 2 * tau) / (3 * q * Lx * POLE_PAIRS);
bwang 37:ba7ebf4f8a78 29 return sqrtf(d * d + q * q);
bwang 37:ba7ebf4f8a78 30 }
bwang 37:ba7ebf4f8a78 31
bwang 37:ba7ebf4f8a78 32 void get_mtpa_is_dq(float is, float *d, float *q) {
bwang 38:07cb4ae6c1bd 33 *d = (-FLUX_LINKAGE + sqrtf(PSI2 + 8 * Lx * Lx * is * is)) / (4.f * Lx);
bwang 37:ba7ebf4f8a78 34 *q = sqrtf(is * is - *d * *d);
bwang 37:ba7ebf4f8a78 35 }
bwang 37:ba7ebf4f8a78 36
bwang 39:80b38a8e1787 37 float get_vs2(float w, float d, float q) {
bwang 39:80b38a8e1787 38 return w * w * (Lq * Lq * q * q + (Ld * d + FLUX_LINKAGE) * (Ld * d + FLUX_LINKAGE));
bwang 39:80b38a8e1787 39 }
bwang 39:80b38a8e1787 40
bwang 31:ebe42589ab9d 41 float val_alpha(float tau, float tau2) {
bwang 32:b31423041c4e 42 float tau23 = acbrt(tau2);
bwang 31:ebe42589ab9d 43 if (tau < TAU0) {
bwang 31:ebe42589ab9d 44 return tau23 * K1_13 * (c0 + c2 * tau2 + c4 * tau2 * tau2);
bwang 31:ebe42589ab9d 45 }
bwang 31:ebe42589ab9d 46 else {
bwang 31:ebe42589ab9d 47 return s0 + s1 * (tau - TAU0);
bwang 31:ebe42589ab9d 48 }
bwang 31:ebe42589ab9d 49 }