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 76a16aa..628e863 100644 --- a/components/step_motor_ctrl_module/step_motor_ctrl_module.cpp +++ b/components/step_motor_ctrl_module/step_motor_ctrl_module.cpp @@ -45,6 +45,29 @@ void StepMotorCtrlModule::create_default_cfg(config_t& cfg) { * EXT * ***********************************************************************************************************************/ int32_t StepMotorCtrlModule::module_xxx_reg(int32_t param_id, bool read, int32_t& val) { + int32_t suc = pri_module_xxx_reg(param_id, read, val); + if (suc != 0) return suc; + switch (param_id) { + case kreg_step_motor_shaft: + case kreg_step_motor_one_circle_pulse: + case kreg_step_motor_one_circle_pulse_denominator: + case kreg_step_motor_default_velocity: + case kreg_step_motor_default_acc: + case kreg_step_motor_default_dec: + case kreg_step_motor_run_to_zero_speed: + case kreg_step_motor_run_to_zero_dec: + case kreg_step_motor_look_zero_edge_speed: + case kreg_step_motor_look_zero_edge_dec: + case kreg_step_motor_ihold: + case kreg_step_motor_irun: + case kreg_step_motor_iholddelay: + case kreg_step_motor_max_d: + case kreg_step_motor_min_d: + step_motor_active_cfg(); + } + return suc; +} +int32_t StepMotorCtrlModule::pri_module_xxx_reg(int32_t param_id, bool read, int32_t& val) { switch (param_id) { MODULE_COMMON_PROCESS_REG_CB(); PROCESS_REG(kreg_step_motor_pos, inter_get_pos(val), ACTION_NONE); @@ -71,6 +94,7 @@ int32_t StepMotorCtrlModule::module_xxx_reg(int32_t param_id, bool read, int32_t } return 0; } + int32_t StepMotorCtrlModule::step_motor_enable(int32_t enable) { ZLOGI(TAG, "m%d motor_enable %ld", m_id, enable); m_stepM1->enable(enable); @@ -215,11 +239,16 @@ int32_t StepMotorCtrlModule::step_motor_easy_set_current_pos(int32_t pos) { } int32_t StepMotorCtrlModule::step_motor_active_cfg() { + ZLOGI(TAG, "m%d motor_active_cfg", m_id); m_stepM1->enable(false); m_stepM1->setIHOLD_IRUN(m_cfg.stepmotor_ihold, m_cfg.stepmotor_irun, m_cfg.stepmotor_iholddelay); m_stepM1->setScale(m_cfg.motor_one_circle_pulse); m_stepM1->setScaleDenominator(m_cfg.motor_one_circle_pulse_denominator); m_stepM1->setMotorShaft(m_cfg.motor_shaft); + if (m_state.enable) { + m_stepM1->enable(true); + } + return 0; } 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 05b87d8..694d2db 100644 --- a/components/step_motor_ctrl_module/step_motor_ctrl_module.hpp +++ b/components/step_motor_ctrl_module/step_motor_ctrl_module.hpp @@ -92,5 +92,7 @@ class StepMotorCtrlModule : public ZIModule, public ZIStepMotor { int32_t exec_move_to_io_task(int32_t ioindex, int32_t direction); void _rotate(int32_t vel, int32_t acc, int32_t dec); + + int32_t pri_module_xxx_reg(int32_t param_id, bool read, int32_t& val); }; } // namespace iflytop \ No newline at end of file diff --git a/components/tmc/ic/ztmc5130.cpp b/components/tmc/ic/ztmc5130.cpp index d2c26ed..465785e 100644 --- a/components/tmc/ic/ztmc5130.cpp +++ b/components/tmc/ic/ztmc5130.cpp @@ -284,12 +284,12 @@ int32_t TMC5130::to_motor_vel(int32_t vel) { // return val; } // rpm int32_t TMC5130::to_motor_pos(int32_t pos) { // - int32_t val = pos * 1.0 / m_scale * m_scale_deceleration * m_onecirclepulse; + int32_t val = pos * 1.0 / m_scale * m_scale_deceleration * m_onecirclepulse + 0.5; return val; } // int32_t TMC5130::to_user_pos(int32_t pos) { // - int32_t val = pos / m_onecirclepulse * m_scale / m_scale_deceleration; + int32_t val = pos / m_onecirclepulse * m_scale / m_scale_deceleration + 0.5; return val; } // int32_t TMC5130::to_user_vel(int32_t vel) { //