]> rtime.felk.cvut.cz Git - fpga/rpi-motor-control.git/commitdiff
Regulation function now implemented with use of polymorphism.
authorMartin Prudek <prudemar@fel.cvut.cz>
Wed, 20 May 2015 19:43:24 +0000 (21:43 +0200)
committerMartin Prudek <prudemar@fel.cvut.cz>
Wed, 20 May 2015 19:43:24 +0000 (21:43 +0200)
pmsm-control/test_sw/cmd_proc.c
pmsm-control/test_sw/controllers.c
pmsm-control/test_sw/controllers.h
pmsm-control/test_sw/main_pmsm.c
pmsm-control/test_sw/pmsm_state.c
pmsm-control/test_sw/pmsm_state.h

index 6846df594e5a57eb4ed02931d4565dcb72e8b2cb..66e9be804b321c4540db865cc353f8072d094e57 100644 (file)
@@ -62,8 +62,7 @@ static void start(struct rpi_state* state){
 static void stop(struct rpi_state* state){
        sem_wait(&state->thd_par_sem);
        setCommutationOff(state);
-       state->pos_reg_ena=0;
-       state->spd_reg_ena=0;
+       setRegulationOff(state);
        state->duty=0;
        state->pwm1=0;
        state->pwm2=0;
@@ -80,8 +79,7 @@ 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;
+       setRegulationOff(state);
        setCommutationOn(state);
        sem_post(&state->thd_par_sem);
 }
@@ -92,8 +90,7 @@ 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;
+       setRegulationPos(state);
        setCommutationOn(state);
        state->desired_pos=pos;
        sem_post(&state->thd_par_sem);
@@ -124,8 +121,7 @@ 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;
+       setRegulationSpeed(state);
        setCommutationOn(state);
        state->desired_spd=speed;
        sem_post(&state->thd_par_sem);
index 059ade62a0b5d1c0849cec81efe83b2aab8a0cd4..bdf5ad95f326d5d08b24664f973a2c838931192e 100644 (file)
@@ -1,6 +1,13 @@
 
 #include "controllers.h"
 
+/**
+ * \brief No regulation.
+ */
+inline void zero_controller(struct rpi_state* state){
+       return;
+}
+
 /*
  * \brief
  * Very simple PID regulator.
index 520745ed2ba317fb059b2857dbcf29c86043b7d5..5b241489317a950b0e471ed72d983fc8aa924f6a 100644 (file)
 #define PID_P_S                0.16            /*2.3 kmita*/ /*1.4 vhodne jen pro P regulator*/
 #define PID_I_S                0.0134
 
+/**
+ * \brief No regulation.
+ */
+inline void zero_controller(struct rpi_state*);
+
 /**
  * \brief
  * Very simple position P regulator.
  * Now only with P-part so that the error doesnt go to zero.
  */
-void pos_pid(struct rpi_state* state);
+void pos_pid(struct rpi_state*);
 
 /**
  * \brief
  * Very simple PI speed regulator.
  */
-void spd_pid(struct rpi_state* state);
+void spd_pid(struct rpi_state*);
 
 
 #endif /*CONTROLLERS*/
index ac3563d59b578396991ba6f0088415bb28668929..f0fc982529cb410ebf8fc4aafd3e8425a8d6803a 100644 (file)
@@ -61,7 +61,8 @@ struct rpi_state rps={
        .log_col=0,
        .doLogs=0,
        .alpha_offset=960,
-       .main_commutator=zero_commutator        /*komutace vypnuta*/
+       .main_commutator=zero_commutator,       /* komutace vypnuta */
+       .main_controller=zero_controller        /* rizeni vypnuto */
 };
 
 
@@ -154,11 +155,7 @@ void * control_loop(void* param){
                        }
 
                        /* pocitame sirku plneni podle potreb rizeni*/
-                       if (rps.pos_reg_ena){           /*pozicni rizeni*/
-                               pos_pid(&rps);
-                       }else if(rps.spd_reg_ena){      /*rizeni na rychlost*/
-                               spd_pid(&rps);
-                       }
+                       rps.main_controller(&rps);
 
                        /* sirku plneni prepocteme na jednotlive pwm */
                        rps.main_commutator(&rps);
index 3938dc7a9f60726e88408d5da742bb4de45c122c..acfd34732e4b967d40d3940fdad5615d2a447f29 100644 (file)
@@ -1,5 +1,6 @@
 #include "pmsm_state.h"
 #include "commutators.h"
+#include "controllers.h"
 
 /**
  * Index Lost.
@@ -36,3 +37,32 @@ inline void setCommutationOff(struct rpi_state* this){
        this->commutate=0;
        this->main_commutator=zero_commutator;
 }
+
+/**
+ * Turn on speed regulation.
+ */
+inline void setRegulationSpeed(struct rpi_state* this){
+       this->spd_reg_ena=1;
+       this->pos_reg_ena=0;
+       this->main_controller=spd_pid;
+}
+
+/**
+ * \brief Turn on position regulation
+ */
+inline void setRegulationPos(struct rpi_state* this){
+       this->spd_reg_ena=0;
+       this->pos_reg_ena=1;
+       this->main_controller=pos_pid;
+}
+
+/**
+ * \brief Turn off regulation.
+ */
+inline void setRegulationOff(struct rpi_state* this){
+       this->spd_reg_ena=0;
+       this->pos_reg_ena=0;
+       this->main_controller=zero_controller;
+
+
+}
index 583eb73cdc253a1ded565a4ba9a7667d19e83380..6fc77f475f47e20db4ca339ea3dc06bfe0ec5038 100644 (file)
@@ -73,4 +73,19 @@ inline void setCommutationOn(struct rpi_state*);
  */
 inline void setCommutationOff(struct rpi_state*);
 
+/**
+ * Turn on speed regulation.
+ */
+inline void setRegulationSpeed(struct rpi_state*);
+
+/**
+ * \brief Turn on position regulation
+ */
+inline void setRegulationPos(struct rpi_state*);
+
+/**
+ * \brief Turn off regulation.
+ */
+inline void setRegulationOff(struct rpi_state*);
+
 #endif /*PMSM_STATE*/