a fork of priustroller

Dependencies:   mbed

Fork of priustroller_current by N K

Committer:
nki
Date:
Sat Mar 14 18:51:36 2015 +0000
Revision:
27:846c08fb3697
Parent:
14:1cc975207995
Child:
33:e7b132029bae
NONWORKING: debugging native ADC reading

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bwang 11:dccbaa9274c5 1 #include "includes.h"
bwang 11:dccbaa9274c5 2 #include "transforms.h"
bwang 11:dccbaa9274c5 3 #include "fastmath.h"
bwang 11:dccbaa9274c5 4
bwang 11:dccbaa9274c5 5 void Transforms::Clarke(float a, float b, float *alpha, float *beta) {
bwang 11:dccbaa9274c5 6 *alpha = a;
bwang 11:dccbaa9274c5 7 *beta = (a + 2.0f * b)/sqrt(3.0f);
bwang 11:dccbaa9274c5 8 }
bwang 11:dccbaa9274c5 9
bwang 14:1cc975207995 10 void Transforms::InverseClarke(float alpha, float beta, float *a, float *b) {
bwang 14:1cc975207995 11 *a = alpha;
bwang 14:1cc975207995 12 *b = -0.5 * alpha + sqrt(3.0f) / 2.0f * beta;
bwang 14:1cc975207995 13 }
bwang 14:1cc975207995 14
nki 27:846c08fb3697 15 void Transforms::Parke(float beta, float alpha, float theta, float *d, float *q) {
nki 27:846c08fb3697 16 //reversed alpha and beta order to make d and q ~=constant.
nki 27:846c08fb3697 17 //I did this because alpha was found to be sinusoidal and beta was found to be cosinusoidal. the equation has to take the form sin^2 + cos^2, not sin*cos + sin*cos.
bwang 11:dccbaa9274c5 18 float cos = FastCos(theta);
bwang 11:dccbaa9274c5 19 float sin = FastSin(theta);
nki 27:846c08fb3697 20
bwang 11:dccbaa9274c5 21 *d = alpha * cos + beta * sin;
bwang 11:dccbaa9274c5 22 *q = -alpha * sin + beta * cos;
nki 27:846c08fb3697 23
bwang 11:dccbaa9274c5 24 }
bwang 11:dccbaa9274c5 25
nki 27:846c08fb3697 26 void Transforms::InverseParke(float d, float q, float theta, float *alpha, float *beta) {
bwang 11:dccbaa9274c5 27 float cos = FastCos(theta);
bwang 11:dccbaa9274c5 28 float sin = FastSin(theta);
nki 27:846c08fb3697 29
bwang 11:dccbaa9274c5 30 *alpha = cos * d - sin * q;
nki 27:846c08fb3697 31 *beta = sin * d + cos * q;
nki 27:846c08fb3697 32
bwang 11:dccbaa9274c5 33 }