From 850402ceaf70cdcabc1773af1ef4bc7019cada36 Mon Sep 17 00:00:00 2001 From: zhaohe Date: Sat, 21 Oct 2023 16:36:31 +0800 Subject: [PATCH] update --- api/config_index.hpp | 36 ++++++++++++++++++++++++++++++++--- api/zi_xymotor.hpp | 1 + cmdid.hpp | 7 ++++--- protocol_parser.cpp | 8 ++++++++ protocol_proxy.cpp | 3 ++- protocol_proxy.hpp | 17 +++++++++++------ zmodule_device_manager.cpp | 3 ++- zmodule_device_manager.hpp | 13 ++++++++++--- zmodule_device_script_cmder_paser.cpp | 13 +++++++------ 9 files changed, 78 insertions(+), 23 deletions(-) diff --git a/api/config_index.hpp b/api/config_index.hpp index b6648ed..69caeb4 100644 --- a/api/config_index.hpp +++ b/api/config_index.hpp @@ -19,9 +19,39 @@ typedef enum { kcfg_motor_y_one_circle_pulse = CONFIG_CODE(100, 7), // y轴一圈脉冲数 kcfg_motor_z_one_circle_pulse = CONFIG_CODE(100, 8), // z轴一圈脉冲数 - k_cfg_stepmotor_ihold = CONFIG_CODE(100, 9), - k_cfg_stepmotor_irun = CONFIG_CODE(100, 10), - k_cfg_stepmotor_iholddelay = CONFIG_CODE(100, 11), + kcfg_motor_default_velocity = CONFIG_CODE(100, 9), // 默认速度 + kcfg_motor_default_acc = CONFIG_CODE(100, 10), // 默认加速度 + kcfg_motor_default_dec = CONFIG_CODE(100, 11), // 默认减速度 + kcfg_motor_default_break_dec = CONFIG_CODE(100, 12), // 默认减速度 + + /******************************************************************************* + * 电机找零相关配置 * + *******************************************************************************/ + kcfg_motor_run_to_zero_max_x_d = CONFIG_CODE(150, 0), // x轴回零最大距离 + kcfg_motor_run_to_zero_max_y_d = CONFIG_CODE(150, 1), // y轴回零最大距离 + kcfg_motor_run_to_zero_max_z_d = CONFIG_CODE(150, 2), // z轴回零最大距离 + + kcfg_motor_look_zero_edge_max_x_d = CONFIG_CODE(150, 3), // x轴找零边缘最大距离 + kcfg_motor_look_zero_edge_max_y_d = CONFIG_CODE(150, 4), // y轴找零边缘最大距离 + kcfg_motor_look_zero_edge_max_z_d = CONFIG_CODE(150, 5), // z轴找零边缘最大距离 + + kcfg_motor_run_to_zero_speed = CONFIG_CODE(150, 6), // 回零速度 + kcfg_motor_run_to_zero_dec = CONFIG_CODE(150, 7), // 回零减速度 + + kcfg_motor_look_zero_edge_speed = CONFIG_CODE(150, 8), // 找零边缘速度 + kcfg_motor_look_zero_edge_dec = CONFIG_CODE(150, 9), // 找零边缘减速度 + + /******************************************************************************* + * 步进电机相关配置 * + *******************************************************************************/ + k_cfg_stepmotor_ihold = CONFIG_CODE(200, 0), + k_cfg_stepmotor_irun = CONFIG_CODE(200, 1), + k_cfg_stepmotor_iholddelay = CONFIG_CODE(200, 2), + + /******************************************************************************* + * XY_ROBOT_CONFIG * + *******************************************************************************/ + k_cfg_xyrobot_robot_type = CONFIG_CODE(300, 0), // 机器人类型 0:hbot 1:corexy } config_index_t; diff --git a/api/zi_xymotor.hpp b/api/zi_xymotor.hpp index ffbe1ab..a738ed3 100644 --- a/api/zi_xymotor.hpp +++ b/api/zi_xymotor.hpp @@ -13,5 +13,6 @@ class ZIXYMotor { virtual int32_t xymotor_enable(int32_t enable) { return err::koperation_not_support; } virtual int32_t xymotor_move_by(int32_t dx, int32_t dy, int32_t motor_velocity) { return err::koperation_not_support; } virtual int32_t xymotor_move_to(int32_t x, int32_t y, int32_t motor_velocity) { return err::koperation_not_support; } + virtual int32_t xymotor_move_to_zero() { return err::koperation_not_support; } }; } // namespace iflytop \ No newline at end of file diff --git a/cmdid.hpp b/cmdid.hpp index 8f9e50f..cd50f55 100644 --- a/cmdid.hpp +++ b/cmdid.hpp @@ -34,9 +34,10 @@ typedef enum { kmotor_read_pos = CMDID(2, 11), // para:{}, ack:{4} kmotor_set_current_pos_by_change_shift = CMDID(2, 12), // para:{4}, ack:{} - kxymotor_enable = CMDID(3, 1), // para:{1}, ack:{} - kxymotor_move_by = CMDID(3, 2), // para:{4,4,4}, ack:{} - kxymotor_move_to = CMDID(3, 3), // para:{4,4,4}, ack:{} + kxymotor_enable = CMDID(3, 1), // para:{1}, ack:{} + kxymotor_move_by = CMDID(3, 2), // para:{4,4,4}, ack:{} + kxymotor_move_to = CMDID(3, 3), // para:{4,4,4}, ack:{} + kxymotor_move_to_zero = CMDID(3, 4), // para:{}, ack:{} } cmdid_t; diff --git a/protocol_parser.cpp b/protocol_parser.cpp index 4a38dfc..89f1341 100644 --- a/protocol_parser.cpp +++ b/protocol_parser.cpp @@ -161,7 +161,15 @@ void ZIProtocolParser::onRceivePacket(zcr_cmd_header_t* rxcmd, uint8_t* data, in /******************************************************************************* * xymotor * *******************************************************************************/ +#if 0 + virtual int32_t xymotor_enable(int32_t enable) { return err::koperation_not_support; } + virtual int32_t xymotor_move_by(int32_t dx, int32_t dy, int32_t motor_velocity) { return err::koperation_not_support; } + virtual int32_t xymotor_move_to(int32_t x, int32_t y, int32_t motor_velocity) { return err::koperation_not_support; } + virtual int32_t xymotor_move_to_zero() { return err::koperation_not_support; } +#endif + PROCESS_PACKET_10(kxymotor_enable, ZIXYMotor, xymotor_enable); PROCESS_PACKET_30(kxymotor_move_by, ZIXYMotor, xymotor_move_by); PROCESS_PACKET_30(kxymotor_move_to, ZIXYMotor, xymotor_move_to); + PROCESS_PACKET_00(kxymotor_move_to_zero, ZIXYMotor, xymotor_move_to_zero); } \ No newline at end of file diff --git a/protocol_proxy.cpp b/protocol_proxy.cpp index 47c4013..8748406 100644 --- a/protocol_proxy.cpp +++ b/protocol_proxy.cpp @@ -118,4 +118,5 @@ int32_t ZIProtocolProxy::motor_set_current_pos_by_change_shift(int32_t para0) { *******************************************************************************/ int32_t ZIProtocolProxy::xymotor_enable(int32_t para0) { PROXY_IMPL_10(kxymotor_enable); } int32_t ZIProtocolProxy::xymotor_move_by(int32_t para0, int32_t para1, int32_t para2) { PROXY_IMPL_30(kxymotor_move_by); } -int32_t ZIProtocolProxy::xymotor_move_to(int32_t para0, int32_t para1, int32_t para2) { PROXY_IMPL_30(kxymotor_move_to); } \ No newline at end of file +int32_t ZIProtocolProxy::xymotor_move_to(int32_t para0, int32_t para1, int32_t para2) { PROXY_IMPL_30(kxymotor_move_to); } +int32_t ZIProtocolProxy::xymotor_move_to_zero() { PROXY_IMPL_00(kxymotor_move_to_zero); } diff --git a/protocol_proxy.hpp b/protocol_proxy.hpp index da22998..d4fe565 100644 --- a/protocol_proxy.hpp +++ b/protocol_proxy.hpp @@ -14,7 +14,7 @@ class ZIProtocolProxy : public ZIMotor, // int32_t m_id = 0; public: - void initialize(int32_t moduleId,IZcanCmderMaster *cancmder) { + void initialize(int32_t moduleId, IZcanCmderMaster *cancmder) { m_cancmder = cancmder; m_id = moduleId; } @@ -51,8 +51,6 @@ class ZIProtocolProxy : public ZIMotor, // virtual int32_t module_flush_cfg() override; virtual int32_t module_active_cfg() override; - - /******************************************************************************* * ZIMotor * *******************************************************************************/ @@ -73,12 +71,19 @@ class ZIProtocolProxy : public ZIMotor, // virtual int32_t motor_read_pos(int32_t *pos) override; virtual int32_t motor_set_current_pos_by_change_shift(int32_t pos) override; - /******************************************************************************* - * ZIXYMotor * - *******************************************************************************/ +/******************************************************************************* + * ZIXYMotor * + *******************************************************************************/ +#if 0 + virtual int32_t xymotor_enable(int32_t enable) { return err::koperation_not_support; } + virtual int32_t xymotor_move_by(int32_t dx, int32_t dy, int32_t motor_velocity) { return err::koperation_not_support; } + virtual int32_t xymotor_move_to(int32_t x, int32_t y, int32_t motor_velocity) { return err::koperation_not_support; } + virtual int32_t xymotor_move_to_zero() { return err::koperation_not_support; } +#endif virtual int32_t xymotor_enable(int32_t enable) override; virtual int32_t xymotor_move_by(int32_t dx, int32_t dy, int32_t motor_velocity) override; virtual int32_t xymotor_move_to(int32_t x, int32_t y, int32_t motor_velocity) override; + virtual int32_t xymotor_move_to_zero() override; }; } // namespace iflytop \ No newline at end of file diff --git a/zmodule_device_manager.cpp b/zmodule_device_manager.cpp index 44fdb7f..6a52ff0 100644 --- a/zmodule_device_manager.cpp +++ b/zmodule_device_manager.cpp @@ -63,4 +63,5 @@ int32_t ZModuleDeviceManager::motor_set_current_pos_by_change_shift(uint16_t id, *******************************************************************************/ int32_t ZModuleDeviceManager::xymotor_enable(uint16_t id, int32_t enable) { PROXY_IMPL(ZIXYMotor, xymotor_enable, enable); } int32_t ZModuleDeviceManager::xymotor_move_by(uint16_t id, int32_t dx, int32_t dy, int32_t motor_velocity) { PROXY_IMPL(ZIXYMotor, xymotor_move_by, dx, dy, motor_velocity); } -int32_t ZModuleDeviceManager::xymotor_move_to(uint16_t id, int32_t x, int32_t y, int32_t motor_velocity) { PROXY_IMPL(ZIXYMotor, xymotor_move_to, x, y, motor_velocity); } \ No newline at end of file +int32_t ZModuleDeviceManager::xymotor_move_to(uint16_t id, int32_t x, int32_t y, int32_t motor_velocity) { PROXY_IMPL(ZIXYMotor, xymotor_move_to, x, y, motor_velocity); } +int32_t ZModuleDeviceManager::xymotor_move_to_zero(uint16_t id) { PROXY_IMPL(ZIXYMotor, xymotor_move_to_zero); } \ No newline at end of file diff --git a/zmodule_device_manager.hpp b/zmodule_device_manager.hpp index 8756d35..9c87acd 100644 --- a/zmodule_device_manager.hpp +++ b/zmodule_device_manager.hpp @@ -96,12 +96,19 @@ class ZModuleDeviceManager { int32_t motor_read_pos(uint16_t id, int32_t *pos); int32_t motor_set_current_pos_by_change_shift(uint16_t id, int32_t pos); - /******************************************************************************* - * ZIXYMotor * - *******************************************************************************/ +/******************************************************************************* + * ZIXYMotor * + *******************************************************************************/ +#if 0 + virtual int32_t xymotor_enable(int32_t enable) { return err::koperation_not_support; } + virtual int32_t xymotor_move_by(int32_t dx, int32_t dy, int32_t motor_velocity) { return err::koperation_not_support; } + virtual int32_t xymotor_move_to(int32_t x, int32_t y, int32_t motor_velocity) { return err::koperation_not_support; } + virtual int32_t xymotor_move_to_zero() { return err::koperation_not_support; } +#endif int32_t xymotor_enable(uint16_t id, int32_t enable); int32_t xymotor_move_by(uint16_t id, int32_t dx, int32_t dy, int32_t motor_velocity); int32_t xymotor_move_to(uint16_t id, int32_t x, int32_t y, int32_t motor_velocity); + int32_t xymotor_move_to_zero(uint16_t id); private: template diff --git a/zmodule_device_script_cmder_paser.cpp b/zmodule_device_script_cmder_paser.cpp index 279a6a9..17595bd 100644 --- a/zmodule_device_script_cmder_paser.cpp +++ b/zmodule_device_script_cmder_paser.cpp @@ -90,12 +90,6 @@ void ZModuleDeviceScriptCmderPaser::initialize(ICmdParser* cancmder, ZModuleDevi int32_t motor_read_pos(uint16_t id, int32_t *pos); int32_t motor_set_current_pos_by_change_shift(uint16_t id, int32_t pos); - /******************************************************************************* - * ZIXYMotor * - *******************************************************************************/ - int32_t xymotor_enable(uint16_t id, int32_t enable); - int32_t xymotor_move_by(uint16_t id, int32_t dx, int32_t dy, int32_t motor_velocity); - int32_t xymotor_move_to(uint16_t id, int32_t x, int32_t y, int32_t motor_velocity); #endif PROCESS_PACKET_10(module_stop, "module_stop (mid)"); @@ -131,7 +125,14 @@ void ZModuleDeviceScriptCmderPaser::initialize(ICmdParser* cancmder, ZModuleDevi PROCESS_PACKET_11(motor_read_pos, "motor_read_pos (mid)"); PROCESS_PACKET_20(motor_set_current_pos_by_change_shift, "motor_set_current_pos_by_change_shift (mid, pos)"); +#if 0 + virtual int32_t xymotor_enable(int32_t enable) { return err::koperation_not_support; } + virtual int32_t xymotor_move_by(int32_t dx, int32_t dy, int32_t motor_velocity) { return err::koperation_not_support; } + virtual int32_t xymotor_move_to(int32_t x, int32_t y, int32_t motor_velocity) { return err::koperation_not_support; } + virtual int32_t xymotor_move_to_zero() { return err::koperation_not_support; } +#endif PROCESS_PACKET_20(xymotor_enable, "xymotor_enable (mid, enable)"); PROCESS_PACKET_40(xymotor_move_by, "xymotor_move_by (mid, dx, dy, motor_velocity)"); PROCESS_PACKET_40(xymotor_move_to, "xymotor_move_to (mid, x, y, motor_velocity)"); + PROCESS_PACKET_10(xymotor_move_to_zero, "xymotor_move_to_zero (mid)"); }