Browse Source

update

master
zhaohe 1 year ago
parent
commit
4dec1cc348
  1. 26
      components/mini_servo_motor/mini_servo_motor_ctrl_module.hpp
  2. 18
      components/step_motor_ctrl_module/step_motor_ctrl_module.hpp
  3. 15
      components/step_motor_ctrl_module/step_motor_ctrl_module_v2.cpp
  4. 25
      components/step_motor_ctrl_module/step_motor_ctrl_module_v2.hpp
  5. 155
      components/zcancmder/zimodule_impl_v2.cpp
  6. 48
      components/zcancmder/zimodule_impl_v2.hpp
  7. 1
      components/zprotocols/zcancmder_v2/api/errorcode.hpp
  8. 36
      components/zprotocols/zcancmder_v2/api/reg_index.hpp
  9. 11
      components/zprotocols/zcancmder_v2/api/zi_module.hpp
  10. 39
      components/zprotocols/zcancmder_v2/api/zi_motor.hpp
  11. 70
      components/zprotocols/zcancmder_v2/cmdid.hpp
  12. 17
      components/zprotocols/zcancmder_v2/protocol_parser.cpp

26
components/mini_servo_motor/mini_servo_motor_ctrl_module.hpp

@ -77,19 +77,19 @@ class MiniRobotCtrlModule : public I_MiniServoModule, public ZIModuleImplV1, pub
*******************************************************************************/ *******************************************************************************/
virtual int32_t module_ping() { return 0; }; virtual int32_t module_ping() { return 0; };
virtual int32_t motor_enable(int32_t enable) override;
virtual int32_t motor_rotate(int32_t direction, int32_t motor_velocity, int32_t acc) override;
virtual int32_t motor_move_by(int32_t distance, int32_t motor_velocity, int32_t acc) override;
virtual int32_t motor_move_to(int32_t position, int32_t motor_velocity, int32_t acc) override;
virtual int32_t motor_rotate_with_torque(int32_t direction, int32_t torque) override;
virtual int32_t motor_move_to_torque(int32_t pos, int32_t torque, int32_t overtime) override;
virtual int32_t motor_rotate_acctime(int32_t direction, int32_t motor_velocity, int32_t acctime) override;
virtual int32_t motor_move_by_acctime(int32_t distance, int32_t motor_velocity, int32_t acctime) override;
virtual int32_t motor_move_to_acctime(int32_t position, int32_t motor_velocity, int32_t acctime) override;
virtual int32_t motor_move_to_zero_forward(int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime) override;
virtual int32_t motor_move_to_zero_backward(int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime) override;
virtual int32_t motor_enable(int32_t enable) ;
virtual int32_t motor_rotate(int32_t direction, int32_t motor_velocity, int32_t acc) ;
virtual int32_t motor_move_by(int32_t distance, int32_t motor_velocity, int32_t acc) ;
virtual int32_t motor_move_to(int32_t position, int32_t motor_velocity, int32_t acc) ;
virtual int32_t motor_rotate_with_torque(int32_t direction, int32_t torque) ;
virtual int32_t motor_move_to_torque(int32_t pos, int32_t torque, int32_t overtime) ;
virtual int32_t motor_rotate_acctime(int32_t direction, int32_t motor_velocity, int32_t acctime) ;
virtual int32_t motor_move_by_acctime(int32_t distance, int32_t motor_velocity, int32_t acctime) ;
virtual int32_t motor_move_to_acctime(int32_t position, int32_t motor_velocity, int32_t acctime) ;
virtual int32_t motor_move_to_zero_forward(int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime) ;
virtual int32_t motor_move_to_zero_backward(int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime) ;
virtual int32_t motor_read_pos(int32_t *pos); virtual int32_t motor_read_pos(int32_t *pos);

18
components/step_motor_ctrl_module/step_motor_ctrl_module.hpp

