From 563e4ca7f479b028da851852ebec4fdfad95482e Mon Sep 17 00:00:00 2001 From: zhaohe Date: Wed, 5 Jun 2024 20:20:10 +0800 Subject: [PATCH] update --- .../step_motor_ctrl_module/step_motor_ctrl_module.cpp | 14 +++++++++++--- .../step_motor_ctrl_module/step_motor_ctrl_module.hpp | 12 +++++++----- components/zcancmder/zcan_protocol_parser.cpp | 5 +++++ components/zcancmder/zcan_protocol_parser.hpp | 1 + 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/components/step_motor_ctrl_module/step_motor_ctrl_module.cpp b/components/step_motor_ctrl_module/step_motor_ctrl_module.cpp index d249ac1..12cf149 100644 --- a/components/step_motor_ctrl_module/step_motor_ctrl_module.cpp +++ b/components/step_motor_ctrl_module/step_motor_ctrl_module.cpp @@ -401,9 +401,15 @@ int32_t StepMotorCtrlModule::step_motor_easy_move_to_io(int32_t ioindex, int32_t return do_step_motor_easy_move_to_io(ioindex, direction); } -// -// -// +int32_t StepMotorCtrlModule::step_motor_easy_move_to_end_point() { + ZLOGI(TAG, "m%d step_motor_easy_move_to_end_point", m_id); + int32_t ecode = check_befor_run(); + if (ecode != 0) return ecode; + if (m_nio <= 1) { + return err::kstep_motor_ioindex_out_of_range; + } + return do_step_motor_easy_move_to_end_point(); +} int32_t StepMotorCtrlModule::do_step_motor_easy_rotate(int32_t direction) { m_thread.stop(); @@ -492,3 +498,5 @@ int32_t StepMotorCtrlModule::do_step_motor_easy_move_to_io(int32_t ioindex, int3 return 0; } + +int32_t StepMotorCtrlModule::do_step_motor_easy_move_to_end_point() { return do_step_motor_easy_move_to_io(1, 1); } diff --git a/components/step_motor_ctrl_module/step_motor_ctrl_module.hpp b/components/step_motor_ctrl_module/step_motor_ctrl_module.hpp index 1b0e3e9..5462660 100644 --- a/components/step_motor_ctrl_module/step_motor_ctrl_module.hpp +++ b/components/step_motor_ctrl_module/step_motor_ctrl_module.hpp @@ -2,8 +2,8 @@ // #include "sdk/os/zos.hpp" #include "sdk\components\tmc\basic\tmc_ic_interface.hpp" -#include "sdk\components\zcancmder\zcanreceiver.hpp" #include "sdk\components\tmc\ic\ztmc5130.hpp" +#include "sdk\components\zcancmder\zcanreceiver.hpp" namespace iflytop { class StepMotorCtrlModule : public ZIModule, public ZIStepMotor { ENABLE_MODULE(StepMotorCtrlModule, ktmc_step_motor, PC_VERSION); @@ -31,10 +31,10 @@ class StepMotorCtrlModule : public ZIModule, public ZIStepMotor { } config_t; typedef struct { - int32_t dpos; - int32_t after_move_pos; - int32_t before_move_pos; - int32_t enable; + int32_t dpos; + int32_t after_move_pos; + int32_t before_move_pos; + int32_t enable; } state_t; private: @@ -77,6 +77,7 @@ class StepMotorCtrlModule : public ZIModule, public ZIStepMotor { virtual int32_t step_motor_easy_move_to(int32_t position) override; virtual int32_t step_motor_easy_move_to_zero() override; virtual int32_t step_motor_easy_move_to_io(int32_t ioindex, int32_t direction) override; + virtual int32_t step_motor_easy_move_to_end_point() override; virtual int32_t step_motor_easy_set_current_pos(int32_t pos) override; virtual int32_t step_motor_active_cfg() override; @@ -96,6 +97,7 @@ class StepMotorCtrlModule : public ZIModule, public ZIStepMotor { int32_t do_step_motor_easy_move_to(int32_t position); int32_t do_step_motor_easy_move_to_zero(); int32_t do_step_motor_easy_move_to_io(int32_t ioindex, int32_t direction); + int32_t do_step_motor_easy_move_to_end_point(); private: void inter_inverse_kinematics(int32_t motor_pos, int32_t& x); diff --git a/components/zcancmder/zcan_protocol_parser.cpp b/components/zcancmder/zcan_protocol_parser.cpp index 9be0dd3..5ed1725 100644 --- a/components/zcancmder/zcan_protocol_parser.cpp +++ b/components/zcancmder/zcan_protocol_parser.cpp @@ -34,6 +34,7 @@ void ZCanProtocolParser::initialize(IZCanReceiver* cancmder) { REGFN(step_motor_stop); REGFN(step_motor_read_io_state); REGFN(step_motor_read_tmc5130_status); + REGFN(step_motor_easy_move_to_end_point); REGFN(mini_servo_enable); REGFN(mini_servo_read_pos); @@ -253,6 +254,10 @@ int32_t ZCanProtocolParser::step_motor_read_tmc5130_status(cmdcontxt_t* cxt) { cxt->acklen = 4; return module->step_motor_read_tmc5130_status(&ack[0]); } +int32_t ZCanProtocolParser::step_motor_easy_move_to_end_point(cmdcontxt_t* cxt) { + CHECK_AND_GET_MODULE(0); + return module->step_motor_easy_move_to_end_point(); +} #undef MODULE_CLASS #define MODULE_CLASS ZIMiniServo diff --git a/components/zcancmder/zcan_protocol_parser.hpp b/components/zcancmder/zcan_protocol_parser.hpp index b48da31..e096023 100644 --- a/components/zcancmder/zcan_protocol_parser.hpp +++ b/components/zcancmder/zcan_protocol_parser.hpp @@ -69,6 +69,7 @@ class ZCanProtocolParser : public IZCanReceiverListener { static int32_t step_motor_active_cfg(cmdcontxt_t* cxt); static int32_t step_motor_read_io_state(cmdcontxt_t* cxt); static int32_t step_motor_read_tmc5130_status(cmdcontxt_t* cxt); + static int32_t step_motor_easy_move_to_end_point(cmdcontxt_t* cxt); static int32_t mini_servo_enable(cmdcontxt_t* cxt);