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 controllers.o commutators.o comp.o logs.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 commutators.o comp.o logs.o -lpthread -lrt
+pmsm: main_pmsm.o rp_spi.o rpi_hw.o misc.o pxmc_sin_fixtab.o cmd_proc.o controllers.o commutators.o comp.o logs.o pmsm_state.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 commutators.o comp.o logs.o pmsm_state.o -lpthread -lrt
*/
static void stop(struct rpi_state* state){
sem_wait(&state->thd_par_sem);
- state->commutate=0;
+ setCommutationOff(state);
state->pos_reg_ena=0;
state->spd_reg_ena=0;
state->duty=0;
state->duty=duty;
state->pos_reg_ena=0;
state->spd_reg_ena=0;
- state->commutate=1;
+ setCommutationOn(state);
sem_post(&state->thd_par_sem);
}
sem_wait(&state->thd_par_sem);
state->spd_reg_ena=0;
state->pos_reg_ena=1;
- state->commutate=1;
+ setCommutationOn(state);
state->desired_pos=pos;
sem_post(&state->thd_par_sem);
}
sem_wait(&state->thd_par_sem);
state->pos_reg_ena=0;
state->spd_reg_ena=1;
- state->commutate=1;
+ setCommutationOn(state);
state->desired_spd=speed;
sem_post(&state->thd_par_sem);
}
#include "commutators.h"
#include "pxmc_sin_fixed.h" /*sinus function*/
+
+/*
+ * \brief
+ * No commutation.
+ */
+void zero_commutator(struct rpi_state* this){
+ return;
+}
+
/*
* \brief
* Computes minimum value of three numbers.
*/
void simple_hall_commutator(struct rpi_state*);
+/*
+ * \brief
+ * No commutation.
+ */
+void zero_commutator(struct rpi_state*);
+
#endif /*COMMUTATORS*/
return;
index_lost:
- this->index_ok=0;
+ setIndexLost(this);
return;
}
.log_col_count=0, /* pocet radku zaznamu */
.log_col=0,
.doLogs=0,
- .alpha_offset=960
+ .alpha_offset=960,
+ .main_commutator=zero_commutator /*komutace vypnuta*/
};
* Feedback loop.
* TODO: replace bunch of 'IFs' with Object-like pattern
*/
-void * read_data(void* param){
+void * control_loop(void* param){
int i;
struct rpi_in pocatek;
struct rpi_state poc={
/*old positions*/
rps.old_pos[rps.tf_count%OLD_POS_NUM]=rps.spi_dat->pozice;
- spi_read(&rps); /*exchange data*/
- /*subtract initiate postion */
+ spi_read(&rps); /*exchange data*/
rps.tf_count++;
- substractOffset(&data,poc.spi_dat);
+ substractOffset(&data,poc.spi_dat); /*subtract initiate postion */
compSpeed(&rps); /*spocita rychlost*/
if (!rps.index_ok){
last_index=data.index_position;
first=0;
}else if (last_index!=data.index_position){
- rps.index_ok=1;
+ setIndexOK(&rps);
comIndDist(&rps); /*vypocet vzdalenosti indexu*/
}
}else{ /*index je v poradku*/
spd_pid(&rps);
}
- /* sirka plneni prepoctena na jednotlive pwm */
- if (rps.index_ok && rps.commutate){
- /*simple_ind_dist_commutator(rps.duty);*/
- /*sin_commutator(rps.duty);*/
- inv_trans_comm(&rps);
- inv_trans_comm_2(&rps);
- }else if(!rps.index_ok && rps.commutate){
- simple_hall_commutator(&rps);
- }
+ /* sirku plneni prepocteme na jednotlive pwm */
+ rps.main_commutator(&rps);
/*zalogujeme hodnoty*/
if (rps.doLogs && !(rps.tf_count%LOG_PERIOD)){
base_thread_id=pthread_self();
/*main control loop*/
- create_rt_task(&base_thread_id,PRIOR_HIGH,read_data,NULL);
+ create_rt_task(&base_thread_id,PRIOR_HIGH,control_loop,NULL);
/*monitor of current state*/
create_rt_task(&base_thread_id,PRIOR_LOW,pos_monitor,NULL);
--- /dev/null
+#include "pmsm_state.h"
+#include "commutators.h"
+
+/**
+ * Index Lost.
+ */
+void setIndexLost(struct rpi_state* this){
+ this->index_ok=0;
+ this->main_commutator=simple_hall_commutator;
+}
+
+/**
+ * Index OK.
+ */
+void setIndexOK(struct rpi_state* this){
+ this->index_ok=1;
+ this->main_commutator=inv_trans_comm_2;
+}
+
+/**
+ * Turn commutation on.
+ */
+void setCommutationOn(struct rpi_state* this){
+ this->commutate=1;
+ if (this->index_ok){
+ this->main_commutator=inv_trans_comm_2;
+ }else{
+ this->main_commutator=simple_hall_commutator;
+ }
+}
+
+/**
+ * Turn commutation off.
+ */
+void setCommutationOff(struct rpi_state* this){
+ this->commutate=0;
+ this->main_commutator=zero_commutator;
+}
int log_col_count; /* number of log columns */
int log_col; /* current colimn */
char doLogs; /* schall we make logs? */
+
+ void (*main_commutator)(struct rpi_state*); /* primarni komutator */
+ void (*main_controller)(struct rpi_state*); /* primarni regulator */
};
-void freeLogs();
+/**
+ * Index OK.
+ */
+void setIndexOK(struct rpi_state*);
+
+/**
+ * Index Lost.
+ */
+void setIndexLost(struct rpi_state*);
+
+/**
+ * Turn commutation on.
+ */
+void setCommutationOn(struct rpi_state*);
+
+/**
+ * Turn commutation off.
+ */
+void setCommutationOff(struct rpi_state*);
#endif /*PMSM_STATE*/