Added inverse park, clark commutator.
authorMartin Prudek <prudemar@fel.cvut.cz>
Mon, 11 May 2015 14:27:30 +0000 (16:27 +0200)
committerMartin Prudek <prudemar@fel.cvut.cz>
Mon, 11 May 2015 14:27:30 +0000 (16:27 +0200)
pmsm-control/test_sw/main_pmsm.c

index da278cc..4c51f51 100644 (file)
@@ -41,7 +41,6 @@
 struct rpi_in data;
 struct rpi_state rps={
        .spi_dat=&data,
-       .thd_par_sem=NULL,
        .test=0,
        .pwm1=0,.pwm2=0, .pwm3=0,
        .pwm1=0, .t_pwm2=0, .t_pwm3=0,
@@ -87,7 +86,45 @@ void substractOffset(struct rpi_in* data, struct rpi_in* offset){
        data->pozice-=offset->pozice;
        return;
 }
+/*
+ * \brief
+ * Transformace pro uhel pocitany po smeru hodinovych rucicek
+ */
+void dq2alphabeta(int32_t *alpha, int32_t *beta, int d, int q, int32_t sin, int32_t cos){
+       *alpha=cos*d+sin*q;
+       *beta=-sin*d+cos*q;
+       return;
+}
+void alphabeta2pwm3(int32_t * pwma, int32_t * pwmb, int32_t *pwmc,int32_t alpha, int32_t beta){
+       *pwma=alpha;
+       *pwmb=-alpha/2+beta*887/1024;
+       *pwmc=-alpha/2-beta*887/1024;
+}
+void inv_trans_comm(int duty){
+       uint32_t pos;
+       int32_t sin, cos;
+       int32_t alpha, beta;
+       int32_t pwma,pwmb,pwmc;
+       pos=rps.index_dist;
+       /*melo by byt urceno co nejpresneji, aby faze 'a' splyvala s osou 'alpha'*/
+       pos+=717;
+       /*use it as cyclic 32-bit logic*/
+       pos*=4294967;
+       pxmc_sincos_fixed_inline(&sin, &cos, pos, 16);
+       dq2alphabeta(&alpha, &beta,0,duty, sin, cos);
+       alpha>>=16;
+       beta>>=16;
+       alphabeta2pwm3(&pwma,&pwmb, &pwmc,alpha,beta);
 
+       if (pwma<0) pwma=0;
+       if (pwmb<0) pwmb=0;
+       if (pwmc<0) pwmc=0;
+
+
+       rps.pwm1=(uint16_t)pwma;
+       rps.pwm3=(uint16_t)pwmb;
+       rps.pwm2=(uint16_t)pwmc;
+}
 
 void prepare_tx(uint8_t * tx){
 
@@ -439,7 +476,8 @@ void * read_data(void* param){
                        pid();
                        if (rps.index_ok && rps.commutate){
                                /*simple_ind_dist_commutator(rps.duty);*/
-                               sin_commutator(rps.duty);
+                               /*sin_commutator(rps.duty);*/
+                               inv_trans_comm(rps.duty);
                        }else if(!rps.index_ok && rps.commutate){
                                simple_hall_commutator(rps.duty);
                        }