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;
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);
}
*/
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);
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);
#include "controllers.h"
+/**
+ * \brief No regulation.
+ */
+inline void zero_controller(struct rpi_state* state){
+ return;
+}
+
/*
* \brief
* Very simple PID regulator.
#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*/
.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 */
};
}
/* 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);
#include "pmsm_state.h"
#include "commutators.h"
+#include "controllers.h"
/**
* Index Lost.
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;
+
+
+}
*/
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*/