Browse Source

update

master
zhaohe 2 years ago
parent
commit
8edb65f2bc
  1. 74
      components/step_motor_ctrl_module/step_motor_ctrl_module.cpp
  2. 34
      components/step_motor_ctrl_module/step_motor_ctrl_module.hpp
  3. 2
      components/zprotocols/zcancmder
  4. 2
      components/zprotocols/zcancmder_v2

74
components/step_motor_ctrl_module/step_motor_ctrl_module.cpp

@ -219,7 +219,8 @@ int32_t StepMotorCtrlModule::enable(bool venable) {
zlock_guard l(m_lock);
ZLOGI(TAG, "m%d enable %d", m_id, venable);
m_stepM1->enable(venable);
m_enable = venable;
// m_enable = venable;
m_com_reg.module_enable = venable;
return 0;
}
int32_t StepMotorCtrlModule::stop(uint8_t stopType) {
@ -295,7 +296,7 @@ int32_t StepMotorCtrlModule::read_detailed_status(detailed_status_t& debug_info)
debug_info.io_state |= (0x01 << i);
}
}
debug_info.last_exec_status = m_module_last_cmd_exec_status;
debug_info.last_exec_status = m_com_reg.module_last_cmd_exec_status;
getnowpos(debug_info.x);
return 0;
}
@ -563,8 +564,8 @@ int32_t StepMotorCtrlModule::move_by_block(int32_t dx, int32_t velocity, int ove
}
void StepMotorCtrlModule::call_exec_status_cb(int32_t status, action_cb_status_t status_cb) {
m_module_last_cmd_exec_status = status;
auto cache_status_cb = m_status_cb;
m_com_reg.module_last_cmd_exec_status = status;
auto cache_status_cb = m_status_cb;
if (cache_status_cb) cache_status_cb(status);
}
void StepMotorCtrlModule::create_default_cfg(flash_config_t& cfg) {
@ -620,11 +621,11 @@ int32_t StepMotorCtrlModule::getid(int32_t* id) {
int32_t StepMotorCtrlModule::module_stop() { return stop(0); }
int32_t StepMotorCtrlModule::module_break() { return stop(0); }
int32_t StepMotorCtrlModule::module_get_last_exec_status(int32_t* status) {
*status = m_module_last_cmd_exec_status;
*status = m_com_reg.module_last_cmd_exec_status;
return 0;
}
int32_t StepMotorCtrlModule::module_get_status(int32_t* status) {
//ZLOGI(TAG, "[%d]-module_get_status %d", m_id, m_thread.isworking());
// ZLOGI(TAG, "[%d]-module_get_status %d", m_id, m_thread.isworking());
*status = m_thread.isworking() ? 1 : 0;
return 0;
}
@ -668,7 +669,7 @@ int32_t StepMotorCtrlModule::module_get_error(int32_t* iserror) {
case param_id: \
*val = modulereg; \
break;
#if 0
int32_t StepMotorCtrlModule::module_set_reg(int32_t param_id, int32_t val) {
switch (param_id) {
SET_REG(kreg_motor_shift, m_param.shift_x);
@ -723,19 +724,42 @@ int32_t StepMotorCtrlModule::module_get_reg(int32_t param_id, int32_t* val) {
GET_REG(kreg_module_enableflag, m_enable);
GET_REG(kreg_robot_pos, nowpos);
GET_REG(kreg_module_last_cmd_exec_status, m_module_last_cmd_exec_status);
GET_REG(kreg_module_last_cmd_exec_val0, m_module_last_cmd_exec_val0);
GET_REG(kreg_module_last_cmd_exec_val1, m_module_last_cmd_exec_val1);
GET_REG(kreg_module_last_cmd_exec_val2, m_module_last_cmd_exec_val2);
GET_REG(kreg_module_last_cmd_exec_val3, m_module_last_cmd_exec_val3);
GET_REG(kreg_module_last_cmd_exec_val4, m_module_last_cmd_exec_val4);
GET_REG(kreg_module_last_cmd_exec_val5, m_module_last_cmd_exec_val5);
default:
return err::kmodule_not_find_config_index;
}
return 0;
}
#endif
int32_t StepMotorCtrlModule::module_set_reg(int32_t param_id, int32_t param_value) { return module_xxx_reg(param_id, false, param_value); }
int32_t StepMotorCtrlModule::module_get_reg(int32_t param_id, int32_t* param_value) { return module_xxx_reg(param_id, true, *param_value); }
int32_t StepMotorCtrlModule::module_xxx_reg(int32_t param_id, bool read, int32_t& val) {
switch (param_id) {
MODULE_COMMON_PROCESS_REG_CB();
PROCESS_REG(kreg_motor_shift, REG_GET(m_param.shift_x), REG_SET(m_param.shift_x));
PROCESS_REG(kreg_motor_shaft, REG_GET(m_param.x_shaft), REG_SET(m_param.x_shaft));
PROCESS_REG(kreg_motor_one_circle_pulse, REG_GET(m_param.distance_scale), REG_SET(m_param.distance_scale));
PROCESS_REG(kreg_motor_one_circle_pulse_denominator, REG_GET(m_param.distance_scale_denominator), REG_SET(m_param.distance_scale_denominator));
PROCESS_REG(kreg_motor_default_velocity, REG_GET(m_param.maxspeed), REG_SET(m_param.maxspeed));
PROCESS_REG(kreg_motor_default_acc, REG_GET(m_param.acc), REG_SET(m_param.acc));
PROCESS_REG(kreg_motor_default_dec, REG_GET(m_param.dec), REG_SET(m_param.dec));
PROCESS_REG(kreg_motor_run_to_zero_max_d, REG_GET(m_param.run_to_zero_max_d), REG_SET(m_param.run_to_zero_max_d));
PROCESS_REG(kreg_motor_look_zero_edge_max_d, REG_GET(m_param.look_zero_edge_max_d), REG_SET(m_param.look_zero_edge_max_d));
PROCESS_REG(kreg_motor_run_to_zero_speed, REG_GET(m_param.run_to_zero_speed), REG_SET(m_param.run_to_zero_speed));
PROCESS_REG(kreg_motor_run_to_zero_dec, REG_GET(m_param.run_to_zero_dec), REG_SET(m_param.run_to_zero_dec));
PROCESS_REG(kreg_motor_look_zero_edge_speed, REG_GET(m_param.look_zero_edge_speed), REG_SET(m_param.look_zero_edge_speed));
PROCESS_REG(kreg_motor_look_zero_edge_dec, REG_GET(m_param.look_zero_edge_dec), REG_SET(m_param.look_zero_edge_dec));
PROCESS_REG(kreg_stepmotor_ihold, REG_GET(m_param.ihold), REG_SET(m_param.ihold));
PROCESS_REG(kreg_stepmotor_irun, REG_GET(m_param.irun), REG_SET(m_param.irun));
PROCESS_REG(kreg_stepmotor_iholddelay, REG_GET(m_param.iholddelay), REG_SET(m_param.iholddelay));
default:
return err::kmodule_not_find_config_index;
break;
}
return 0;
}
int32_t StepMotorCtrlModule::do_action(int32_t actioncode) {}
int32_t StepMotorCtrlModule::module_clear_error() { return 0; }
@ -819,7 +843,7 @@ int32_t StepMotorCtrlModule::motor_move_to(int32_t tox, int32_t motor_velocity,
call_exec_status_cb(0, nullptr);
},
[this, tox]() { _motor_stop(); });
//ZLOGI(TAG, "m%d motor_move_to %d end", m_id, tox);
// ZLOGI(TAG, "m%d motor_move_to %d end", m_id, tox);
return 0;
}
int32_t StepMotorCtrlModule::motor_rotate_with_torque(int32_t direction, int32_t torque) { return err::koperation_not_support; }
@ -853,14 +877,13 @@ int32_t StepMotorCtrlModule::motor_read_pos(int32_t* pos) {
*pos = xnow;
return 0;
}
void StepMotorCtrlModule::set_last_exec_status(int32_t ecode, int32_t val0, int32_t val1, int32_t val2, int32_t val3, int32_t val4, int32_t val5) {
m_module_last_cmd_exec_status = ecode;
m_module_last_cmd_exec_val0 = val0;
m_module_last_cmd_exec_val1 = val1;
m_module_last_cmd_exec_val2 = val2;
m_module_last_cmd_exec_val3 = val3;
m_module_last_cmd_exec_val4 = val4;
m_module_last_cmd_exec_val5 = val5;
void StepMotorCtrlModule::set_last_exec_status(int32_t ecode, int32_t val0, int32_t val1, int32_t val2, int32_t val3, int32_t val4) {
m_com_reg.module_last_cmd_exec_status = ecode;
m_com_reg.module_last_cmd_exec_val0 = val0;
m_com_reg.module_last_cmd_exec_val1 = val1;
m_com_reg.module_last_cmd_exec_val2 = val2;
m_com_reg.module_last_cmd_exec_val3 = val3;
m_com_reg.module_last_cmd_exec_val4 = val4;
}
int32_t StepMotorCtrlModule::motor_calculated_pos_by_move_to_zero() {
@ -876,7 +899,7 @@ int32_t StepMotorCtrlModule::motor_calculated_pos_by_move_to_zero() {
if (erro != 0) {
set_last_exec_status(erro);
} else {
m_module_last_cmd_exec_status = erro;
m_com_reg.module_last_cmd_exec_status = erro;
set_last_exec_status(erro, dx + m_param.shift_x);
m_stepM1->setXACTUAL(0);
}
@ -894,9 +917,6 @@ int32_t StepMotorCtrlModule::motor_easy_rotate(int32_t direction) {
return 0;
};
// int32_t StepMotorCtrlModule::motor_move_by(int32_t dx, int32_t motor_velocity, int32_t acc) {
// int32_t StepMotorCtrlModule::motor_move_to(int32_t tox, int32_t motor_velocity, int32_t acc) {
int32_t StepMotorCtrlModule::motor_easy_move_by(int32_t distance) {
zlock_guard lock(m_lock);
ZLOGI(TAG, "m%d motor_easy_move_by %d", m_id, distance);

34
components/step_motor_ctrl_module/step_motor_ctrl_module.hpp

@ -6,6 +6,8 @@
#include "sdk\components\zprotocols\zcancmder\api\i_step_motor_ctrl_module.hpp"
namespace iflytop {
class StepMotorCtrlModule : public I_StepMotorCtrlModule, public ZIModule, public ZIMotor {
ENABLE_MODULE(StepMotorCtrlModule, kmotor_module, 0x0001);
public:
private:
IStepperMotor* m_stepM1;
@ -32,22 +34,14 @@ class StepMotorCtrlModule : public I_StepMotorCtrlModule, public ZIModule, publi
const char* m_flashmark = nullptr;
action_cb_status_t m_status_cb;
int32_t m_enable = 0;
int32_t m_module_last_cmd_exec_status = 0;
int32_t m_module_last_cmd_exec_val0 = 0;
int32_t m_module_last_cmd_exec_val1 = 0;
int32_t m_module_last_cmd_exec_val2 = 0;
int32_t m_module_last_cmd_exec_val3 = 0;
int32_t m_module_last_cmd_exec_val4 = 0;
int32_t m_module_last_cmd_exec_val5 = 0;
// int32_t m_enable = 0;
public:
void initialize(int moduleid, IStepperMotor* stepM, ZGPIO iotable[], int nio, const char* flashmark);
static void create_default_cfg(flash_config_t& cfg);
virtual bool isbusy() override;
virtual int32_t get_last_exec_status() override { return m_module_last_cmd_exec_status; };
virtual int32_t get_last_exec_status() override { return m_com_reg.module_last_cmd_exec_status; };
virtual int32_t move_to(int32_t tox, action_cb_status_t status_cb) override;
virtual int32_t move_by(int32_t dx, action_cb_status_t status_cb) override;
@ -93,20 +87,6 @@ class StepMotorCtrlModule : public I_StepMotorCtrlModule, public ZIModule, publi
virtual int32_t flush() override;
virtual int32_t factory_reset() override;
#if 0
virtual int32_t set_run_param(uint8_t operation, const run_param_t& param, run_param_t& ack) override;
// virtual int32_t set_run_to_zero_param(uint8_t operation, const run_to_zero_param_t& param, run_to_zero_param_t& ack) override;
virtual int32_t set_warning_limit_param(uint8_t operation, const warning_limit_param_t& param, warning_limit_param_t& ack) override;
int32_t read_run_param(run_param_t& param) { return set_run_param(kset_cmd_type_read, param, param); }
int32_t read_run_to_zero_param(run_to_zero_param_t& param) { return set_run_to_zero_param(kset_cmd_type_read, param, param); }
int32_t read_warning_limit_param(warning_limit_param_t& param) { return set_warning_limit_param(kset_cmd_type_read, param, param); }
int32_t set_run_param(run_param_t& param) { return set_run_param(kset_cmd_type_set, param, param); }
int32_t set_run_to_zero_param(run_to_zero_param_t& param) { return set_run_to_zero_param(kset_cmd_type_set, param, param); }
int32_t set_warning_limit_param(warning_limit_param_t& param) { return set_warning_limit_param(kset_cmd_type_set, param, param); }
#endif
int32_t do_motor_action_block_2(function<int32_t()> action, function<int32_t(bool&, int periodcount)> break_condition);
/*******************************************************************************
@ -190,9 +170,13 @@ class StepMotorCtrlModule : public I_StepMotorCtrlModule, public ZIModule, publi
int32_t _move_by(int32_t dx, action_cb_status_t status_cb);
void call_exec_status_cb(int32_t status, action_cb_status_t status_cb);
void set_last_exec_status(int32_t ecode, int32_t val0 = 0, int32_t val1 = 0, int32_t val2 = 0, int32_t val3 = 0, int32_t val4 = 0, int32_t val5 = 0);
void set_last_exec_status(int32_t ecode, int32_t val0 = 0, int32_t val1 = 0, int32_t val2 = 0, int32_t val3 = 0, int32_t val4 = 0);
private:
int32_t _read_io();
private:
int32_t module_xxx_reg(int32_t param_id, bool read, int32_t& val);
int32_t do_action(int32_t actioncode);
};
} // namespace iflytop

2
components/zprotocols/zcancmder

@ -1 +1 @@
Subproject commit ceb6729e4ee474a6ff170793202f3113b5838101
Subproject commit 6652d159d875cc4645ec045d05f0f9f8e906bcd1

2
components/zprotocols/zcancmder_v2

@ -1 +1 @@
Subproject commit 4b8745f224fb4891302e6984d94ed2673521eaa5
Subproject commit 5abdb1de50d15b2c6fc811da71cab6654b497e64
Loading…
Cancel
Save