Ben Katz
/
Hobbyking_Cheetah_V1
FOC Implementation for putting multirotor motors in robots
Embed:
(wiki syntax)
Show/hide line numbers
Transforms.cpp
00001 #include "mbed.h" 00002 #include "Transforms.h" 00003 #include "FastMath.h" 00004 00005 using namespace FastMath; 00006 00007 void Transforms::Park(float alpha, float beta, float theta, float *d, float *q){ 00008 //float cosine = cos(theta); 00009 //float sine = sin(theta); 00010 float cosine = FastCos(theta); 00011 float sine = FastSin(theta); 00012 //*d = alpha*cosine - beta*sine; //This is a hack - effectively using -beta instead of beta 00013 //*q = -beta*cosine - alpha*sine; //I think because I'm using pi as the d axis offset instead of zero, but I need to investigate more. 00014 *d = alpha*cosine + beta*sine; 00015 *q = beta*cosine - alpha*sine; 00016 //DAC->DHR12R1 = (int) (*q*49.648f) + 2048; 00017 //DAC->DHR12R1 = (int) (*q*2048.0f) + 2048; 00018 } 00019 00020 void Transforms::InvPark(float d, float q, float theta, float *alpha, float *beta){ 00021 //float cosine = cos(theta); 00022 //float sine = sin(theta); 00023 float cosine = FastCos(theta); 00024 float sine = FastSin(theta); 00025 *alpha = d*cosine - q*sine; 00026 *beta = q*cosine + d*sine; 00027 } 00028 00029 void Transforms::Clarke(float a, float b, float *alpha, float *beta){ 00030 *alpha = a; 00031 *beta = 0.57735026919f*(a + 2.0f*b); 00032 } 00033 00034 void Transforms::InvClarke(float alpha, float beta, float *a, float *b, float *c){ 00035 *a = alpha; 00036 *b = 0.5f*(-alpha + 1.73205080757f*beta); 00037 *c = 0.5f*(-alpha - 1.73205080757f*beta); 00038 } 00039
Generated on Wed Jul 13 2022 02:31:45 by 1.7.2