Bayley Wang
/
priustroller_3
temp repo
Fork of priustroller_2 by
meta/modulators.cpp@21:da41c08e51bc, 2015-03-09 (annotated)
- Committer:
- nki
- Date:
- Mon Mar 09 05:07:49 2015 +0000
- Revision:
- 21:da41c08e51bc
- Parent:
- 20:3a7eae543153
- Child:
- 22:46d164aa4f1c
fixed an issue with the debug output
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bwang | 11:dccbaa9274c5 | 1 | #include "includes.h" |
bwang | 11:dccbaa9274c5 | 2 | #include "core.h" |
bwang | 11:dccbaa9274c5 | 3 | #include "meta.h" |
bwang | 14:1cc975207995 | 4 | #include "fastmath.h" |
bwang | 14:1cc975207995 | 5 | #include "transforms.h" |
bwang | 11:dccbaa9274c5 | 6 | |
bwang | 20:3a7eae543153 | 7 | void SinusoidalModulator::Update(float valpha, float vbeta) { |
bwang | 13:79e247e54d78 | 8 | //--hack to make duty cycles positive |
bwang | 20:3a7eae543153 | 9 | float dtcA = valpha; |
bwang | 20:3a7eae543153 | 10 | float dtcB = ((-valpha + sqrt(3.0f) * vbeta) / 2.0f); |
bwang | 20:3a7eae543153 | 11 | float dtcC = ((-valpha - sqrt(3.0f) * vbeta) / 2.0f); |
bwang | 13:79e247e54d78 | 12 | _inverter->SetDtcA(dtcA * 0.5f + 0.5f); |
bwang | 13:79e247e54d78 | 13 | _inverter->SetDtcB(dtcB * 0.5f + 0.5f); |
bwang | 13:79e247e54d78 | 14 | _inverter->SetDtcC(dtcC * 0.5f + 0.5f); |
bwang | 14:1cc975207995 | 15 | } |
bwang | 14:1cc975207995 | 16 | |
bwang | 14:1cc975207995 | 17 | void SvmModulator::Update(float valpha, float vbeta) { |
bwang | 14:1cc975207995 | 18 | float va, vb, vc; |
bwang | 19:280c62c71cf8 | 19 | InverseClarke(vbeta, valpha, &va, &vb); |
bwang | 14:1cc975207995 | 20 | vc = -(va + vb); |
bwang | 19:280c62c71cf8 | 21 | |
bwang | 19:280c62c71cf8 | 22 | float dtcA, dtcB, dtcC, t1, t2; |
bwang | 19:280c62c71cf8 | 23 | |
bwang | 19:280c62c71cf8 | 24 | if (va >= 0){ // (xx1) |
bwang | 19:280c62c71cf8 | 25 | if (vb >= 0){ // (x11) |
bwang | 19:280c62c71cf8 | 26 | // Must be Sector 3 since Sector 7 not allowed |
bwang | 19:280c62c71cf8 | 27 | // Sector 3: (0,1,1) 0-60 degrees |
bwang | 19:280c62c71cf8 | 28 | t1 = vb; |
bwang | 19:280c62c71cf8 | 29 | t2 = va; |
bwang | 19:280c62c71cf8 | 30 | } |
bwang | 19:280c62c71cf8 | 31 | else { // (x01) |
bwang | 19:280c62c71cf8 | 32 | if (vc >= 0){ // Sector 5: (1,0,1) 120-180 degrees |
bwang | 19:280c62c71cf8 | 33 | t1 = va; |
bwang | 19:280c62c71cf8 | 34 | t2 = vc; |
bwang | 19:280c62c71cf8 | 35 | } |
bwang | 19:280c62c71cf8 | 36 | else {// Sector 1: (0,0,1) 60-120 degrees |
nki | 21:da41c08e51bc | 37 | t1 = -vc; //was -vb |
nki | 21:da41c08e51bc | 38 | t2 = -vb; //was -vc |
bwang | 19:280c62c71cf8 | 39 | } |
bwang | 19:280c62c71cf8 | 40 | } |
bwang | 19:280c62c71cf8 | 41 | } else { // (xx0) |
bwang | 19:280c62c71cf8 | 42 | if (vb >= 0) { // (x10) |
bwang | 19:280c62c71cf8 | 43 | if (vc >= 0) { // Sector 6: (1,1,0) 240-300 degrees |
bwang | 19:280c62c71cf8 | 44 | t1 = vc; |
bwang | 19:280c62c71cf8 | 45 | t2 = vb; |
bwang | 19:280c62c71cf8 | 46 | } |
bwang | 19:280c62c71cf8 | 47 | else {// Sector 2: (0,1,0) 300-0 degrees |
nki | 21:da41c08e51bc | 48 | t1 = -va; //was -vc |
nki | 21:da41c08e51bc | 49 | t2 = -vc; //was -va |
bwang | 19:280c62c71cf8 | 50 | } |
bwang | 19:280c62c71cf8 | 51 | } |
bwang | 19:280c62c71cf8 | 52 | else { // (x00) |
bwang | 19:280c62c71cf8 | 53 | // Must be Sector 4 since Sector 0 not allowed |
bwang | 19:280c62c71cf8 | 54 | // Sector 4: (1,0,0) 180-240 degrees |
nki | 21:da41c08e51bc | 55 | t1 = -vb; //was -va |
nki | 21:da41c08e51bc | 56 | t2 = -va; //was -vb |
bwang | 19:280c62c71cf8 | 57 | } |
bwang | 19:280c62c71cf8 | 58 | } |
bwang | 19:280c62c71cf8 | 59 | |
bwang | 19:280c62c71cf8 | 60 | dtcA = (1.0f - t1 - t2)/2.0f; |
bwang | 19:280c62c71cf8 | 61 | dtcB = dtcA + t1; |
bwang | 19:280c62c71cf8 | 62 | dtcC = dtcB + t2; |
bwang | 19:280c62c71cf8 | 63 | |
bwang | 19:280c62c71cf8 | 64 | _inverter->SetDtcA(dtcA); |
bwang | 19:280c62c71cf8 | 65 | _inverter->SetDtcB(dtcB); |
bwang | 19:280c62c71cf8 | 66 | _inverter->SetDtcC(dtcC); |
nki | 21:da41c08e51bc | 67 | |
nki | 21:da41c08e51bc | 68 | dbg_dtcA = dtcA; |
nki | 21:da41c08e51bc | 69 | dbg_dtcB = dtcB; |
nki | 21:da41c08e51bc | 70 | dbg_dtcC = dtcC; |
bwang | 11:dccbaa9274c5 | 71 | } |