-
Notifications
You must be signed in to change notification settings - Fork 12
/
transforms.c
executable file
·36 lines (32 loc) · 1.19 KB
/
transforms.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "transforms.h"
#include <math.h>
#include "utils.h"
void transforms_park(volatile float alpha, volatile float beta, volatile float theta, volatile float *d, volatile float *q)
{
float sin, cos;
utils_sincos(fmod(theta, 360), &sin, &cos);
*d = alpha * cos + beta * sin;
*q = beta * cos - alpha * sin;
}
void transforms_inverse_park(volatile float d, volatile float q, volatile float theta, volatile float *alpha, volatile float *beta)
{
float sin, cos;
utils_sincos(fmod(theta, 360), &sin, &cos);
*alpha = d * cos - q * sin;
*beta = d * sin + q * cos;
}
void transforms_clarke(volatile float a, volatile float b, volatile float c, volatile float *alpha, volatile float *beta)
{
*alpha = a;
*beta = (ONE_BY_SQRT3 * a) + (TWO_BY_SQRT3 * b);
}
void transforms_inverse_clarke(volatile float alpha, volatile float beta, volatile float *a, volatile float *b, volatile float *c)
{
*a = alpha;
*b = -alpha / 2.0 + (SQRT3_BY_2 * beta);
*c = -alpha / 2.0 - (SQRT3_BY_2 * beta);
// Multiply by 1/sqrt(3) because phase voltages have amplitude 1/sqrt(3) of bus voltage
*a = (ONE_BY_SQRT3 * (*a));
*b = (ONE_BY_SQRT3 * (*b));
*c = (ONE_BY_SQRT3 * (*c));
}