]> rtime.felk.cvut.cz Git - fpga/rpi-motor-control.git/blobdiff - pmsm-control/test_sw/main_pmsm.c
Controll loop now more complex.
[fpga/rpi-motor-control.git] / pmsm-control / test_sw / main_pmsm.c
index 56b926a11073d6f5a576be48533a6769d61eefca..4ae245b099f497af63c331fea9c32431b20852bb 100644 (file)
@@ -49,7 +49,10 @@ struct rpi_state rps={
        .index_dist=0,          /* distance to index position */
        .index_ok=0,
        .tf_count=0,            /*number of transfer*/
-       .desired_pos=0          /* desired position */
+       .desired_pos=0,         /* desired position */
+       .pos_reg_ena=0,
+       .desired_spd=0,
+       .spd_reg_ena=0
 };
 
 /**
@@ -499,7 +502,7 @@ void comIndDist(){
  * Now only with P-part so that the error doesnt go to zero.
  * TODO: add anti-wind up and I and D parts
  */
-inline void pid(){
+inline void pos_pid(){
        int duty_tmp;
        duty_tmp = PID_P*(rps.desired_pos - (int32_t)data.pozice);
        if (duty_tmp>MAX_DUTY){
@@ -513,6 +516,7 @@ inline void pid(){
 /*
  * \brief
  * Feedback loop.
+ * TODO: replace bunch of 'IFs' with Object-like pattern
  */
 void * read_data(void* param){
        int i;
@@ -535,16 +539,23 @@ void * read_data(void* param){
                        /*subtract initiate postion */
                        rps.tf_count++;
                        substractOffset(&data,&pocatek);
-                       comIndDist();
+
                        if (!rps.index_ok){
                                if (first){
                                        last_index=data.index_position;
                                        first=0;
                                }else if (last_index!=data.index_position){
                                        rps.index_ok=1;
+                                       comIndDist();   /*vypocet vzdalenosti indexu*/
                                }
+                       }else{ /*index je v poradku*/
+                               comIndDist();           /*vypocet vzdalenosti indexu*/
+                       }
+                       /* pocitame sirku plneni podle potreb rizeni*/
+                       if (rps.pos_reg_ena){
+                               pos_pid();
                        }
-                       pid();
+                       /* sirka plneni prepoctena na jednotlive pwm */
                        if (rps.index_ok && rps.commutate){
                                /*simple_ind_dist_commutator(rps.duty);*/
                                /*sin_commutator(rps.duty);*/