PI reg. constants modified according rltool results. Added possibility to interactive...
authorMartin Prudek <prudemar@fel.cvut.cz>
Wed, 20 May 2015 14:48:13 +0000 (16:48 +0200)
committerMartin Prudek <prudemar@fel.cvut.cz>
Wed, 20 May 2015 14:48:13 +0000 (16:48 +0200)
pmsm-control/test_sw/cmd_proc.c
pmsm-control/test_sw/main_pmsm.c
pmsm-control/test_sw/pmsm_state.h

index 9625c1d..cc92a0b 100644 (file)
@@ -23,6 +23,7 @@ static void printHelp(){
        puts("duty:[hodnota] - Nastavi pevnou sirku plneni.");
        puts("spd:[hodnota] - Zapne rizeni na danou rychlost.");
        puts("log - Spusti nebo ulozi logovani.");
+       puts("ao:[hodnota] - Prenastavi alpha offset.");
 
        puts("print - Zapne nebo vypne pravidelne vypisovani hodnot.");
        puts("help - Vypne vypisovani hodnot a zobrazi tuto napovedu.");
@@ -129,6 +130,18 @@ static void setSpeed(struct rpi_state* state, int speed){
        sem_post(&state->thd_par_sem);
 }
 
+/*
+ * \brief
+ * Set alpha offset.
+ */
+static void setAlphaOff(struct rpi_state* state, int offset){
+       if (offset<0) offset*=-1;
+       offset%=1000;
+       sem_wait(&state->thd_par_sem);
+       state->alpha_offset=(unsigned short)offset;
+       sem_post(&state->thd_par_sem);
+}
+
 /*
  * \brief
  * Initialize logs
@@ -232,6 +245,8 @@ void poll_cmd(struct rpi_state* state){
                         setSpeed(state, val);
                 }else if (!strcmp(cmd,"log")){
                         setLogSEM(state);
+                }else if (!strcmp(cmd,"ao")){
+                       setAlphaOff(state,val);
                 }
         }
 
@@ -281,6 +296,7 @@ void printData(struct rpi_state* state){
        printf("rychlost=%d\n",s.speed);
        printf("chtena pozice=%d\n",s.desired_pos);
        printf("chtena rychlost=%d\n",s.desired_spd);
+       printf("alpha offset=%hu\n",s.alpha_offset);
        printf("transfer count=%u\n",s.tf_count);
        printf("raw_pozice=%u\n",data_p.pozice_raw);
        printf("raw_pozice last12=%u\n",(data_p.pozice_raw&0x0FFF));
index 4d58037..e4ec9ac 100644 (file)
 
 
 #define PID_P          0.3
-#define PID_P_S                0.8     /*2.3 kmita*/ /*1.4 vhodne jen pro P regulator*/
-#define PID_I_S                0.01
+
+/*     RL-tool results from first order system approx  */
+/*     P=0.16 I=13,4/freq=0.013                        */
+/*     Hodnoty upraveny podle skutecnych vysledku      */
+/*     P=0.8   I=0.01                                  */
+
+#define PID_P_S                0.16            /*2.3 kmita*/ /*1.4 vhodne jen pro P regulator*/
+#define PID_I_S                0.0134
 
 #define PRIOR_KERN     50
 #define PRIOR_HIGH     49
@@ -60,7 +66,8 @@ struct rpi_state rps={
        .spd_err_sum=0,
        .log_col_count=0,       /* pocet radku zaznamu */
        .log_col=0,
-       .doLogs=0
+       .doLogs=0,
+       .alpha_offset=960
 };
 
 /**
@@ -318,7 +325,7 @@ void inv_trans_comm_2(int duty){
        int32_t u1,u2,u3;
        pos=rps.index_dist;
 
-       pos+=960; /*zarovnani faze 'a' s osou 'alpha'*/
+       pos+=rps.alpha_offset; /*zarovnani faze 'a' s osou 'alpha'*/
 
        /*pro výpočet sin a cos je pouzita 32-bit cyklicka logika*/
        pos*=4294967;
index 20e60e6..b3a3125 100644 (file)
@@ -36,6 +36,7 @@ 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 */
+       unsigned short alpha_offset;    /* offset between 'alpha' and 'a' axis */
 
        int spd_err_sum;                /* for speed pid regulator */