From df10e6c255b6428ef6ba33697aee667dfda86964 Mon Sep 17 00:00:00 2001 From: zhaohe Date: Sun, 2 Jun 2024 20:46:11 +0800 Subject: [PATCH] update --- api/apibasic/cmdid.hpp | 3 ++- api/apibasic/errorcode.hpp | 12 ++++++++++++ api/apibasic/reg_index.hpp | 17 ++++++++--------- api/zi_module.cpp | 7 ++++++- api/zi_module.hpp | 3 ++- api/zi_motor.hpp | 1 + 6 files changed, 31 insertions(+), 12 deletions(-) diff --git a/api/apibasic/cmdid.hpp b/api/apibasic/cmdid.hpp index d569f65..a10ca02 100644 --- a/api/apibasic/cmdid.hpp +++ b/api/apibasic/cmdid.hpp @@ -19,7 +19,7 @@ typedef enum { virtual int32_t module_enable(int32_t enable) { return err::koperation_not_support; } virtual int32_t module_start() { return err::koperation_not_support; } #endif - kmodule_ping = CMDID(1, 0), // para:{}, ack:{} + kmodule_ping = CMDID(1, 0), // para:{}, ack:{} // kmodule_stop = CMDID(1, 1), // para:{}, ack:{} // kmodule_break = CMDID(1, 2), // para:{}, ack:{} // kmodule_get_last_exec_status = CMDID(1, 3), // para:{}, ack:{4} @@ -111,6 +111,7 @@ typedef enum { kstep_motor_easy_move_to_io = CMDID(2, 22), // para:{4,4}, ack:{} kstep_motor_active_cfg = CMDID(2, 23), // para:{4,4}, ack:{} kstep_motor_stop = CMDID(2, 24), // para:{4}, ack:{} + kstep_motor_read_io_state = CMDID(2, 25), // para:{4}, ack:{} } cmdid_t; diff --git a/api/apibasic/errorcode.hpp b/api/apibasic/errorcode.hpp index 2bda9c7..db5094c 100644 --- a/api/apibasic/errorcode.hpp +++ b/api/apibasic/errorcode.hpp @@ -67,6 +67,7 @@ typedef enum { kxymotor_x_find_zero_edge_fail = ERROR_CODE(300, 6), // 离开零点失败 kxymotor_y_find_zero_edge_fail = ERROR_CODE(300, 7), // 离开零点失败 kmotor_run_overtime = ERROR_CODE(300, 8), // 运行超时 + kmotor_not_enable = ERROR_CODE(300, 9), // 电机未使能 /** * @brief STMP2错误 @@ -102,6 +103,17 @@ typedef enum { kmicro_uartRecvFail = ERROR_CODE(500, 2), // kmicro_adcRecvFail = ERROR_CODE(500, 3), // + /** + * @brief step motor error + */ + kstep_motor_not_found_zero_point = ERROR_CODE(600, 0), // 未找到零点 + kstep_motor_not_go_zero = ERROR_CODE(600, 1), // 设备未归零 + kstep_motor_over_temperature = ERROR_CODE(600, 2), // 过温 + kstep_motor_over_voltage = ERROR_CODE(600, 3), // 过压 + kstep_motor_run_overtime = ERROR_CODE(600, 4), // 运行超时 + kstep_motor_not_enable = ERROR_CODE(600, 5), // 电机未使能 + kstep_motor_ioindex_out_of_range = ERROR_CODE(600, 6), // IO超出范围 + } error_t; const char* error2str(int32_t code); diff --git a/api/apibasic/reg_index.hpp b/api/apibasic/reg_index.hpp index 2c86e55..0e5f712 100644 --- a/api/apibasic/reg_index.hpp +++ b/api/apibasic/reg_index.hpp @@ -9,10 +9,10 @@ typedef enum { /******************************************************************************* * 模块通用配置和状态 * *******************************************************************************/ - kreg_module_version = REG_INDEX(0, 0, 0), // 模块版本 - kreg_module_type = REG_INDEX(0, 0, 1), // 模块类型 - kreg_module_status = REG_INDEX(0, 0, 2), // 0idle,1busy,2error - kreg_module_errorcode = REG_INDEX(0, 0, 3), // inited_flag + kreg_module_version = REG_INDEX(0, 0, 0), // 模块版本 + kreg_module_type = REG_INDEX(0, 0, 1), // 模块类型 + kreg_module_status = REG_INDEX(0, 0, 2), // 0idle,1busy,2error + kreg_module_errorcode = REG_INDEX(0, 0, 3), // inited_flag // kreg_module_raw_sector_size = REG_INDEX(0, 0, 10), // sector_size // kreg_module_raw_sector_num = REG_INDEX(0, 0, 11), // @@ -125,8 +125,10 @@ typedef enum { /******************************************************************************* * MOTOR_DEFAULT * *******************************************************************************/ - kreg_step_motor_pos = REG_INDEX(10, 0, 1), // 机器人x坐标 - kreg_step_motor_io_state = REG_INDEX(10, 0, 2), // IO状态 + kreg_step_motor_pos = REG_INDEX(10, 0, 1), // 机器人x坐标 + kreg_step_motor_io_state = REG_INDEX(10, 0, 2), // IO状态 + kreg_step_motor_dpos = REG_INDEX(10, 0, 3), // 执行完上一条指令后的相对位移 + kreg_step_motor_shift = REG_INDEX(10, 50, 0), // x偏移 kreg_step_motor_shaft = REG_INDEX(10, 50, 1), // x轴是否反转 kreg_step_motor_one_circle_pulse = REG_INDEX(10, 50, 2), // x轴一圈脉冲数 @@ -149,9 +151,6 @@ typedef enum { kreg_step_motor_max_d = REG_INDEX(10, 50, 28), // 最大限制距离 kreg_step_motor_min_d = REG_INDEX(10, 50, 29), // 最小限制距离 - - - /*********************************************************************************************************************** * XYROBOT * ***********************************************************************************************************************/ diff --git a/api/zi_module.cpp b/api/zi_module.cpp index 5346ccd..81c0d4a 100644 --- a/api/zi_module.cpp +++ b/api/zi_module.cpp @@ -1,4 +1,4 @@ -#pragma once + #include "zi_module.hpp" #include @@ -89,3 +89,8 @@ int32_t ZIModule::module_clear_error() { creg.module_errorbitflag0 = 0; return 0; } + +int32_t ZIModule::module_get_status(int32_t *status) { + *status = creg.m_module_status; + return 0; +} diff --git a/api/zi_module.hpp b/api/zi_module.hpp index 45ddfaf..a89d90e 100644 --- a/api/zi_module.hpp +++ b/api/zi_module.hpp @@ -40,6 +40,7 @@ using namespace std; typedef struct { int32_t module_errorcode; int32_t module_errorbitflag0; + int32_t m_module_status; } module_common_reg_t; class ZIModule { @@ -58,6 +59,7 @@ class ZIModule { virtual int32_t module_clear_error(); virtual int32_t module_set_reg(int32_t param_id, int32_t param_value); virtual int32_t module_get_reg(int32_t param_id, int32_t *param_value); + virtual int32_t module_get_status(int32_t *status); virtual int32_t module_get_version(int32_t *val) = 0; virtual int32_t module_get_type(int32_t *val) = 0; @@ -65,7 +67,6 @@ class ZIModule { * 用户实现 * ***********************************************************************************************************************/ virtual int32_t getid(int32_t *id) = 0; - virtual int32_t module_get_status(int32_t *status) = 0; virtual int32_t module_xxx_reg(int32_t param_id, bool read, int32_t &val) = 0; protected: diff --git a/api/zi_motor.hpp b/api/zi_motor.hpp index 134892c..56e543f 100644 --- a/api/zi_motor.hpp +++ b/api/zi_motor.hpp @@ -20,5 +20,6 @@ class ZIStepMotor { virtual int32_t step_motor_easy_set_current_pos(int32_t pos) = 0; virtual int32_t step_motor_easy_move_to_io(int32_t ioindex, int32_t direction) = 0; virtual int32_t step_motor_active_cfg() = 0; + virtual int32_t step_motor_read_io_state(int32_t ioindex) = 0; }; } // namespace iflytop \ No newline at end of file