clarkeinv.comp
1 component clarkeinv "Inverse Clarke transform"; 2 description """The inverse Clarke transform can be used rotate a 3 vector quantity and then translate it from Cartesian coordinate 4 system to a three phase system (three components 120 degrees apart)."""; 5 see_also """\\fBclarke2\\fR and \\fBclarke3\\fR for the forward transform."""; 6 pin in float x; 7 pin in float y "cartesian components of input"; 8 pin in float h "homopolar component of input (usually zero)"; 9 pin in float theta "rotation angle: 0.00 to 1.00 = 0 to 360 degrees"; 10 pin out float a; 11 pin out float b; 12 pin out float c "three phase output vector"; 13 function _; 14 license "GPL"; 15 ;; 16 #include <rtapi_math.h> 17 18 /* for the details, google "clarke transform", or see section 3 of 19 http://focus.ti.com/lit/an/bpra048/bpra048.pdf and/or appendix B of 20 http://www.esat.kuleuven.be/electa/publications/fulltexts/pub_1610.pdf 21 */ 22 23 #define K1 (0.500000000000000) /* 1/2 */ 24 #define K2 (0.866025403784439) /* sqrt(3)/2 */ 25 #define K3 (0.707106781186547) /* 1/sqrt(2) */ 26 #define rev2rad (6.283185308) /* 2 * pi */ 27 28 FUNCTION(_) { 29 double xr, yr, rads, costheta, sintheta; 30 31 // rotate it 32 rads = theta * rev2rad; 33 costheta = cos(rads); 34 sintheta = sin(rads); 35 xr = x * costheta - y * sintheta; 36 yr = x * sintheta + y * costheta; 37 38 /* transform to three phase */ 39 a = xr + K3*h; 40 b = -K1*xr + K2*yr + K3*h; 41 c = -K1*xr - K2*yr + K3*h; 42 }