Speed regulation with zero error.
authorMartin Prudek <prudemar@fel.cvut.cz>
Sat, 16 May 2015 15:00:23 +0000 (17:00 +0200)
committerMartin Prudek <prudemar@fel.cvut.cz>
Sat, 16 May 2015 15:00:23 +0000 (17:00 +0200)
pmsm-control/test_sw/cmd_proc.c
pmsm-control/test_sw/main_pmsm.c
pmsm-control/test_sw/pmsm_state.h

index 640002f..82d5390 100644 (file)
@@ -76,7 +76,6 @@ static void dutySet(struct rpi_state* state, int duty){
        state->pos_reg_ena=0;
        state->spd_reg_ena=0;
        state->commutate=1;
-       printf("duty=");
        sem_post(&state->thd_par_sem);
 }
 
index dd2372d..3d13ff2 100644 (file)
@@ -27,7 +27,8 @@
 
 
 #define PID_P          0.3
-#define PID_P_S                0.7
+#define PID_P_S                0.9     /*2.3 kmita*/ /*1.4 vhodne jen pro P regulator*/
+#define PID_I_S                0.01
 
 #define PRIOR_KERN     50
 #define PRIOR_HIGH     49
@@ -55,7 +56,8 @@ struct rpi_state rps={
        .pos_reg_ena=0,
        .desired_spd=0,
        .spd_reg_ena=0,
-       .old_pos={0}
+       .old_pos={0},
+       .spd_err_sum=0
 };
 
 /**
@@ -539,7 +541,10 @@ inline void pos_pid(){
  */
 inline void spd_pid(){
        int duty_tmp;
-       duty_tmp = PID_P_S*(rps.desired_spd - rps.speed);
+       int error;
+       error=rps.desired_spd - rps.speed;
+       rps.spd_err_sum+=error;
+       duty_tmp = PID_P_S*error+PID_I_S*rps.spd_err_sum;
        if (duty_tmp>MAX_DUTY){
                rps.duty=MAX_DUTY;
        }else if (duty_tmp<-MAX_DUTY){
index 3cd648f..32c8d74 100644 (file)
@@ -31,6 +31,8 @@ struct rpi_state{
        char commutate;                 /* zapina prepocet duty na jednotlive pwm */
        char pos_reg_ena;               /* position regulation enable */
        char spd_reg_ena;               /* speed rugulation enable */
+
+       int spd_err_sum;                /* for speed pid regulator */
 };
 
 #endif /*PMSM_STATE*/