#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 */