|
|
@ -7,10 +7,9 @@ |
|
|
|
using namespace iflytop; |
|
|
|
using namespace std; |
|
|
|
#define TAG "XYRobotCtrlModule"
|
|
|
|
void XYRobotCtrlModule::initialize(int32_t id, IStepperMotor* stepM1, //
|
|
|
|
IStepperMotor* stepM2, //
|
|
|
|
ZGPIO* Xgpio, //
|
|
|
|
int ngpio, const char* flashmark) { |
|
|
|
void XYRobotCtrlModule::initialize(int32_t id, IStepperMotor* stepM1, IStepperMotor* stepM2, //
|
|
|
|
ZGPIO* Xgpio, int ngpio, //
|
|
|
|
flash_config_t& default_cfg, const char* flashmark) { |
|
|
|
m_stepM1 = stepM1; |
|
|
|
m_stepM2 = stepM2; |
|
|
|
m_Xgpio = &Xgpio[0]; |
|
|
@ -24,13 +23,18 @@ void XYRobotCtrlModule::initialize(int32_t id, IStepperMotor* stepM1, // |
|
|
|
ZASSERT(m_Ygpio); |
|
|
|
|
|
|
|
m_lock.init(); |
|
|
|
m_flashmark = flashmark; |
|
|
|
// base_param_t cfg;
|
|
|
|
m_flashmark = flashmark; |
|
|
|
m_default_cfg = default_cfg; |
|
|
|
|
|
|
|
if (m_flashmark) { |
|
|
|
ZASSERT(ZNVS::ins().get_config(m_flashmark, (uint8_t*)&m_cfg, sizeof(m_cfg))); |
|
|
|
if (!m_cfg.configInited) { |
|
|
|
m_cfg.configInited = true; |
|
|
|
m_cfg = m_default_cfg; |
|
|
|
flush(); |
|
|
|
} |
|
|
|
} else { |
|
|
|
create_default_cfg(m_cfg); |
|
|
|
m_cfg = m_default_cfg; |
|
|
|
} |
|
|
|
active_cfg(); |
|
|
|
enable(true); |
|
|
@ -295,6 +299,8 @@ int32_t XYRobotCtrlModule::read_detailed_status(detailed_status_t& debug_info) { |
|
|
|
getnowpos(debug_info.x, debug_info.y); |
|
|
|
return 0; |
|
|
|
} |
|
|
|
int32_t XYRobotCtrlModule::get_flash_config_size() { return sizeof(flash_config_t); } |
|
|
|
|
|
|
|
void XYRobotCtrlModule::create_default_cfg(flash_config_t& cfg) { |
|
|
|
memset(&cfg, 0, sizeof(cfg)); |
|
|
|
cfg.basecfg.robot_type = corexy; |
|
|
@ -392,6 +398,7 @@ int32_t XYRobotCtrlModule::exec_move_to_zero_task() { |
|
|
|
ZLOGE(TAG, "find zero point fail"); |
|
|
|
return err::kxymotor_x_find_zero_edge_fail; |
|
|
|
} |
|
|
|
ZLOGI(TAG, "step1 reach x zero ok"); |
|
|
|
} |
|
|
|
|
|
|
|
if (m_Xgpio->getState()) { |
|
|
@ -415,6 +422,7 @@ int32_t XYRobotCtrlModule::exec_move_to_zero_task() { |
|
|
|
ZLOGI(TAG, "leave away zero failed"); |
|
|
|
return err::kxymotor_x_find_zero_edge_fail; |
|
|
|
} |
|
|
|
ZLOGI(TAG, "step2 leave x zero ok"); |
|
|
|
} |
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
@ -441,6 +449,7 @@ int32_t XYRobotCtrlModule::exec_move_to_zero_task() { |
|
|
|
ZLOGE(TAG, "find zero point fail"); |
|
|
|
return err::kxymotor_y_find_zero_edge_fail; |
|
|
|
} |
|
|
|
ZLOGI(TAG, "step3 reach y zero ok"); |
|
|
|
} |
|
|
|
|
|
|
|
if (m_Ygpio->getState()) { |
|
|
@ -462,7 +471,9 @@ int32_t XYRobotCtrlModule::exec_move_to_zero_task() { |
|
|
|
ZLOGI(TAG, "leave away zero failed"); |
|
|
|
return err::kxymotor_y_find_zero_edge_fail; |
|
|
|
} |
|
|
|
ZLOGI(TAG, "step4 leave y zero ok"); |
|
|
|
} |
|
|
|
ZLOGI(TAG, "move to zero ok"); |
|
|
|
|
|
|
|
return 0; |
|
|
|
} |
|
|
@ -487,7 +498,7 @@ void XYRobotCtrlModule::_motor_move_to(int32_t x, int32_t y, int32_t maxv, int32 |
|
|
|
m_stepM1->setDeceleration(dec); |
|
|
|
m_stepM2->setDeceleration(dec); |
|
|
|
|
|
|
|
ZLOGI(TAG, "_motor_move_to target_m1pos:%d target_m2pos:%d", target_m1pos, target_m2pos); |
|
|
|
// ZLOGI(TAG, "_motor_move_to target_m1pos:%d target_m2pos:%d", target_m1pos, target_m2pos);
|
|
|
|
m_stepM1->moveTo(target_m1pos, maxv); |
|
|
|
m_stepM2->moveTo(target_m2pos, maxv); |
|
|
|
} |
|
|
@ -508,7 +519,7 @@ void XYRobotCtrlModule::_motor_move_by(int32_t dx, int32_t dy, int32_t maxv, int |
|
|
|
|
|
|
|
m_stepM1->setDeceleration(dec); |
|
|
|
m_stepM2->setDeceleration(dec); |
|
|
|
ZLOGI(TAG, "_motor_move_by target_m1pos:%d target_m2pos:%d", target_m1pos, target_m2pos); |
|
|
|
// ZLOGI(TAG, "_motor_move_by target_m1pos:%d target_m2pos:%d", target_m1pos, target_m2pos);
|
|
|
|
m_stepM1->moveTo(target_m1pos, maxv); |
|
|
|
m_stepM2->moveTo(target_m2pos, maxv); |
|
|
|
} |
|
|
@ -592,7 +603,8 @@ int32_t XYRobotCtrlModule::flush() { // |
|
|
|
}; |
|
|
|
int32_t XYRobotCtrlModule::factory_reset() { //
|
|
|
|
ZLOGI(TAG, "factory_reset"); |
|
|
|
create_default_cfg(m_cfg); |
|
|
|
m_cfg = m_default_cfg; |
|
|
|
m_cfg.configInited = true; |
|
|
|
if (m_flashmark) { |
|
|
|
ZNVS::ins().set_config(m_flashmark, (uint8_t*)&m_cfg, sizeof(m_cfg)); |
|
|
|
ZNVS::ins().flush(); |
|
|
@ -763,10 +775,11 @@ int32_t XYRobotCtrlModule::xymotor_calculated_pos_by_move_to_zero() { |
|
|
|
m_dx = dx; |
|
|
|
m_dy = dy; |
|
|
|
m_com_reg.module_last_cmd_exec_status = 0; |
|
|
|
m_com_reg.module_last_cmd_exec_val0 = m_dx; |
|
|
|
m_com_reg.module_last_cmd_exec_val1 = m_dy; |
|
|
|
m_com_reg.module_last_cmd_exec_val0 = -m_dx; |
|
|
|
m_com_reg.module_last_cmd_exec_val1 = -m_dy; |
|
|
|
m_stepM1->setXACTUAL(0); |
|
|
|
m_stepM2->setXACTUAL(0); |
|
|
|
ZLOGI(TAG, "xymotor_calculated_pos_by_move_to_zero dx:%d dy:%d", dx, dy); |
|
|
|
return; |
|
|
|
}); |
|
|
|
return 0; |
|
|
|