Browse Source

Merge branch 'master' of 192.168.1.3:manufacturer_stm32/iflytop_stm32_os_sdk

master
zhaohe 2 years ago
parent
commit
74b48f099c
  1. 116
      components/step_motor_ctrl_module/step_motor_ctrl_module.cpp
  2. 1
      components/step_motor_ctrl_module/step_motor_ctrl_module.hpp

116
components/step_motor_ctrl_module/step_motor_ctrl_module.cpp

@ -625,69 +625,69 @@ int32_t StepMotorCtrlModule::module_get_error(int32_t* iserror) {
return 0;
}
int32_t StepMotorCtrlModule::module_set_param(int32_t param_id, int32_t param_value) {
if (param_id == kcfg_motor_x_shift) {
m_param.shift_x = param_value;
return 0;
}
if (param_id == kcfg_motor_x_shaft) {
m_param.x_shaft = param_value;
return 0;
}
if (param_id == kcfg_motor_x_one_circle_pulse) {
m_param.distance_scale = param_value;
return 0;
}
#if 0
kcfg_motor_x_shift = CONFIG_CODE(100, 0), // x偏移
kcfg_motor_x_shaft = CONFIG_CODE(100, 3), // x轴是否反转
kcfg_motor_x_one_circle_pulse = CONFIG_CODE(100, 6), // x轴一圈脉冲数
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_look_zero_edge_max_x_d = CONFIG_CODE(150, 3), // x轴找零边缘最大距离
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),
if (param_id == k_cfg_stepmotor_ihold) {
m_param.ihold = param_value;
return 0;
}
#endif
if (param_id == k_cfg_stepmotor_irun) {
m_param.irun = param_value;
return 0;
#define SET_CONFIG(param_id, configval) \
case param_id: \
if (set) { \
configval = param_value; \
} else { \
param_value = configval; \
} \
break;
int32_t StepMotorCtrlModule::_module_set_or_get_param(bool set, int32_t param_id, int32_t& param_value) {
switch (param_id) {
SET_CONFIG(kcfg_motor_x_shift, m_param.shift_x);
SET_CONFIG(kcfg_motor_x_shaft, m_param.x_shaft);
SET_CONFIG(kcfg_motor_x_one_circle_pulse, m_param.distance_scale);
SET_CONFIG(kcfg_motor_default_velocity, m_param.maxspeed);
SET_CONFIG(kcfg_motor_default_acc, m_param.acc);
SET_CONFIG(kcfg_motor_default_dec, m_param.dec);
// SET_CONFIG(kcfg_motor_default_break_dec, m_param.dec);
SET_CONFIG(kcfg_motor_run_to_zero_max_x_d, m_param.run_to_zero_max_d);
SET_CONFIG(kcfg_motor_look_zero_edge_max_x_d, m_param.look_zero_edge_max_d);
SET_CONFIG(kcfg_motor_run_to_zero_speed, m_param.run_to_zero_speed);
SET_CONFIG(kcfg_motor_run_to_zero_dec, m_param.run_to_zero_dec);
SET_CONFIG(kcfg_motor_look_zero_edge_speed, m_param.look_zero_edge_speed);
SET_CONFIG(kcfg_motor_look_zero_edge_dec, m_param.look_zero_edge_dec);
SET_CONFIG(k_cfg_stepmotor_ihold, m_param.ihold);
SET_CONFIG(k_cfg_stepmotor_irun, m_param.irun);
SET_CONFIG(k_cfg_stepmotor_iholddelay, m_param.iholddelay);
default:
return err::kmodule_not_find_config_index;
}
return 0;
}
if (param_id == k_cfg_stepmotor_iholddelay) {
m_param.iholddelay = param_value;
return 0;
}
return err::kmodule_not_find_config_index;
int32_t StepMotorCtrlModule::module_set_param(int32_t param_id, int32_t param_value) {
return _module_set_or_get_param(true, param_id, param_value);
}
int32_t StepMotorCtrlModule::module_get_param(int32_t param_id, int32_t* param_value) {
if (param_id == kcfg_motor_x_shift) {
*param_value = m_param.shift_x;
return 0;
}
if (param_id == kcfg_motor_x_shaft) {
*param_value = m_param.x_shaft;
return 0;
}
if (param_id == kcfg_motor_x_one_circle_pulse) {
*param_value = m_param.distance_scale;
return 0;
}
if (param_id == k_cfg_stepmotor_ihold) {
*param_value = m_param.ihold;
return 0;
}
if (param_id == k_cfg_stepmotor_irun) {
*param_value = m_param.irun;
return 0;
}
if (param_id == k_cfg_stepmotor_iholddelay) {
*param_value = m_param.iholddelay;
return 0;
}
return err::kmodule_not_find_config_index;
return _module_set_or_get_param(false, param_id, *param_value);
}
int32_t StepMotorCtrlModule::module_clear_error() { return 0; }
@ -758,7 +758,7 @@ int32_t StepMotorCtrlModule::motor_move_to(int32_t tox, int32_t motor_velocity,
if (acc == 0) {
acc = m_param.acc;
}
if(motor_velocity == 0){
if (motor_velocity == 0) {
motor_velocity = m_param.maxspeed;
}

1
components/step_motor_ctrl_module/step_motor_ctrl_module.hpp

@ -113,6 +113,7 @@ class StepMotorCtrlModule : public I_StepMotorCtrlModule, public ZIModule, publi
virtual int32_t module_set_param(int32_t param_id, int32_t param_value) override;
virtual int32_t module_get_param(int32_t param_id, int32_t* param_value) override;
int32_t _module_set_or_get_param(bool set, int32_t param_id, int32_t& param_value);
virtual int32_t module_readio(int32_t* io) override;
virtual int32_t module_writeio(int32_t io) override;

Loading…
Cancel
Save