]> rtime.felk.cvut.cz Git - fpga/rpi-motor-control.git/blobdiff - pmsm-control/test_sw/cmd_proc.c
PI reg. constants modified according rltool results. Added possibility to interactive...
[fpga/rpi-motor-control.git] / pmsm-control / test_sw / cmd_proc.c
index a0b059274443aac36e320cd9392c3c1230664e1c..cc92a0b29a13c0c5ec73bdd3b0d609f9c9484ef2 100644 (file)
@@ -8,6 +8,7 @@
 #define PRUM_SOUC      6183
 
 static char doPrint = 1;
+static char error = 0;
 
 /*
  * \brief
@@ -22,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.");
@@ -59,6 +61,9 @@ static void start(struct rpi_state* state){
 static void stop(struct rpi_state* state){
        sem_wait(&state->thd_par_sem);
        state->commutate=0;
+       state->pos_reg_ena=0;
+       state->spd_reg_ena=0;
+       state->duty=0;
        state->pwm1=0;
        state->pwm2=0;
        state->pwm3=0;
@@ -125,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
@@ -135,7 +152,13 @@ static void logInit(struct rpi_state* state){
        state->log_col_count=LOG_DEF_COL;
        for (r=0;r<LOG_ROWS;r++){
                state->logs[r]=malloc(state->log_col_count*sizeof(int));
+               if (state->logs[r]==NULL){
+                       error=1;
+                       state->log_col_count=-1;
+                       return;
+               }
        }
+       state->doLogs=1;
 }
 
 /*
@@ -146,7 +169,7 @@ static void saveLogs(struct rpi_state* state){
        FILE *f;
        int r,s;
 
-       f = fopen("logs.txt", "w");
+       f = fopen("logs.log", "w");
        if (f == NULL){
                printf("Error opening file!\n");
                return;
@@ -182,7 +205,6 @@ static void setLogSEM(struct rpi_state* state){
        /* spustim zachytavani logu */
        }else{
                logInit(state);
-               state->doLogs=1;
                sem_post(&state->thd_par_sem);
        }
 }
@@ -223,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);
                 }
         }
 
@@ -272,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));
@@ -290,4 +315,7 @@ void printData(struct rpi_state* state){
        printf("duty=%d\n",s.duty);
        if (s.index_ok) printf("index ok\n");
        if (s.commutate) printf("commutation in progress\n");
+       if (s.doLogs) printf("logujeme\n");
+       if (error) printf("error pri maloc logs!! \n");
+
 }