7
7
float CurrentSense::getDCCurrent (float motor_electrical_angle){
8
8
// read current phase currents
9
9
PhaseCurrent_s current = getPhaseCurrents ();
10
- // currnet sign - if motor angle not provided the magnitude is always positive
11
- float sign = 1 ;
12
-
10
+
13
11
// calculate clarke transform
14
- float i_alpha, i_beta;
15
- if (!current.c ){
16
- // if only two measured currents
17
- i_alpha = current.a ;
18
- i_beta = _1_SQRT3 * current.a + _2_SQRT3 * current.b ;
19
- }else if (!current.a ){
20
- // if only two measured currents
21
- float a = -current.c - current.b ;
22
- i_alpha = a;
23
- i_beta = _1_SQRT3 * a + _2_SQRT3 * current.b ;
24
- }else if (!current.b ){
25
- // if only two measured currents
26
- float b = -current.a - current.c ;
27
- i_alpha = current.a ;
28
- i_beta = _1_SQRT3 * current.a + _2_SQRT3 * b;
29
- }else {
30
- // signal filtering using identity a + b + c = 0. Assumes measurement error is normally distributed.
31
- float mid = (1 .f /3 ) * (current.a + current.b + current.c );
32
- float a = current.a - mid;
33
- float b = current.b - mid;
34
- i_alpha = a;
35
- i_beta = _1_SQRT3 * a + _2_SQRT3 * b;
36
- }
12
+ ABCurrent_s ABcurrent = getABCurrents (current);
13
+
14
+ // current sign - if motor angle not provided the magnitude is always positive
15
+ float sign = 1 ;
37
16
38
17
// if motor angle provided function returns signed value of the current
39
18
// determine the sign of the current
@@ -42,20 +21,34 @@ float CurrentSense::getDCCurrent(float motor_electrical_angle){
42
21
float ct;
43
22
float st;
44
23
_sincos (motor_electrical_angle, &st, &ct);
45
- sign = (i_beta *ct - i_alpha *st) > 0 ? 1 : -1 ;
24
+ sign = (ABcurrent. beta *ct - ABcurrent. alpha *st) > 0 ? 1 : -1 ;
46
25
}
47
26
// return current magnitude
48
- return sign*_sqrt (i_alpha*i_alpha + i_beta*i_beta );
27
+ return sign*_sqrt (ABcurrent. alpha *ABcurrent. alpha + ABcurrent. beta *ABcurrent. beta );
49
28
}
50
29
51
30
// function used with the foc algorihtm
52
31
// calculating DQ currents from phase currents
53
32
// - function calculating park and clarke transform of the phase currents
54
- // - using getPhaseCurrents internally
33
+ // - using getPhaseCurrents and getABCurrents internally
55
34
DQCurrent_s CurrentSense::getFOCCurrents (float angle_el){
56
35
// read current phase currents
57
36
PhaseCurrent_s current = getPhaseCurrents ();
58
37
38
+ // calculate clarke transform
39
+ ABCurrent_s ABcurrent = getABCurrents (current);
40
+
41
+ // calculate park transform
42
+ DQCurrent_s return_current = getDQCurrents (ABcurrent,angle_el);
43
+
44
+ return return_current;
45
+ }
46
+
47
+ // function used with the foc algorihtm
48
+ // calculating Alpha Beta currents from phase currents
49
+ // - function calculating Clarke transform of the phase currents
50
+ ABCurrent_s CurrentSense::getABCurrents (PhaseCurrent_s current){
51
+
59
52
// calculate clarke transform
60
53
float i_alpha, i_beta;
61
54
if (!current.c ){
@@ -81,13 +74,23 @@ DQCurrent_s CurrentSense::getFOCCurrents(float angle_el){
81
74
i_beta = _1_SQRT3 * a + _2_SQRT3 * b;
82
75
}
83
76
84
- // calculate park transform
77
+ ABCurrent_s return_ABcurrent;
78
+ return_ABcurrent.alpha = i_alpha;
79
+ return_ABcurrent.beta = i_beta;
80
+ return return_ABcurrent;
81
+ }
82
+
83
+ // function used with the foc algorihtm
84
+ // calculating D and Q currents from Alpha Beta currents and electrical angle
85
+ // - function calculating Clarke transform of the phase currents
86
+ DQCurrent_s CurrentSense::getDQCurrents (ABCurrent_s current, float angle_el){
87
+ // calculate park transform
85
88
float ct;
86
89
float st;
87
90
_sincos (angle_el, &st, &ct);
88
91
DQCurrent_s return_current;
89
- return_current.d = i_alpha * ct + i_beta * st;
90
- return_current.q = i_beta * ct - i_alpha * st;
92
+ return_current.d = current. alpha * ct + current. beta * st;
93
+ return_current.q = current. beta * ct - current. alpha * st;
91
94
return return_current;
92
95
}
93
96
@@ -96,4 +99,4 @@ DQCurrent_s CurrentSense::getFOCCurrents(float angle_el){
96
99
*/
97
100
void CurrentSense::linkDriver (BLDCDriver* _driver) {
98
101
driver = _driver;
99
- }
102
+ }
0 commit comments