@ -80,7 +80,7 @@ class StepMotorCtrlModule : public ZIModuleImplV1, public ZIMotor {
static void create_default_cfg(flash_config_t& cfg); static void create_default_cfg(flash_config_t& cfg);
static uint32_t get_flash_cfg_size() { return sizeof(flash_config_t); } static uint32_t get_flash_cfg_size() { return sizeof(flash_config_t); }
virtual bool isbusy();
virtual bool isbusy();
virtual int32_t move_to_logic_point(int32_t logic_point_num, action_cb_status_t status_cb); virtual int32_t move_to_logic_point(int32_t logic_point_num, action_cb_status_t status_cb);
virtual int32_t set_logic_point(int logic_point_num, int32_t x, int32_t vel, int32_t acc, int32_t dec); virtual int32_t set_logic_point(int logic_point_num, int32_t x, int32_t vel, int32_t acc, int32_t dec);
@ -130,17 +130,19 @@ class StepMotorCtrlModule : public ZIModuleImplV1, public ZIMotor {
/******************************************************************************* /*******************************************************************************
* Motor * * Motor *
*******************************************************************************/ *******************************************************************************/
virtual int32_t motor_enable(int32_t enable) override;
virtual int32_t motor_rotate(int32_t direction, int32_t motor_velocity, int32_t acc) override;
virtual int32_t motor_move_by(int32_t distance, int32_t motor_velocity, int32_t acc) override;
virtual int32_t motor_move_to(int32_t position, int32_t motor_velocity, int32_t acc) override;
virtual int32_t motor_enable(int32_t enable);
virtual int32_t motor_rotate(int32_t direction, int32_t motor_velocity, int32_t acc);
virtual int32_t motor_move_by(int32_t distance, int32_t motor_velocity, int32_t acc);
virtual int32_t motor_move_to(int32_t position, int32_t motor_velocity, int32_t acc);
virtual int32_t motor_move_to_zero_backward(int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime) override;
virtual int32_t motor_read_pos(int32_t* pos) override;
virtual int32_t motor_move_to_zero_backward(int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime);
virtual int32_t motor_read_pos(int32_t* pos);
virtual int32_t motor_move_to_zero_backward_and_calculated_shift(int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime) override;
virtual int32_t motor_move_to_zero_backward_and_calculated_shift(int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime);
virtual int32_t motor_calculated_pos_by_move_to_zero() override; virtual int32_t motor_calculated_pos_by_move_to_zero() override;
virtual int32_t motor_easy_set_current_pos(int32_t pos) { return err::koperation_not_support; }
virtual int32_t motor_easy_rotate(int32_t direction) override; virtual int32_t motor_easy_rotate(int32_t direction) override;
virtual int32_t motor_easy_move_by(int32_t distance) override; virtual int32_t motor_easy_move_by(int32_t distance) override;
virtual int32_t motor_easy_move_to(int32_t position) override; virtual int32_t motor_easy_move_to(int32_t position) override;

15
components/step_motor_ctrl_module/step_motor_ctrl_module_v2.cpp

@ -0,0 +1,15 @@
#include "step_motor_ctrl_module_v2.hpp"
using namespace iflytop;
int32_t StepMotorCtrlModuleV2::module_stop() { return 0; }
int32_t StepMotorCtrlModuleV2::module_break() { return 0; }
int32_t StepMotorCtrlModuleV2::module_start() { return 0; }
int32_t StepMotorCtrlModuleV2::motor_easy_rotate(int32_t direction) { return 0; }
int32_t StepMotorCtrlModuleV2::motor_easy_move_by(int32_t distance) { return 0; }
int32_t StepMotorCtrlModuleV2::motor_easy_move_to(int32_t position) { return 0; }
int32_t StepMotorCtrlModuleV2::motor_easy_move_to_zero(int32_t direction) { return 0; }
int32_t StepMotorCtrlModuleV2::motor_easy_set_current_pos(int32_t pos) { return 0; }
int32_t StepMotorCtrlModuleV2::motor_easy_move_to_io(int32_t ioindex, int32_t direction) { return 0; }
int32_t StepMotorCtrlModuleV2::motor_calculated_pos_by_move_to_zero() { return 0; }

25
components/step_motor_ctrl_module/step_motor_ctrl_module_v2.hpp

@ -0,0 +1,25 @@
#pragma once
//
#include "sdk/os/zos.hpp"
#include "sdk\components\tmc\basic\tmc_ic_interface.hpp"
#include "sdk\components\zcancmder\zcanreceiver.hpp"
#include "sdk\components\zcancmder\zimodule_impl_v2.hpp"
namespace iflytop {
class StepMotorCtrlModuleV2 : public ZIModuleImplV2, public ZIMotor {
private:
IStepperMotor* m_stepM1;
public:
virtual int32_t module_stop();
virtual int32_t module_break();
virtual int32_t module_start();
virtual int32_t motor_easy_rotate(int32_t direction);
virtual int32_t motor_easy_move_by(int32_t distance);
virtual int32_t motor_easy_move_to(int32_t position);
virtual int32_t motor_easy_move_to_zero(int32_t direction);
virtual int32_t motor_easy_set_current_pos(int32_t pos);
virtual int32_t motor_easy_move_to_io(int32_t ioindex, int32_t direction);
virtual int32_t motor_calculated_pos_by_move_to_zero();
};
} // namespace iflytop

155
components/zcancmder/zimodule_impl_v2.cpp

@ -1,16 +1,15 @@
#include "zimodule_impl_v2.hpp" #include "zimodule_impl_v2.hpp"
#include <stdint.h> #include <stdint.h>
#include <stdio.h>
#include <functional> #include <functional>
#include "sdk/os/zos.hpp"
#include "sdk\components\zprotocols\zcancmder_v2\api\reg_index.hpp" #include "sdk\components\zprotocols\zcancmder_v2\api\reg_index.hpp"
#include "sdk\components\zprotocols\zcancmder_v2\api\zi_module.hpp" #include "sdk\components\zprotocols\zcancmder_v2\api\zi_module.hpp"
using namespace iflytop; using namespace iflytop;
ZIModuleImplV2::ZIModuleImplV2(int32_t id) { m_id = id; }
int32_t ZIModuleImplV2::getid(int32_t *id) { int32_t ZIModuleImplV2::getid(int32_t *id) {
*id = m_id; *id = m_id;
return 0; return 0;
@ -21,26 +20,150 @@ int32_t ZIModuleImplV2::module_get_status(int32_t *status) { return module_get_r
int32_t ZIModuleImplV2::module_get_error(int32_t *iserror) { return module_get_reg(kreg_module_errorcode, iserror); } int32_t ZIModuleImplV2::module_get_error(int32_t *iserror) { return module_get_reg(kreg_module_errorcode, iserror); }
int32_t ZIModuleImplV2::module_clear_error() { return module_set_reg(kreg_module_errorcode, 0); } int32_t ZIModuleImplV2::module_clear_error() { return module_set_reg(kreg_module_errorcode, 0); }
int32_t ZIModuleImplV2::module_enable(int32_t enable) { return module_set_reg(kreg_module_enableflag, enable); } int32_t ZIModuleImplV2::module_enable(int32_t enable) { return module_set_reg(kreg_module_enableflag, enable); }
// int32_t ZIModuleImplV2::module_readio(int32_t *io) { return module_get_reg(kreg_module_input_state, io); }
// int32_t ZIModuleImplV2::module_writeio(int32_t idindex, int32_t io) { return module_set_reg(kreg_module_output_state, io); }
int32_t ZIModuleImplV2::module_factory_reset() { return 0; } int32_t ZIModuleImplV2::module_factory_reset() { return 0; }
int32_t ZIModuleImplV2::module_flush_cfg() { return 0; } int32_t ZIModuleImplV2::module_flush_cfg() { return 0; }
int32_t ZIModuleImplV2::module_active_cfg() { return 0; } int32_t ZIModuleImplV2::module_active_cfg() { return 0; }
int32_t ZIModuleImplV2::module_readio(int32_t *io) { return module_get_reg(kreg_module_input_state, io); }
int32_t ZIModuleImplV2::module_writeio(int32_t idindex, int32_t io) { return module_set_reg(kreg_module_output_state, io); }
void ZIModuleImplV2::_initialize(int32_t moduleid, int32_t module_type, int32_t sf_version) {
m_id = moduleid;
m_regtable = NULL;
m_regNum = 0;
_addRegItem(kreg_module_version, sf_version, kreg_flag_ronly); // 模块版本
_addRegItem(kreg_module_type, module_type, kreg_flag_ronly); // 模块类型
_addRegItem(kreg_module_status, 0, kreg_flag_rw_limit, 0, 2); // 模块限制
_addRegItem(kreg_module_errorcode, 0, kreg_flag_rw); // 模块错误码
_addRegItem(kreg_module_initflag, 0, kreg_flag_rw); // 复位标志位,上电自动置0,上位机可以通过将这个寄存器置1,来判断单片机是否发生复位
_addRegItem(kreg_module_enableflag, 0, kreg_flag_rw); // 模块使能标志位,一般用于电机控制
_addRegItem(kreg_module_errorbitflag0, 0, kreg_flag_rw); // 详细的错误状态
_addRegItem(kreg_module_errorbitflag1, 0, kreg_flag_rw); // 详细的错误状态
_addRegItem(kreg_module_input_state, 0, kreg_flag_rw); // 输入IO状态
_addRegItem(kreg_module_output_state, 0, kreg_flag_rw); // 输出IO状态
_addRegItem(kreg_module_raw_sector_size, 0, kreg_flag_ronly); // 用于辅助module_read_raw方法
_addRegItem(kreg_module_raw_sector_num, 0, kreg_flag_ronly); // 用于辅助module_read_raw方法
_addRegItem(kreg_module_is_online, 0, kreg_flag_ronly); // 如果模块存在下属传感器,可以通过这个寄存器判断传感器是否在线
}
void ZIModuleImplV2::_regRegChangeListener(reg_operation_event_listener_t onregchange) { //
m_reg_operation_event_listener = onregchange;
}
void ZIModuleImplV2::_addRegItem(int32_t index, int32_t value, int32_t regflag, int32_t minval, int32_t maxval) {
reg_iterm_t *iterm = (reg_iterm_t *)realloc(m_regtable, sizeof(reg_iterm_t) * (m_regNum + 1));
ZASSERT(iterm != NULL);
iterm[m_regNum].index = index;
iterm[m_regNum].value = value;
iterm[m_regNum].flag = regflag;
iterm[m_regNum].minval = minval;
iterm[m_regNum].maxval = maxval;
m_regtable = iterm;
m_regNum++;
}
int32_t ZIModuleImplV2::module_set_reg(int32_t param_id, int32_t param_value) { int32_t ZIModuleImplV2::module_set_reg(int32_t param_id, int32_t param_value) {
int32_t retVal = 0;
// if (m_reg_change_listener) {
// m_reg_change_listener(param_id, param_value);
// }
return 0;
int32_t retVal = 0;
reg_iterm_t *regitem = _findreg(param_id);
if (regitem == NULL) {
return err::kreg_not_find_error;
}
if ((regitem->flag & kreg_flag_writeable) == 0) {
return err::koperation_not_support;
}
if ((regitem->flag & kreg_flag_limit) != 0) {
if (param_value < regitem->minval || param_value > regitem->maxval) {
return err::kparam_out_of_range;
}
}
if (m_reg_operation_event_listener) {
retVal = m_reg_operation_event_listener(kon_reg_write, param_id, param_value);
}
if (retVal == 0) {
return retVal;
}
regitem->value = param_value;
return 0;
} }
int32_t ZIModuleImplV2::module_get_reg(int32_t param_id, int32_t *param_value) { int32_t ZIModuleImplV2::module_get_reg(int32_t param_id, int32_t *param_value) {
reg_iterm_t *regitem = _findreg(param_id);
if (regitem == NULL) {
return err::kreg_not_find_error;
}
if ((regitem->flag & kreg_flag_readable) == 0) {
return err::koperation_not_support;
}
if (m_reg_operation_event_listener) {
int32_t retVal = m_reg_operation_event_listener(kon_reg_read, param_id, regitem->value);
if (retVal != 0) {
return retVal;
}
}
*param_value = regitem->value;
return 0;
}
int32_t ZIModuleImplV2::module_get_regbit(int32_t param_id, int32_t bitoffset, int32_t *param_value) {
int32_t regval = 0;
int32_t retVal = module_get_reg(param_id, &regval);
if (retVal != 0) {
return retVal;
}
*param_value = (regval >> bitoffset) & 0x01;
return 0;
}
int32_t ZIModuleImplV2::module_set_regbit(int32_t param_id, int32_t bitoffset, int32_t bitval) {
int32_t regval = 0;
int32_t retVal = _module_get_reg_internal(param_id, &regval);
if (retVal != 0) {
return retVal;
}
regval &= ~(0x01 << bitoffset);
regval |= (bitval & 0x01) << bitoffset;
return module_set_reg(param_id, regval);
}
int32_t ZIModuleImplV2::_module_set_reg_internal(int32_t index, int32_t value) {
reg_iterm_t *regitem = _findreg(index);
if (regitem == NULL) {
return err::kreg_not_find_error;
}
regitem->value = value;
return 0;
}
int32_t ZIModuleImplV2::_module_get_reg_internal(int32_t param_id, int32_t *param_value) {
reg_iterm_t *regitem = _findreg(param_id);
if (regitem == NULL) {
return err::kreg_not_find_error;
}
*param_value = regitem->value;
return 0;
} }
int32_t ZIModuleImplV2::module_get_regbit(int32_t param_id, int32_t bitoffset, int32_t *param_value) {}
int32_t ZIModuleImplV2::module_set_regbit(int32_t param_id, int32_t bitoffset, int32_t bitval) {}
void ZIModuleImplV2::_regRegChangeListener(reg_change_listener_t onregchange) { //
m_reg_change_listener = onregchange;
ZIModuleImplV2::reg_iterm_t *ZIModuleImplV2::_findreg(int32_t index) {
for (int i = 0; i < m_regNum; i++) {
if (m_regtable[i].index == index) {
return &m_regtable[i];
}
}
return NULL;
} }
void ZIModuleImplV2::_allocRegTable(int32_t regNum) {}

48
components/zcancmder/zimodule_impl_v2.hpp

@ -14,11 +14,26 @@ class ZIModuleImplV2 : public ZIModule {
/******************************************************************************* /*******************************************************************************
* * * *
*******************************************************************************/ *******************************************************************************/
typedef enum {
kidle = 0,
kbusy = 1,
kerror = 2,
} module_status_t;
typedef enum {
kreg_flag_writeable = 0x01,
kreg_flag_readable = 0x01 << 1,
kreg_flag_limit = 0x01 << 2,
kreg_flag_rw = kreg_flag_writeable | kreg_flag_readable,
kreg_flag_rw_limit = kreg_flag_writeable | kreg_flag_readable | kreg_flag_limit,
kreg_flag_ronly = kreg_flag_readable,
} reg_flag_t;
typedef struct { typedef struct {
int32_t index; int32_t index;
int32_t value; int32_t value;
// limit
bool enablelimit;
int32_t flag;
int32_t minval; int32_t minval;
int32_t maxval; int32_t maxval;
} reg_iterm_t; } reg_iterm_t;
@ -28,7 +43,7 @@ class ZIModuleImplV2 : public ZIModule {
kon_reg_read, kon_reg_read,
} reg_change_event_t; } reg_change_event_t;
typedef function<int32_t(reg_change_event_t event, int32_t index, int32_t &regval)> reg_change_listener_t;
typedef function<int32_t(reg_change_event_t event, int32_t index, int32_t &regval)> reg_operation_event_listener_t;
private: private:
/******************************************************************************* /*******************************************************************************
@ -38,16 +53,11 @@ class ZIModuleImplV2 : public ZIModule {
reg_iterm_t *m_regtable = NULL; reg_iterm_t *m_regtable = NULL;
int32_t m_regNum = 0; int32_t m_regNum = 0;
reg_iterm_t *m_internal_regtable = NULL;
int32_t m_internal_regNum = 0;
reg_change_listener_t m_reg_change_listener;
reg_operation_event_listener_t m_reg_operation_event_listener;
public: public:
virtual ~ZIModuleImplV2() {} virtual ~ZIModuleImplV2() {}
ZIModuleImplV2(int32_t id);
/******************************************************************************* /*******************************************************************************
* ZIModuleImpl * * ZIModuleImpl *
*******************************************************************************/ *******************************************************************************/
@ -63,24 +73,26 @@ class ZIModuleImplV2 : public ZIModule {
virtual int32_t module_set_reg(int32_t param_id, int32_t param_value) override final; virtual int32_t module_set_reg(int32_t param_id, int32_t param_value) override final;
virtual int32_t module_set_regbit(int32_t param_id, int32_t bitoffset, int32_t bitval) final; virtual int32_t module_set_regbit(int32_t param_id, int32_t bitoffset, int32_t bitval) final;
virtual int32_t module_get_reg(int32_t param_id, int32_t *param_value) final; virtual int32_t module_get_reg(int32_t param_id, int32_t *param_value) final;
virtual int32_t module_get_regbit(int32_t param_id, int32_t bitoffset, int32_t *param_value) final;
virtual int32_t module_get_regbit(int32_t param_id, int32_t bitoffset, int32_t *param_value) final;
virtual int32_t module_factory_reset() override final; virtual int32_t module_factory_reset() override final;
virtual int32_t module_flush_cfg() override final; virtual int32_t module_flush_cfg() override final;
virtual int32_t module_active_cfg() override final; virtual int32_t module_active_cfg() override final;
// virtual int32_t module_stop() = 0;
// virtual int32_t module_break() = 0;
// virtual int32_t module_start() = 0;
// virtual int32_t module_read_raw(int32_t index, uint8_t *data, int32_t *len) override final;
virtual int32_t module_readio(int32_t *io) override final;
virtual int32_t module_writeio(int32_t idindex, int32_t io) override final;
/******************************************************************************* /*******************************************************************************
* * * *
*******************************************************************************/ *******************************************************************************/
virtual void _initialize(int32_t moduleid, int32_t module_type, int32_t sf_version) final;
virtual void _regRegChangeListener(reg_operation_event_listener_t onregchange) final;
virtual void _addRegItem(int32_t index, int32_t value, //
int32_t regflag = (kreg_flag_writeable | kreg_flag_readable), int32_t minval = 0, int32_t maxval = 0) final;
virtual int32_t _module_set_reg_internal(int32_t index, int32_t value) final; // 模块内部调用设置寄存器,此方法不会任何限制
virtual int32_t _module_get_reg_internal(int32_t param_id, int32_t *param_value) final; // 模块内部调用设置寄存器,此方法不会任何限制
void _regRegChangeListener(reg_change_listener_t onregchange);
void _allocRegTable(int32_t regNum);
public:
private:
reg_iterm_t *_findreg(int32_t index);
}; };
} // namespace iflytop } // namespace iflytop

1
components/zprotocols/zcancmder_v2/api/errorcode.hpp

@ -27,6 +27,7 @@ typedef enum {
kcatch_exception = ERROR_CODE(0, 16), kcatch_exception = ERROR_CODE(0, 16),
khwardware_error_fan_error = ERROR_CODE(0, 17), khwardware_error_fan_error = ERROR_CODE(0, 17),
khwardware_error = ERROR_CODE(0, 18), khwardware_error = ERROR_CODE(0, 18),
kreg_not_find_error = ERROR_CODE(0, 19),
/** /**
* @brief * @brief

36
components/zprotocols/zcancmder_v2/api/reg_index.hpp

@ -9,20 +9,19 @@ typedef enum {
/******************************************************************************* /*******************************************************************************
* * * *
*******************************************************************************/ *******************************************************************************/
kreg_module_version = REG_INDEX(0, 0, 0), // 模块版本
kreg_module_type = REG_INDEX(0, 0, 1), // 模块类型
kreg_module_status = REG_INDEX(0, 0, 2), // 0idle,1busy,2error
kreg_module_errorcode = REG_INDEX(0, 0, 3), // inited_flag
kreg_module_initflag = REG_INDEX(0, 0, 4), // inited_flag
kreg_module_enableflag = REG_INDEX(0, 0, 5), //
kreg_module_errorbitflag0 = REG_INDEX(0, 0, 6), // 模块异常标志,bit,每个模块自定义
kreg_module_errorbitflag1 = REG_INDEX(0, 0, 7), //
kreg_module_input_state = REG_INDEX(0, 0, 8), //
kreg_module_output_state = REG_INDEX(0, 0, 9), //
kreg_module_raw_sector_size = REG_INDEX(0, 0, 10), // sector_size
kreg_module_raw_sector_num = REG_INDEX(0, 0, 11), //
kreg_module_is_online = REG_INDEX(0, 0, 12), //
kreg_module_version = REG_INDEX(0, 0, 0), // 模块版本
kreg_module_type = REG_INDEX(0, 0, 1), // 模块类型
kreg_module_status = REG_INDEX(0, 0, 2), // 0idle,1busy,2error
kreg_module_errorcode = REG_INDEX(0, 0, 3), // inited_flag
kreg_module_initflag = REG_INDEX(0, 0, 4), // inited_flag
kreg_module_enableflag = REG_INDEX(0, 0, 5), //
kreg_module_errorbitflag0 = REG_INDEX(0, 0, 6), // 模块异常标志,bit,每个模块自定义
kreg_module_errorbitflag1 = REG_INDEX(0, 0, 7), //
kreg_module_input_state = REG_INDEX(0, 0, 8), //
kreg_module_output_state = REG_INDEX(0, 0, 9), //
kreg_module_raw_sector_size = REG_INDEX(0, 0, 10), // sector_size
kreg_module_raw_sector_num = REG_INDEX(0, 0, 11), //
kreg_module_is_online = REG_INDEX(0, 0, 12), //
/******************************************************************************* /*******************************************************************************
* SENSOR * * SENSOR *
@ -125,10 +124,11 @@ typedef enum {
/******************************************************************************* /*******************************************************************************
* MOTOR_DEFAULT * * MOTOR_DEFAULT *
*******************************************************************************/ *******************************************************************************/
kreg_robot_move = REG_INDEX(10, 0, 0), // 机器人X是否在移动
kreg_robot_pos = REG_INDEX(10, 0, 1), // 机器人x坐标
kreg_robot_velocity = REG_INDEX(10, 0, 2), // 机器人x速度
kreg_robot_torque = REG_INDEX(10, 0, 3), // 机器人x电流
kreg_robot_move = REG_INDEX(10, 0, 0), // 机器人X是否在移动
kreg_robot_pos = REG_INDEX(10, 0, 1), // 机器人x坐标
kreg_robot_velocity = REG_INDEX(10, 0, 2), // 机器人x速度
kreg_robot_torque = REG_INDEX(10, 0, 3), // 机器人x电流
kreg_robot_last_cmd_dpos = REG_INDEX(10, 0, 4), // 机器人x上一条指令的相对位移
kreg_motor_shift = REG_INDEX(10, 50, 0), // x偏移 kreg_motor_shift = REG_INDEX(10, 50, 0), // x偏移
kreg_motor_shaft = REG_INDEX(10, 50, 1), // x轴是否反转 kreg_motor_shaft = REG_INDEX(10, 50, 1), // x轴是否反转

11
components/zprotocols/zcancmder_v2/api/zi_module.hpp

@ -16,22 +16,23 @@ class ZIModule {
virtual int32_t getid(int32_t *id) = 0; virtual int32_t getid(int32_t *id) = 0;
virtual int32_t getid() = 0; virtual int32_t getid() = 0;
virtual int32_t module_ping() = 0; virtual int32_t module_ping() = 0;
virtual int32_t module_stop() = 0;
virtual int32_t module_break() = 0;
virtual int32_t module_start() = 0;
virtual int32_t module_stop() = 0; // user impl
virtual int32_t module_break() = 0; // user impl
virtual int32_t module_start() = 0; // user impl
virtual int32_t module_get_status(int32_t *status) = 0; virtual int32_t module_get_status(int32_t *status) = 0;
virtual int32_t module_get_error(int32_t *iserror) = 0; virtual int32_t module_get_error(int32_t *iserror) = 0;
virtual int32_t module_clear_error() = 0; virtual int32_t module_clear_error() = 0;
virtual int32_t module_enable(int32_t enable) = 0; virtual int32_t module_enable(int32_t enable) = 0;
virtual int32_t module_set_reg(int32_t param_id, int32_t param_value) = 0; virtual int32_t module_set_reg(int32_t param_id, int32_t param_value) = 0;
virtual int32_t module_get_reg(int32_t param_id, int32_t *param_value) = 0; virtual int32_t module_get_reg(int32_t param_id, int32_t *param_value) = 0;
virtual int32_t module_readio(int32_t *io) = 0;
virtual int32_t module_writeio(int32_t idindex, int32_t io) = 0;
virtual int32_t module_readio(int32_t *io) = 0; // ¼´½«¶ªÆú
virtual int32_t module_writeio(int32_t idindex, int32_t io) = 0; // ¼´½«¶ªÆú
virtual int32_t module_read_adc(int32_t adcindex, int32_t *adc) = 0; virtual int32_t module_read_adc(int32_t adcindex, int32_t *adc) = 0;
virtual int32_t module_read_raw(int32_t index, uint8_t *data, int32_t *len) = 0; virtual int32_t module_read_raw(int32_t index, uint8_t *data, int32_t *len) = 0;
virtual int32_t module_factory_reset() = 0; virtual int32_t module_factory_reset() = 0;
virtual int32_t module_flush_cfg() = 0; virtual int32_t module_flush_cfg() = 0;
virtual int32_t module_active_cfg() = 0; virtual int32_t module_active_cfg() = 0;
public: public:
}; };
} // namespace iflytop } // namespace iflytop

39
components/zprotocols/zcancmder_v2/api/zi_motor.hpp

@ -10,39 +10,12 @@ using namespace std;
class ZIMotor { class ZIMotor {
public: public:
virtual ~ZIMotor() {} virtual ~ZIMotor() {}
virtual int32_t motor_enable(int32_t enable) { return err::koperation_not_support; }
virtual int32_t motor_rotate(int32_t direction, int32_t motor_velocity, int32_t acc) { return err::koperation_not_support; }
virtual int32_t motor_move_by(int32_t distance, int32_t motor_velocity, int32_t acc) { return err::koperation_not_support; }
virtual int32_t motor_move_to(int32_t position, int32_t motor_velocity, int32_t acc) { return err::koperation_not_support; }
virtual int32_t motor_rotate_acctime(int32_t direction, int32_t motor_velocity, int32_t acctime) { return err::koperation_not_support; }
virtual int32_t motor_move_by_acctime(int32_t distance, int32_t motor_velocity, int32_t acctime) { return err::koperation_not_support; }
virtual int32_t motor_move_to_acctime(int32_t position, int32_t motor_velocity, int32_t acctime) { return err::koperation_not_support; }
virtual int32_t motor_rotate_with_torque(int32_t direction, int32_t torque) { return err::koperation_not_support; }
virtual int32_t motor_move_to_torque(int32_t pos, int32_t torque, int32_t overtime) { return err::koperation_not_support; }
virtual int32_t motor_move_to_zero_forward(int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime) { return err::koperation_not_support; }
virtual int32_t motor_move_to_zero_backward(int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime) { return err::koperation_not_support; }
virtual int32_t motor_move_to_zero_forward_and_calculated_shift(int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime) { return err::koperation_not_support; }
virtual int32_t motor_move_to_zero_backward_and_calculated_shift(int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime) { return err::koperation_not_support; }
virtual int32_t motor_easy_rotate(int32_t direction) { return err::koperation_not_support; }
virtual int32_t motor_easy_move_by(int32_t distance) { return err::koperation_not_support; }
virtual int32_t motor_easy_move_to(int32_t position) { return err::koperation_not_support; }
virtual int32_t motor_easy_move_to_zero(int32_t direction) { return err::koperation_not_support; }
virtual int32_t motor_easy_set_current_pos(int32_t pos) { return err::koperation_not_support; }
virtual int32_t motor_easy_move_to_io(int32_t ioindex, int32_t direction) { return err::koperation_not_support; }
virtual int32_t motor_calculated_pos_by_move_to_zero() { return err::koperation_not_support; } virtual int32_t motor_calculated_pos_by_move_to_zero() { return err::koperation_not_support; }
virtual int32_t motor_read_pos(int32_t* pos) { return err::koperation_not_support; }
virtual int32_t motor_set_current_pos_by_change_shift(int32_t pos) { return err::koperation_not_support; } // Ò»°ãÓÃÓÚ¶æ»ú
virtual int32_t motor_easy_rotate(int32_t direction) { return err::koperation_not_support; };
virtual int32_t motor_easy_move_by(int32_t distance) { return err::koperation_not_support; };
virtual int32_t motor_easy_move_to(int32_t position) { return err::koperation_not_support; };
virtual int32_t motor_easy_move_to_zero(int32_t direction) { return err::koperation_not_support; };
virtual int32_t motor_easy_set_current_pos(int32_t pos) { return err::koperation_not_support; };
virtual int32_t motor_easy_move_to_io(int32_t ioindex, int32_t direction) { return err::koperation_not_support; };
// virtual int32_t motor_set_shaft();
// s32 pos, s32 speed, s32 torque,
}; };
} // namespace iflytop } // namespace iflytop

70
components/zprotocols/zcancmder_v2/cmdid.hpp

@ -4,57 +4,41 @@
namespace iflytop { namespace iflytop {
namespace zcr { namespace zcr {
typedef enum { typedef enum {
kboard_reset = CMDID(0, 0), // para:{}, ack:{}
kboard_reset = CMDID(0, 0), // para:{}, ack:{}
kevent_bus_reg_change_report = CMDID(0, 100), // para:{}, ack:{} kevent_bus_reg_change_report = CMDID(0, 100), // para:{}, ack:{}
/******************************************************************************* /*******************************************************************************
* MODULE_PUBLIC_CMD * * MODULE_PUBLIC_CMD *
*******************************************************************************/ *******************************************************************************/
kmodule_ping = CMDID(1, 0), // para:{}, ack:{}
kmodule_stop = CMDID(1, 1), // para:{}, ack:{}
kmodule_break = CMDID(1, 2), // para:{}, ack:{}
kmodule_get_status = CMDID(1, 4), // para:{}, ack:{4}
kmodule_set_reg = CMDID(1, 5), // para:{4,4}, ack:{}
kmodule_get_reg = CMDID(1, 6), // para:{4}, ack:{4}I
kmodule_readio = CMDID(1, 7), // para:{}, ack:{4}
kmodule_writeio = CMDID(1, 8), // para:{4}, ack:{}
kmodule_read_adc = CMDID(1, 9), // para:{4}, ack:{4}
kmodule_get_error = CMDID(1, 10), // para:{}, ack:{1}
kmodule_clear_error = CMDID(1, 11), // para:{}, ack:{}
kmodule_set_inited_flag = CMDID(1, 12), // para:{4}, ack:{}
kmodule_get_inited_flag = CMDID(1, 13), // para:{}, ack:{4}
kmodule_factory_reset = CMDID(1, 14), // para:{}, ack:{}
kmodule_flush_cfg = CMDID(1, 15), // para:{}, ack:{}
kmodule_active_cfg = CMDID(1, 16), // para:{}, ack:{}
kmodule_read_raw = CMDID(1, 19), // para:{4,4}, ack:{4}
kmodule_enable = CMDID(1, 20), // para:{4}, ack:{}
kmodule_start = CMDID(1, 21), // para:{4}, ack:{}
kmodule_ping = CMDID(1, 0), // para:{}, ack:{}
kmodule_stop = CMDID(1, 1), // para:{}, ack:{}
kmodule_break = CMDID(1, 2), // para:{}, ack:{}
kmodule_get_status = CMDID(1, 4), // para:{}, ack:{4}
kmodule_set_reg = CMDID(1, 5), // para:{4,4}, ack:{}
kmodule_get_reg = CMDID(1, 6), // para:{4}, ack:{4}I
kmodule_readio = CMDID(1, 7), // para:{}, ack:{4}
kmodule_writeio = CMDID(1, 8), // para:{4}, ack:{}
kmodule_read_adc = CMDID(1, 9), // para:{4}, ack:{4}
kmodule_get_error = CMDID(1, 10), // para:{}, ack:{1}
kmodule_clear_error = CMDID(1, 11), // para:{}, ack:{}
kmodule_set_inited_flag = CMDID(1, 12), // para:{4}, ack:{}
kmodule_get_inited_flag = CMDID(1, 13), // para:{}, ack:{4}
kmodule_factory_reset = CMDID(1, 14), // para:{}, ack:{}
kmodule_flush_cfg = CMDID(1, 15), // para:{}, ack:{}
kmodule_active_cfg = CMDID(1, 16), // para:{}, ack:{}
kmodule_read_raw = CMDID(1, 19), // para:{4,4}, ack:{4}
kmodule_enable = CMDID(1, 20), // para:{4}, ack:{}
kmodule_start = CMDID(1, 21), // para:{4}, ack:{}
/******************************************************************************* /*******************************************************************************
* MOTOR_CTRL * * MOTOR_CTRL *
*******************************************************************************/ *******************************************************************************/
kmotor_enable = CMDID(2, 1), // para:{1}, ack:{}
kmotor_rotate = CMDID(2, 2), // para:{1,4}, ack:{}
kmotor_move_by = CMDID(2, 3), // para:{4,4}, ack:{}
kmotor_move_to = CMDID(2, 4), // para:{4,4}, ack:{}
kmotor_rotate_acctime = CMDID(2, 5), // para:{4,4}, ack:{}
kmotor_move_by_acctime = CMDID(2, 6), // para:{4,4}, ack:{}
kmotor_move_to_acctime = CMDID(2, 7), // para:{4,4}, ack:{}
kmotor_rotate_with_torque = CMDID(2, 8), // para:{4,4}, ack:{}
kmotor_move_to_zero_forward = CMDID(2, 9), // para:{4,4,4,4}, ack:{} //int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime
kmotor_move_to_zero_backward = CMDID(2, 10), // para:{4,4,4,4}, ack:{} //int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime
kmotor_read_pos = CMDID(2, 11), // para:{}, ack:{4}
kmotor_set_current_pos_by_change_shift = CMDID(2, 12), // para:{4}, ack:{}
kmotor_motor_move_to_zero_forward_and_calculated_shift = CMDID(2, 13), // para:{4,4,4,4}, ack:{} //int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime
kmotor_motor_move_to_zero_backward_and_calculated_shift = CMDID(2, 14), // para:{4,4,4,4}, ack:{} //int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime
kmotor_move_to_torque = CMDID(2, 15), // para:{4,4,4}, ack:{}
kmotor_calculated_pos_by_move_to_zero = CMDID(2, 16), // para:{}, ack:{}
kmotor_easy_rotate = CMDID(2, 17), // para:{4}, ack:{}
kmotor_easy_move_by = CMDID(2, 18), // para:{4}, ack:{}
kmotor_easy_move_to = CMDID(2, 19), // para:{4}, ack:{}
kmotor_easy_move_to_zero = CMDID(2, 20), // para:{1}, ack:{}
kmotor_easy_set_current_pos = CMDID(2, 21), // para:{4}, ack:{}
kmotor_easy_move_to_io = CMDID(2, 22), // para:{4,4}, ack:{}
kmotor_calculated_pos_by_move_to_zero = CMDID(2, 16), // para:{}, ack:{}
kmotor_easy_rotate = CMDID(2, 17), // para:{4}, ack:{}
kmotor_easy_move_by = CMDID(2, 18), // para:{4}, ack:{}
kmotor_easy_move_to = CMDID(2, 19), // para:{4}, ack:{}
kmotor_easy_move_to_zero = CMDID(2, 20), // para:{1}, ack:{}
kmotor_easy_set_current_pos = CMDID(2, 21), // para:{4}, ack:{}
kmotor_easy_move_to_io = CMDID(2, 22), // para:{4,4}, ack:{}
/******************************************************************************* /*******************************************************************************
* XYMOTOR * * XYMOTOR *

17
components/zprotocols/zcancmder_v2/protocol_parser.cpp

@ -112,7 +112,6 @@ void ZIProtocolParser::onRceivePacket(zcr_cmd_header_t* rxcmd, uint8_t* data, in
/******************************************************************************* /*******************************************************************************
* module * * module *
*******************************************************************************/ *******************************************************************************/
PROCESS_PACKET_00(kmodule_ping, ZIModule, module_ping); PROCESS_PACKET_00(kmodule_ping, ZIModule, module_ping);
PROCESS_PACKET_00(kmodule_stop, ZIModule, module_stop); PROCESS_PACKET_00(kmodule_stop, ZIModule, module_stop);
PROCESS_PACKET_00(kmodule_break, ZIModule, module_break); PROCESS_PACKET_00(kmodule_break, ZIModule, module_break);
@ -131,22 +130,6 @@ void ZIProtocolParser::onRceivePacket(zcr_cmd_header_t* rxcmd, uint8_t* data, in
PROCESS_PACKET_10(kmodule_enable, ZIModule, module_enable); PROCESS_PACKET_10(kmodule_enable, ZIModule, module_enable);
PROCESS_PACKET_00(kmodule_start, ZIModule, module_start); PROCESS_PACKET_00(kmodule_start, ZIModule, module_start);
PROCESS_PACKET_10(kmotor_enable, ZIMotor, motor_enable);
PROCESS_PACKET_30(kmotor_rotate, ZIMotor, motor_rotate);
PROCESS_PACKET_30(kmotor_move_by, ZIMotor, motor_move_by);
PROCESS_PACKET_30(kmotor_move_to, ZIMotor, motor_move_to);
PROCESS_PACKET_20(kmotor_rotate_with_torque, ZIMotor, motor_rotate_with_torque);
PROCESS_PACKET_30(kmotor_rotate_acctime, ZIMotor, motor_rotate_acctime);
PROCESS_PACKET_30(kmotor_move_by_acctime, ZIMotor, motor_move_by_acctime);
PROCESS_PACKET_30(kmotor_move_to_acctime, ZIMotor, motor_move_to_acctime);
PROCESS_PACKET_40(kmotor_move_to_zero_forward, ZIMotor, motor_move_to_zero_forward);
PROCESS_PACKET_40(kmotor_move_to_zero_backward, ZIMotor, motor_move_to_zero_backward);
PROCESS_PACKET_01(kmotor_read_pos, ZIMotor, motor_read_pos);
PROCESS_PACKET_10(kmotor_set_current_pos_by_change_shift, ZIMotor, motor_set_current_pos_by_change_shift);
PROCESS_PACKET_40(kmotor_motor_move_to_zero_forward_and_calculated_shift, ZIMotor, motor_move_to_zero_forward_and_calculated_shift);
PROCESS_PACKET_40(kmotor_motor_move_to_zero_backward_and_calculated_shift, ZIMotor, motor_move_to_zero_backward_and_calculated_shift);
PROCESS_PACKET_30(kmotor_move_to_torque, ZIMotor, motor_move_to_torque);
PROCESS_PACKET_00(kmotor_calculated_pos_by_move_to_zero, ZIMotor, motor_calculated_pos_by_move_to_zero); PROCESS_PACKET_00(kmotor_calculated_pos_by_move_to_zero, ZIMotor, motor_calculated_pos_by_move_to_zero);
PROCESS_PACKET_10(kmotor_easy_rotate, ZIMotor, motor_easy_rotate); PROCESS_PACKET_10(kmotor_easy_rotate, ZIMotor, motor_easy_rotate);
PROCESS_PACKET_10(kmotor_easy_move_by, ZIMotor, motor_easy_move_by); PROCESS_PACKET_10(kmotor_easy_move_by, ZIMotor, motor_easy_move_by);

Loading…
Cancel
Save