]> rtime.felk.cvut.cz Git - fpga/rpi-motor-control.git/blobdiff - pmsm-control/test_sw/cmd_proc.c
Regulation function now implemented with use of polymorphism.
[fpga/rpi-motor-control.git] / pmsm-control / test_sw / cmd_proc.c
index cc92a0b29a13c0c5ec73bdd3b0d609f9c9484ef2..66e9be804b321c4540db865cc353f8072d094e57 100644 (file)
@@ -3,12 +3,13 @@
 #include <string.h>
 
 #include "cmd_proc.h"
+#include "logs.h"
 
 #define PRUM_PROUD     2061
 #define PRUM_SOUC      6183
 
 static char doPrint = 1;
-static char error = 0;
+
 
 /*
  * \brief
@@ -60,9 +61,8 @@ 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;
+       setCommutationOff(state);
+       setRegulationOff(state);
        state->duty=0;
        state->pwm1=0;
        state->pwm2=0;
@@ -79,9 +79,8 @@ static void dutySet(struct rpi_state* state, int duty){
        if (duty>MAX_DUTY) duty=MAX_DUTY;
        if (duty<-MAX_DUTY) duty=-MAX_DUTY;/*paranoia*/
        state->duty=duty;
-       state->pos_reg_ena=0;
-       state->spd_reg_ena=0;
-       state->commutate=1;
+       setRegulationOff(state);
+       setCommutationOn(state);
        sem_post(&state->thd_par_sem);
 }
 
@@ -91,9 +90,8 @@ static void dutySet(struct rpi_state* state, int duty){
  */
 static void goAbsolute(struct rpi_state* state, int pos){
        sem_wait(&state->thd_par_sem);
-       state->spd_reg_ena=0;
-       state->pos_reg_ena=1;
-       state->commutate=1;
+       setRegulationPos(state);
+       setCommutationOn(state);
        state->desired_pos=pos;
        sem_post(&state->thd_par_sem);
 }
@@ -123,9 +121,8 @@ static void setSpeed(struct rpi_state* state, int speed){
        if (speed>MAX_SPEED) speed=MAX_SPEED;
        if (speed<-MAX_SPEED) speed=-MAX_SPEED;/*paranoia*/
        sem_wait(&state->thd_par_sem);
-       state->pos_reg_ena=0;
-       state->spd_reg_ena=1;
-       state->commutate=1;
+       setRegulationSpeed(state);
+       setCommutationOn(state);
        state->desired_spd=speed;
        sem_post(&state->thd_par_sem);
 }
@@ -142,53 +139,6 @@ static void setAlphaOff(struct rpi_state* state, int offset){
        sem_post(&state->thd_par_sem);
 }
 
-/*
- * \brief
- * Initialize logs
- */
-static void logInit(struct rpi_state* state){
-       int r;
-       state->log_col=0;
-       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;
-}
-
-/*
- * \brief
- * Save logs
- */
-static void saveLogs(struct rpi_state* state){
-       FILE *f;
-       int r,s;
-
-       f = fopen("logs.log", "w");
-       if (f == NULL){
-               printf("Error opening file!\n");
-               return;
-       }
-
-       for (r=0;r<LOG_ROWS;r++){
-               for(s=0;s<state->log_col-1;s++){        /*posledni sloupec je vevyplneny*/
-                       if (s==state->log_col-2){
-                               fprintf(f,"%d ",state->logs[r][s]);
-                       }else{
-                               fprintf(f,"%d, ",state->logs[r][s]);
-                       }
-               }
-               fprintf(f,"\r");
-       }
-       fclose(f);
-       freeLogs();
-}
-
 /**
  * \brief
  * SetLog
@@ -316,6 +266,6 @@ void printData(struct rpi_state* state){
        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");
+       if (s.error) printf("error pri maloc logs!! \n");
 
 }