spi: rp_spi.o
gcc -o spi rp_spi.c
#pro rpi
-pmsm: main_pmsm.o rp_spi.o rpi_hw.o misc.o pxmc_sin_fixtab.o cmd_proc.o
- gcc -o pmsm_controll main_pmsm.o rp_spi.o rpi_hw.o misc.o pxmc_sin_fixtab.o cmd_proc.o -lpthread -lrt
+pmsm: main_pmsm.o rp_spi.o rpi_hw.o misc.o pxmc_sin_fixtab.o cmd_proc.o controllers.o
+ gcc -o pmsm_controll main_pmsm.o rp_spi.o rpi_hw.o misc.o pxmc_sin_fixtab.o cmd_proc.o controllers.o -lpthread -lrt
--- /dev/null
+
+#include "controllers.h"
+
+/*
+ * \brief
+ * Very simple PID regulator.
+ * Now only with P-part so that the error doesnt go to zero.
+ * TODO: add anti-wind up and I and D parts
+ */
+void pos_pid(struct rpi_state* state){
+ int duty_tmp;
+ duty_tmp = PID_P*(state->desired_pos - (int32_t)state->spi_dat->pozice);
+ if (duty_tmp>MAX_DUTY){
+ state->duty=MAX_DUTY;
+ }else if (duty_tmp<-MAX_DUTY){
+ state->duty=-MAX_DUTY;
+ }else{
+ state->duty = duty_tmp;
+ }
+}
+
+/*
+ * \brief
+ * Very simple PID regulator.
+ * FIXME: make better
+ */
+void spd_pid(struct rpi_state* state){
+ int duty_tmp;
+ int error;
+ error=state->desired_spd - state->speed;
+ state->spd_err_sum+=error;
+ duty_tmp = PID_P_S*error+PID_I_S*state->spd_err_sum;
+ if (duty_tmp>MAX_DUTY){
+ state->duty=MAX_DUTY;
+ }else if (duty_tmp<-MAX_DUTY){
+ state->duty=-MAX_DUTY;
+ }else{
+ state->duty = duty_tmp;
+ }
+}
--- /dev/null
+/**
+ * \brief
+ * Speed and position regulators.
+ * \author Martin Prudek
+ * \file controllers.h
+ *
+ */
+#ifndef CONTROLLERS
+#define CONTROLLERS
+
+#include "pmsm_state.h" /*pmsm state*/
+#include "rp_spi.h" /*spi struct*/
+
+#define PID_P 0.3
+
+/* 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
+
+/**
+ * \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);
+
+/**
+ * \brief
+ * Very simple PI speed regulator.
+ */
+void spd_pid(struct rpi_state* state);
+
+
+#endif /*CONTROLLERS*/
#include "pxmc_sin_fixed.h" /*to test sin commutation */
#include "pmsm_state.h"
#include "cmd_proc.h"
+#include "controllers.h"
-#define PID_P 0.3
-/* 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
struct rpi_in data;
struct rpi_state rps={
+ //.MAX_DUTY=170,
.spi_dat=&data,
.test=0,
.pwm1=0,.pwm2=0, .pwm3=0,
}
return res;
}
+
inline
int sin_commutator(int duty){
#define DEGREE_60 715827883
rps.index_ok=0;
return;
}
-/*
- * \brief
- * Very simple PID regulator.
- * Now only with P-part so that the error doesnt go to zero.
- * TODO: add anti-wind up and I and D parts
- */
-inline void pos_pid(){
- int duty_tmp;
- duty_tmp = PID_P*(rps.desired_pos - (int32_t)data.pozice);
- if (duty_tmp>MAX_DUTY){
- rps.duty=MAX_DUTY;
- }else if (duty_tmp<-MAX_DUTY){
- rps.duty=-MAX_DUTY;
- }else{
- rps.duty = duty_tmp;
- }
-}
-/*
- * \brief
- * Very simple PID regulator.
- * Now only with P-part so that the error doesnt go to zero.
- * FIXME: make better
- */
-inline void spd_pid(){
- int duty_tmp;
- int error;
- error=rps.desired_spd - rps.speed;
- rps.spd_err_sum+=error;
- duty_tmp = PID_P_S*error+PID_I_S*rps.spd_err_sum;
- if (duty_tmp>MAX_DUTY){
- rps.duty=MAX_DUTY;
- }else if (duty_tmp<-MAX_DUTY){
- rps.duty=-MAX_DUTY;
- }else{
- rps.duty = duty_tmp;
- }
-}
+
/*
* \brief
/* pocitame sirku plneni podle potreb rizeni*/
if (rps.pos_reg_ena){ /*pozicni rizeni*/
- pos_pid();
+ pos_pid(&rps);
}else if(rps.spd_reg_ena){ /*rizeni na rychlost*/
- spd_pid();
+ spd_pid(&rps);
}
/* sirka plneni prepoctena na jednotlive pwm */
struct rpi_in;
struct rpi_state{
+ //const unsigned MAX_DUTY; /*Max duty*/
+
struct rpi_in* spi_dat; /* spi data */
sem_t thd_par_sem; /* data metual exlusion access */
uint8_t test; /* configuratin byte - pwm enabl. bits etc. */