flow calculation & move

This commit is contained in:
leo 2023-08-21 14:24:59 +02:00
parent 25689803d1
commit defa22a3e8
Signed by: leo
GPG Key ID: 0DD993BFB2B307DB
6 changed files with 60 additions and 11 deletions

View File

@ -22,6 +22,7 @@ typedef enum {PORT_X, PORT_Y, PORT_Z, PORT_E} pse_ports;
typedef struct{ typedef struct{
uint32_t step_itvl; uint32_t step_itvl;
uint8_t step_max; uint8_t step_max;
uint32_t tick_counter;
GPIO_TypeDef* EN_GPIO_Port; GPIO_TypeDef* EN_GPIO_Port;
uint16_t EN_GPIO_Pin; uint16_t EN_GPIO_Pin;

View File

@ -10,11 +10,18 @@
#include "PSE_unit.h" #include "PSE_unit.h"
#define PSE_STEPPER_INTERRUPT_RATE 20000 // 64Mhz (Presc 64, count 50) : 20kHz
#define PSE_STEPPER_SCREW_PITCH 1000 // M6 : 1000µm / rotation
#define PSE_STEPPER_STEPS_PER_ROTATION 200 // NEMA17 without microstepping 200 steps/rotation
void pse_sp_start_axis(pse_stepper_conf* conf); void pse_sp_start_axis(pse_stepper_conf* conf);
void pse_sp_stop_axis(pse_stepper_conf* conf); void pse_sp_stop_axis(pse_stepper_conf* conf);
void pse_sp_set_dir(pse_stepper_conf* conf, int dir); void pse_sp_set_dir(pse_stepper_conf* conf, int dir);
void pse_stepper_planer_tick(pse_unit* units, uint8_t units_num); void pse_stepper_planer_tick(pse_unit* units, uint8_t units_num);
unsigned int get_tick_counter(); void pse_sp_start_all(pse_unit* units, int unit_num);
void pse_sp_stop_all(pse_unit* units, int unit_num);
void pse_stepper_planer_compute_sps(pse_unit* unit);
#endif /* INC_PSE_STEPPER_PLANER_H_ */ #endif /* INC_PSE_STEPPER_PLANER_H_ */

View File

@ -19,5 +19,9 @@ void load_units(pse_unit* units, pse_syringe* syringes, pse_stepper_conf* steppe
.syringe = &syringes[i], .syringe = &syringes[i],
.stepper_conf = &stepper_confs[i], .stepper_conf = &stepper_confs[i],
}; };
syringes[i] = (pse_syringe){
.name = "Test",
.diameter = 26700,
};
} }
} }

View File

