diff --git a/api/i_step_motor_ctrl_module.hpp b/api/i_step_motor_ctrl_module.hpp new file mode 100644 index 0000000..98d2d4e --- /dev/null +++ b/api/i_step_motor_ctrl_module.hpp @@ -0,0 +1,108 @@ +#pragma once +#include + +#include + +#include "basic_type.hpp" +// + +namespace iflytop { +using namespace std; +class I_StepMotorCtrlModule { + public: + typedef enum { hbot, corexy } RobotType_t; + typedef enum { kNormalStop, kBreakStop } StopType_t; + + /******************************************************************************* + * ACTION * + *******************************************************************************/ + + typedef struct { + int32_t exec_status; + int32_t tox; + } move_to_cb_status_t; + + typedef struct { + int32_t exec_status; + int32_t dx; + } move_by_cb_status_t; + + typedef struct { + int32_t exec_status; + } move_to_zero_cb_status_t; + + typedef struct { + int32_t exec_status; + int32_t zero_shift_x; + } move_to_zero_with_calibrate_cb_status_t; + + typedef struct { + int32_t exec_status; + int32_t lastforms; + } rotate_cb_status_t; + + /******************************************************************************* + * READ * + *******************************************************************************/ + typedef struct { + int32_t version; + } version_t; + + typedef struct { + uint8_t status; + int32_t x; + } status_t; + + typedef struct { + uint8_t status; + int32_t x; + } debug_info_t; + + /******************************************************************************* + * CFG * + *******************************************************************************/ + + typedef struct { + u8 x_shaft; + u8 ihold; + u8 irun; + u16 iholddelay; + s32 distance_scale; // 0.001 + s32 shift_x; + s32 acc; + s32 dec; + s32 maxspeed; + s32 min_x; + s32 max_x; + } run_param_t; + + typedef struct { + uint8_t pad; + } warning_limit_param_t; + + typedef struct { + u32 move_to_zero_max_d; + u32 leave_from_zero_max_d; + u32 speed; + u32 dec; + } run_to_zero_param_t; + + public: + virtual int32_t move_to(int32_t x, function status_cb) = 0; + virtual int32_t move_by(int32_t dx, function status_cb) = 0; + virtual int32_t move_to_zero(function status_cb) = 0; + virtual int32_t move_to_zero_with_calibrate(int32_t x, function status_cb) = 0; + virtual int32_t enable(bool venable) = 0; + virtual int32_t stop(uint8_t stopType) = 0; + virtual int32_t force_change_current_pos(int32_t x) = 0; + virtual int32_t rotate(int32_t speed, int32_t lastforms, function status_cb) = 0; + + virtual int32_t read_version(version_t& version) = 0; + virtual int32_t read_status(status_t& status) = 0; + virtual int32_t read_debug_info(debug_info_t& debug_info) = 0; + + virtual int32_t set_run_param(uint8_t operation, const run_param_t& param, run_param_t& ack) = 0; + virtual int32_t set_run_to_zero_param(uint8_t operation, const run_to_zero_param_t& param, run_to_zero_param_t& ack) = 0; + virtual int32_t set_warning_limit_param(uint8_t operation, const warning_limit_param_t& param, warning_limit_param_t& ack) = 0; +}; +} // namespace iflytop \ No newline at end of file diff --git a/zcancmder_protocol.hpp b/zcancmder_protocol.hpp index a6d9591..ceed921 100644 --- a/zcancmder_protocol.hpp +++ b/zcancmder_protocol.hpp @@ -2,6 +2,7 @@ #include #include "api/basic_type.hpp" +#include "api/i_step_motor_ctrl_module.hpp" #include "api/i_xyrobot_ctrl_module.hpp" #include "zcancmder_protocol_basic.hpp" namespace iflytop { @@ -48,7 +49,8 @@ typedef enum { kcmd_step_motor_ctrl_move_to_zero_with_calibrate = CMDID(1007, 3), // 回零并校准 kcmd_step_motor_ctrl_move_to = CMDID(1007, 4), // 移动到 kcmd_step_motor_ctrl_move_by = CMDID(1007, 5), // 相对移动 - kcmd_step_motor_ctrl_rotate = CMDID(1007, 6), // 相对移动 + kcmd_step_motor_ctrl_force_change_current_pos = CMDID(1007, 6), // 相对移动 + kcmd_step_motor_ctrl_rotate = CMDID(1007, 7), // 相对移动 kcmd_step_motor_ctrl_read_version = CMDID(1007, 50), // 读取模块型号版本信息 kcmd_step_motor_ctrl_read_status = CMDID(1007, 51), // 读取模块精简状态信息 @@ -226,50 +228,23 @@ ZPACKET_CMD_ACK(kcmd_xy_robot_ctrl_set_run_to_zero_param, CMD(u8 id; u8 opt_type /******************************************************************************* * |Module_1007:步进电机控制模组 * *******************************************************************************/ -ZPACKET_CMD_ACK(kcmd_step_motor_ctrl_enable, - CMD(u8 id; u8 enable;), // - ACK(u8 id;)); -ZPACKET_CMD_ACK(kcmd_step_motor_ctrl_stop, - CMD(u8 id; u8 stop_type;), // - ACK(u8 id;)); -ZPACKET_CMD_ACK_AND_REPORT(kcmd_step_motor_ctrl_move_to_zero, - CMD(u8 id;), // - ACK(u8 id;), // - REPORT(u8 id; u8 status;)); -ZPACKET_CMD_ACK_AND_REPORT(kcmd_step_motor_ctrl_move_to_zero_with_calibrate, - CMD(u8 id; s32 nowx; s32 nowy;), // - ACK(u8 id;), // - REPORT(u8 id; u8 status; s32 zero_shift_x;)); -ZPACKET_CMD_ACK_AND_REPORT(kcmd_step_motor_ctrl_move_to, - CMD(u8 id; s32 x; s32 speed;), // - ACK(u8 id;), // - REPORT(u8 id; u8 status; u32 x;)); -ZPACKET_CMD_ACK_AND_REPORT(kcmd_step_motor_ctrl_move_by, - CMD(u8 id; s32 dx; s32 speed;), // - ACK(u8 id;), // - REPORT(u8 id; u8 status; s32 dx;)); -ZPACKET_CMD_ACK_AND_REPORT(kcmd_step_motor_ctrl_rotate, - CMD(u8 id; s32 speed; s32 run_time;), // - ACK(u8 id;), // - REPORT(u8 id; u8 status; s32 has_run_time;)); -ZPACKET_CMD_ACK(kcmd_step_motor_ctrl_read_version, // - CMD(u8 id;), // - ACK(u8 id;)); -ZPACKET_CMD_ACK(kcmd_step_motor_ctrl_read_status, // - CMD(u8 id;), // - ACK(u8 id; u8 status; s32 x; s32 velocity;)); -ZPACKET_CMD_ACK(kcmd_step_motor_ctrl_read_debug_info, // - CMD(u8 id;), // - ACK(u8 id; u8 status; s32 x; s32 velocity; s32 acc; s32 dec; s32 speed;)); -ZPACKET_CMD_ACK(kcmd_step_motor_ctrl_set_run_param, // - CMD(u8 id; u8 opt_type; u8 shaft; s32 d_scale; s32 x_shift; s32 acc; s32 dec; s32 breakdec; s32 maxv; s32 minpos; s32 maxpos;), // - ACK(u8 id; u8 opt_type; u8 shaft; s32 d_scale; s32 x_shift; s32 acc; s32 dec; s32 breakdec; s32 maxv; s32 minpos; s32 maxpos;)); -ZPACKET_CMD_ACK(kcmd_step_motor_ctrl_set_warning_limit_param, // - CMD(u8 id; u8 opt_type; s32 pad;), // - ACK(u8 id; u8 opt_type; s32 pad;)); -ZPACKET_CMD_ACK(kcmd_step_motor_ctrl_set_run_to_zero_param, // - CMD(u8 id; u8 opt_type; u32 move_to_zero_max_d; u32 leave_from_zero_max_d; u32 speed; u32 dec;), // - ACK(u8 id; u8 opt_type; u32 move_to_zero_max_d; u32 leave_from_zero_max_d; u32 speed; u32 dec;)); + +ZPACKET_CMD_ACK(kcmd_step_motor_ctrl_enable, CMD(u8 id; u8 enable;), ACK(u8 id;)); +ZPACKET_CMD_ACK(kcmd_step_motor_ctrl_stop, CMD(u8 id; u8 stop_type;), ACK(u8 id;)); +ZPACKET_CMD_ACK_AND_REPORT(kcmd_step_motor_ctrl_move_to_zero, CMD(u8 id;), ACK(u8 id;), REPORT(u8 id; I_StepMotorCtrlModule::move_to_zero_cb_status_t status;)); +ZPACKET_CMD_ACK_AND_REPORT(kcmd_step_motor_ctrl_move_to_zero_with_calibrate, CMD(u8 id; s32 nowx; s32 nowy;), ACK(u8 id;), REPORT(u8 id; I_StepMotorCtrlModule::move_to_zero_with_calibrate_cb_status_t status;)); +ZPACKET_CMD_ACK_AND_REPORT(kcmd_step_motor_ctrl_move_to, CMD(u8 id; s32 x; s32 y; s32 speed;), ACK(u8 id;), REPORT(u8 id; I_StepMotorCtrlModule::move_to_cb_status_t status;)); +ZPACKET_CMD_ACK_AND_REPORT(kcmd_step_motor_ctrl_move_by, CMD(u8 id; s32 dx; s32 dy; s32 speed;), ACK(u8 id;), REPORT(u8 id; I_StepMotorCtrlModule::move_by_cb_status_t status;)); +ZPACKET_CMD_ACK(kcmd_step_motor_ctrl_force_change_current_pos, CMD(u8 id; s32 x; s32 y;), ACK(u8 id;)); +ZPACKET_CMD_ACK_AND_REPORT(kcmd_step_motor_ctrl_rotate, CMD(u8 id; s32 speed; s32 run_time;), ACK(u8 id;), REPORT(u8 id; I_StepMotorCtrlModule::rotate_cb_status_t status;)); +// READ +ZPACKET_CMD_ACK(kcmd_step_motor_ctrl_read_version, CMD(u8 id;), ACK(u8 id; I_StepMotorCtrlModule::version_t ack;)); +ZPACKET_CMD_ACK(kcmd_step_motor_ctrl_read_status, CMD(u8 id;), ACK(u8 id; I_StepMotorCtrlModule::status_t ack;)); +ZPACKET_CMD_ACK(kcmd_step_motor_ctrl_read_debug_info, CMD(u8 id;), ACK(u8 id; I_StepMotorCtrlModule::debug_info_t ack;)); +// SET +ZPACKET_CMD_ACK(kcmd_step_motor_ctrl_set_run_param, CMD(u8 id; u8 opt_type; I_StepMotorCtrlModule::run_param_t param;), ACK(u8 id; I_StepMotorCtrlModule::run_param_t ack;)); +ZPACKET_CMD_ACK(kcmd_step_motor_ctrl_set_warning_limit_param, CMD(u8 id; u8 opt_type; I_StepMotorCtrlModule::warning_limit_param_t param;), ACK(u8 id; I_StepMotorCtrlModule::warning_limit_param_t ack;)); +ZPACKET_CMD_ACK(kcmd_step_motor_ctrl_set_run_to_zero_param, CMD(u8 id; u8 opt_type; I_StepMotorCtrlModule::run_to_zero_param_t param;), ACK(u8 id; I_StepMotorCtrlModule::run_to_zero_param_t ack;)); /******************************************************************************* * |Module_1008:舵机 *