diff --git a/components/flash/znvs.cpp b/components/flash/znvs.cpp index e2c5670..4ad11ab 100644 --- a/components/flash/znvs.cpp +++ b/components/flash/znvs.cpp @@ -17,11 +17,12 @@ ZNVS& ZNVS::ins() { } void ZNVS::initialize(int32_t flash_sector) { zsimple_flash_init(flash_sector); } -bool ZNVS::alloc_config(const char* key, uint8_t* data, size_t datalen) { +bool ZNVS::alloc_config(const char* key, size_t datalen) { return alloc_config(key, nullptr, datalen); } +bool ZNVS::alloc_config(const char* key, uint8_t* __, size_t datalen) { ZASSERT(m_index_num < ZARRAY_SIZE(m_index)); - m_index[m_index_num].name = key; - m_index[m_index_num].len = datalen; - m_index[m_index_num].defaultval = data; + m_index[m_index_num].name = key; + m_index[m_index_num].len = datalen; + // m_index[m_index_num].defaultval = data; m_index_num++; return true; } @@ -53,7 +54,8 @@ bool ZNVS::init_config() { void ZNVS::flush_all_to_configcache() { for (int i = 0; i < m_index_num; i++) { - memcpy(m_cfgcache->data, m_index[i].defaultval, m_index[i].len); + // memcpy(m_cfgcache->data, m_index[i].defaultval, m_index[i].len); + memset(m_cfgcache->data, 0, m_index[i].len); } } diff --git a/components/flash/znvs.hpp b/components/flash/znvs.hpp index 19fe802..5b0122b 100644 --- a/components/flash/znvs.hpp +++ b/components/flash/znvs.hpp @@ -8,7 +8,7 @@ using namespace std; class ZNVS { typedef struct { const char* name; - uint8_t* defaultval; + uint8_t* ___; size_t len; } cfg_index_t; #pragma pack(1) @@ -33,7 +33,8 @@ class ZNVS { void initialize(int32_t flash_sector); - bool alloc_config(const char* key, uint8_t* data, size_t datalen); + bool alloc_config(const char* key, uint8_t* ___, size_t datalen); + bool alloc_config(const char* key, size_t datalen); bool init_config(); bool get_config(const char* key, uint8_t* data, size_t len); diff --git a/components/xy_robot_ctrl_module/xy_robot_ctrl_module.cpp b/components/xy_robot_ctrl_module/xy_robot_ctrl_module.cpp index fdd565e..057b874 100644 --- a/components/xy_robot_ctrl_module/xy_robot_ctrl_module.cpp +++ b/components/xy_robot_ctrl_module/xy_robot_ctrl_module.cpp @@ -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; diff --git a/components/xy_robot_ctrl_module/xy_robot_ctrl_module.hpp b/components/xy_robot_ctrl_module/xy_robot_ctrl_module.hpp index 02017b1..c3e1101 100644 --- a/components/xy_robot_ctrl_module/xy_robot_ctrl_module.hpp +++ b/components/xy_robot_ctrl_module/xy_robot_ctrl_module.hpp @@ -25,22 +25,15 @@ class XYRobotCtrlModule : public I_XYRobotCtrlModule, public ZIXYMotor, public Z int32_t m_moduleId; - int m_x = 0; int m_y = 0; int32_t m_dx; int32_t m_dy; - // uint8_t m_status = 0; - - // base_param_t m_cfg; - - // int32_t m_zero_shift_x = 0; - // int32_t m_zero_shift_y = 0; - const char* m_flashmark = nullptr; flash_config_t m_cfg; + flash_config_t m_default_cfg; base_param_t& m_basecfg = m_cfg.basecfg; bool m_enable = false; @@ -48,10 +41,9 @@ class XYRobotCtrlModule : public I_XYRobotCtrlModule, public ZIXYMotor, public Z // zmutex m_statu_lock; public: - void initialize(int32_t id, IStepperMotor* stepM1, // - IStepperMotor* stepM2, // - ZGPIO* Xgpio, // - int ngpio, const char* flashmark); + void initialize(int32_t id, IStepperMotor* stepM1, IStepperMotor* stepM2, // + ZGPIO* Xgpio, int ngpio, // + flash_config_t& default_cfg, const char* flashmark); virtual int32_t move_to(int32_t x, int32_t y, int32_t speed, action_cb_status_t status_cb) override; virtual int32_t move_by(int32_t dx, int32_t dy, int32_t speed, action_cb_status_t status_cb) override; @@ -68,6 +60,7 @@ class XYRobotCtrlModule : public I_XYRobotCtrlModule, public ZIXYMotor, public Z virtual int32_t read_detailed_status(detailed_status_t& debug_info) override; static void create_default_cfg(flash_config_t& cfg); + static int32_t get_flash_config_size(); virtual int32_t set_base_param(const base_param_t& param) override; virtual int32_t get_base_param(base_param_t& ack) override; @@ -93,6 +86,8 @@ class XYRobotCtrlModule : public I_XYRobotCtrlModule, public ZIXYMotor, public Z virtual int32_t module_flush_cfg(); virtual int32_t module_active_cfg(); + virtual int32_t module_enable(int32_t enable) { return xymotor_enable(enable); } + virtual int32_t xymotor_enable(int32_t enable); virtual int32_t xymotor_move_by(int32_t dx, int32_t dy, int32_t motor_velocity); virtual int32_t xymotor_move_to(int32_t x, int32_t y, int32_t motor_velocity); diff --git a/components/zprotocols/zcancmder b/components/zprotocols/zcancmder index c3780f3..ceb6729 160000 --- a/components/zprotocols/zcancmder +++ b/components/zprotocols/zcancmder @@ -1 +1 @@ -Subproject commit c3780f3e459bc468645f664228d3a1359abec1bf +Subproject commit ceb6729e4ee474a6ff170793202f3113b5838101 diff --git a/components/zprotocols/zcancmder_v2 b/components/zprotocols/zcancmder_v2 index 9cdfcc0..4b8745f 160000 --- a/components/zprotocols/zcancmder_v2 +++ b/components/zprotocols/zcancmder_v2 @@ -1 +1 @@ -Subproject commit 9cdfcc02e4c0e75f4d1b731c91b87ae2c22b467e +Subproject commit 4b8745f224fb4891302e6984d94ed2673521eaa5