@ -19,12 +19,17 @@
static lv_obj_t* parent_screen; static lv_obj_t* parent_screen;
static lv_obj_t* this_screen; static lv_obj_t* this_screen;
static pse_unit* c_pse_unit;
static void back_button_handler(lv_event_t * e){ static void back_button_handler(lv_event_t * e){
lv_event_code_t code = lv_event_get_code(e); lv_event_code_t code = lv_event_get_code(e);
if(code == LV_EVENT_CLICKED) { if(code == LV_EVENT_CLICKED) {
// Save // Save
// update stepper pwm generation
pse_stepper_planer_compute_sps(c_pse_unit);
// go back to the main menu
lv_obj_t* curr_scr = lv_scr_act(); lv_obj_t* curr_scr = lv_scr_act();
lv_scr_load(parent_screen); lv_scr_load(parent_screen);
lv_obj_del(curr_scr); lv_obj_del(curr_scr);
@ -192,6 +197,8 @@ void PSE_unit_edit_screen_Gen(lv_obj_t* parent, pse_unit* unit){
lv_obj_t* scr = lv_obj_create(NULL); lv_obj_t* scr = lv_obj_create(NULL);
this_screen = scr; this_screen = scr;
c_pse_unit = unit;
// create the top menu on the top 20% // create the top menu on the top 20%
lv_obj_t* top_menu = lv_obj_create(scr); lv_obj_t* top_menu = lv_obj_create(scr);
lv_obj_set_align(top_menu, LV_ALIGN_TOP_LEFT); lv_obj_set_align(top_menu, LV_ALIGN_TOP_LEFT);

View File

@ -12,6 +12,10 @@
#include "PSE_unit.h" #include "PSE_unit.h"
#include "PSE_unit_edit_screen.h" #include "PSE_unit_edit_screen.h"
#include "pse_stepper_planer.h"
static pse_unit* units;
static int units_num;
static void run_handler(lv_event_t * e){ static void run_handler(lv_event_t * e){
lv_event_code_t code = lv_event_get_code(e); lv_event_code_t code = lv_event_get_code(e);
@ -22,9 +26,11 @@ static void run_handler(lv_event_t * e){
lv_state_t state = lv_obj_get_state(button); lv_state_t state = lv_obj_get_state(button);
if(state & LV_STATE_CHECKED){ if(state & LV_STATE_CHECKED){
lv_label_set_text(label, LV_SYMBOL_PAUSE); lv_label_set_text(label, LV_SYMBOL_PAUSE);
pse_sp_start_all(units, units_num);
} }
else{ else{
lv_label_set_text(label, LV_SYMBOL_PLAY); lv_label_set_text(label, LV_SYMBOL_PLAY);
pse_sp_stop_all(units, units_num);
} }
} }
} }
@ -107,6 +113,10 @@ void Home_Screen_Gen(pse_unit* pse_units, uint8_t pse_unit_num){
lv_obj_t* scr = lv_obj_create(NULL); lv_obj_t* scr = lv_obj_create(NULL);
screen = scr; screen = scr;
// set global unit variable
units = pse_units;
units_num = pse_unit_num;
// create the top menu on the top 20% // create the top menu on the top 20%
lv_obj_t* top_menu = lv_obj_create(scr); lv_obj_t* top_menu = lv_obj_create(scr);
lv_obj_set_align(top_menu, LV_ALIGN_TOP_LEFT); lv_obj_set_align(top_menu, LV_ALIGN_TOP_LEFT);

View File

@ -9,7 +9,7 @@
#include "PSE_unit.h" #include "PSE_unit.h"
unsigned int tick_counter = 0; #include "pse_stepper_planer.h"
void pse_stepper_planer_tick(pse_unit* units, uint8_t units_num){ void pse_stepper_planer_tick(pse_unit* units, uint8_t units_num){
for(int i = 0; i < units_num; i++){ for(int i = 0; i < units_num; i++){
@ -17,19 +17,16 @@ void pse_stepper_planer_tick(pse_unit* units, uint8_t units_num){
int state; int state;
if(c->step_max){ if(c->step_max){
state = tick_counter % 2; c->tick_counter %= 2;
state = c->tick_counter;
} }
else{ else{
state = (tick_counter % c->step_itvl) == 0; c->tick_counter %= c->step_itvl;
state = c->tick_counter == 0;
} }
HAL_GPIO_WritePin(c->STEP_GPIO_Port, c->STEP_GPIO_Pin, tick_counter%2); c->tick_counter++;
HAL_GPIO_WritePin(c->STEP_GPIO_Port, c->STEP_GPIO_Pin, state);
} }
tick_counter++;
}
unsigned int get_tick_counter(){
return tick_counter;
} }
void pse_sp_start_axis(pse_stepper_conf* conf){ void pse_sp_start_axis(pse_stepper_conf* conf){
@ -42,3 +39,26 @@ void pse_sp_stop_axis(pse_stepper_conf* conf){
void pse_sp_set_dir(pse_stepper_conf* conf, int dir){ void pse_sp_set_dir(pse_stepper_conf* conf, int dir){
HAL_GPIO_WritePin(conf->DIR_GPIO_Port, conf->DIR_GPIO_Pin, dir); HAL_GPIO_WritePin(conf->DIR_GPIO_Port, conf->DIR_GPIO_Pin, dir);
} }
void pse_stepper_planer_compute_sps(pse_unit* unit){
pse_stepper_conf* c = unit->stepper_conf;
// magic constants are used to approximate pi and other multiplicatives constant as a rationnal
uint64_t numerator = (uint64_t)1 * unit->syringe->diameter * unit->syringe->diameter * PSE_STEPPER_INTERRUPT_RATE * PSE_STEPPER_SCREW_PITCH;
uint64_t denominator = (uint64_t)21220209 * unit->flow * PSE_STEPPER_STEPS_PER_ROTATION;
c->step_itvl = numerator / denominator;
}
void pse_sp_start_all(pse_unit* units, int units_num){
for(int i = 0; i < units_num; i++){
if(units[i].enabled)
pse_sp_start_axis(units[i].stepper_conf);
}
}
void pse_sp_stop_all(pse_unit* units, int units_num){
for(int i = 0; i < units_num; i++){
if(units[i].enabled)
pse_sp_stop_axis(units[i].stepper_conf);
}
}