19 changed files with 0 additions and 944 deletions
-
14protocol/api/api.hpp
-
14protocol/api/apibasic/basic.hpp
-
70protocol/api/apibasic/cmdid.cpp
-
90protocol/api/apibasic/cmdid.hpp
-
61protocol/api/apibasic/errorcode.cpp
-
72protocol/api/apibasic/errorcode.hpp
-
13protocol/api/apibasic/module_type_index.hpp
-
31protocol/api/apibasic/packet_interface.hpp
-
1protocol/api/apibasic/protocol_constant.hpp
-
78protocol/api/apibasic/reg_index.cpp
-
78protocol/api/apibasic/reg_index.hpp
-
20protocol/api/zi_board.hpp
-
14protocol/api/zi_event_bus.hpp
-
26protocol/api/zi_mini_servo.hpp
-
96protocol/api/zi_module.cpp
-
83protocol/api/zi_module.hpp
-
154protocol/api/zi_motor.hpp
-
24protocol/i_zcanreceiver.hpp
-
5protocol/protocol.hpp
@ -1,14 +0,0 @@ |
|||
#pragma once
|
|||
#include "apibasic/basic.hpp"
|
|||
|
|||
//
|
|||
#include "zi_module.hpp"
|
|||
//
|
|||
#include "zi_motor.hpp"
|
|||
|
|||
//
|
|||
#include "zi_event_bus.hpp"
|
|||
|
|||
#include "zi_mini_servo.hpp"
|
|||
//
|
|||
#include "zi_board.hpp"
|
@ -1,14 +0,0 @@ |
|||
#pragma once
|
|||
|
|||
#include "cmdid.hpp"
|
|||
//
|
|||
#include "errorcode.hpp"
|
|||
//
|
|||
#include "packet_interface.hpp"
|
|||
//
|
|||
#include "module_type_index.hpp"
|
|||
//
|
|||
#include "protocol_constant.hpp"
|
|||
//
|
|||
#include "reg_index.hpp"
|
|||
//
|
@ -1,70 +0,0 @@ |
|||
#include "cmdid.hpp"
|
|||
|
|||
#include <stdint.h>
|
|||
namespace iflytop { |
|||
namespace zcr { |
|||
|
|||
#define CMD_ITERM(enum) \
|
|||
{ enum, #enum } |
|||
|
|||
static cmdinfo_t table[] = { |
|||
CMD_ITERM(kboard_reset), |
|||
|
|||
CMD_ITERM(kevent_bus_reg_change_report), |
|||
|
|||
CMD_ITERM(kmodule_ping), |
|||
CMD_ITERM(kmodule_get_status), |
|||
CMD_ITERM(kmodule_stop), |
|||
CMD_ITERM(kmodule_set_reg), |
|||
CMD_ITERM(kmodule_get_reg), |
|||
CMD_ITERM(kmodule_get_error), |
|||
CMD_ITERM(kmodule_clear_error), |
|||
CMD_ITERM(kmodule_active_cfg), |
|||
|
|||
CMD_ITERM(kstep_motor_enable), |
|||
CMD_ITERM(kstep_motor_read_pos), |
|||
CMD_ITERM(kstep_motor_easy_rotate), |
|||
CMD_ITERM(kstep_motor_easy_move_by), |
|||
CMD_ITERM(kstep_motor_easy_move_to), |
|||
CMD_ITERM(kstep_motor_easy_move_to_zero), |
|||
CMD_ITERM(kstep_motor_easy_move_to_end_point), |
|||
CMD_ITERM(kstep_motor_easy_set_current_pos), |
|||
CMD_ITERM(kstep_motor_easy_move_to_io), |
|||
CMD_ITERM(kstep_motor_active_cfg), |
|||
CMD_ITERM(kstep_motor_stop), |
|||
CMD_ITERM(kstep_motor_read_io_state), |
|||
|
|||
CMD_ITERM(kmini_servo_enable), |
|||
CMD_ITERM(kmini_servo_read_pos), |
|||
CMD_ITERM(kmini_servo_active_cfg), |
|||
CMD_ITERM(kmini_servo_stop), |
|||
CMD_ITERM(kmini_servo_set_mid_point), |
|||
CMD_ITERM(kmini_servo_read_io_state), |
|||
|
|||
CMD_ITERM(kmini_servo_move_to), |
|||
CMD_ITERM(kmini_servo_rotate), |
|||
CMD_ITERM(kmini_servo_rotate_with_torque), |
|||
|
|||
CMD_ITERM(kextboard_read_inio), |
|||
CMD_ITERM(kextboard_write_outio), |
|||
CMD_ITERM(kextboard_read_muti_inio), |
|||
CMD_ITERM(kextboard_read_inio_index_in_stm32), |
|||
CMD_ITERM(kextboard_read_outio_index_in_stm32), |
|||
CMD_ITERM(kextboard_read_outio), |
|||
|
|||
|
|||
}; |
|||
|
|||
const char* cmdid2str(int32_t code) { |
|||
for (int i = 0; i < sizeof(table) / sizeof(table[0]); i++) { |
|||
if (table[i].index == code) { |
|||
return table[i].fnname; |
|||
} |
|||
} |
|||
return "unknown_cmd"; |
|||
} |
|||
cmdinfo_t* cmdid_get_table() { return table; } |
|||
int cmdid_get_table_size() { return sizeof(table) / sizeof(table[0]); } |
|||
|
|||
} // namespace zcr
|
|||
} // namespace iflytop
|
@ -1,90 +0,0 @@ |
|||
#pragma once
|
|||
#include <stdint.h>
|
|||
|
|||
#define CMDID(cmdid, cmdSubId) ((cmdid << 8) + cmdSubId)
|
|||
|
|||
#define NEW_CMDID(cmdid, cmdSubId) ((cmdid * 100) + cmdSubId)
|
|||
|
|||
namespace iflytop { |
|||
namespace zcr { |
|||
typedef enum { |
|||
#if 0
|
|||
|
|||
virtual int32_t board_reset() = 0; |
|||
#endif
|
|||
|
|||
kboard_reset = CMDID(0, 0), // para:{}, ack:{}
|
|||
|
|||
kevent_bus_reg_change_report = CMDID(0, 100), // val{regindex, oldval, toval}
|
|||
|
|||
kmodule_ping = CMDID(1, 0), |
|||
kmodule_get_status = CMDID(1, 4), |
|||
kmodule_stop = CMDID(1, 1), |
|||
kmodule_set_reg = CMDID(1, 5), |
|||
kmodule_get_reg = CMDID(1, 6), |
|||
kmodule_get_error = CMDID(1, 10), |
|||
kmodule_clear_error = CMDID(1, 11), |
|||
kmodule_active_cfg = CMDID(1, 16), |
|||
|
|||
/***********************************************************************************************************************
|
|||
* STEP_MOTOR * |
|||
***********************************************************************************************************************/ |
|||
|
|||
kstep_motor_enable = CMDID(2, 1), // para:{1}, ack:{}
|
|||
kstep_motor_read_pos = CMDID(2, 11), // para:{}, ack:{4}
|
|||
kstep_motor_easy_rotate = CMDID(2, 17), // para:{4}, ack:{}
|
|||
kstep_motor_easy_move_by = CMDID(2, 18), // para:{4}, ack:{}
|
|||
kstep_motor_easy_move_to = CMDID(2, 19), // para:{4}, ack:{}
|
|||
kstep_motor_easy_move_to_zero = CMDID(2, 20), // para:{1}, ack:{}
|
|||
kstep_motor_easy_set_current_pos = CMDID(2, 21), // para:{4}, ack:{}
|
|||
kstep_motor_easy_move_to_io = CMDID(2, 22), // para:{4,4}, ack:{}
|
|||
kstep_motor_stop = CMDID(2, 40), // para:{4}, ack:{}
|
|||
kstep_motor_active_cfg = CMDID(2, 41), // para:{4}, ack:{}
|
|||
kstep_motor_read_io_state = CMDID(2, 42), // para:{4}, ack:{}
|
|||
kstep_motor_easy_move_to_end_point = CMDID(2, 44), //
|
|||
|
|||
kstep_motor_read_tmc5130_status = CMDID(2, 50), //
|
|||
kstep_motor_read_tmc5130_state = CMDID(2, 51), // 调试使用
|
|||
kstep_motor_read_tmc4361a_status = CMDID(2, 52), // 调试使用
|
|||
kstep_motor_read_tmc4361a_state = CMDID(2, 53), // 调试使用
|
|||
kstep_motor_read_tmc2160_status = CMDID(2, 54), // 调试使用
|
|||
kstep_motor_read_tmc2160_state = CMDID(2, 55), // 调试使用
|
|||
kstep_motor_read_io_index_in_stm32 = CMDID(2, 56), // 调试使用
|
|||
|
|||
/***********************************************************************************************************************
|
|||
* MINI_SERVO * |
|||
***********************************************************************************************************************/ |
|||
kmini_servo_enable = CMDID(102, 1), |
|||
kmini_servo_read_pos = CMDID(102, 2), |
|||
kmini_servo_active_cfg = CMDID(102, 3), |
|||
kmini_servo_stop = CMDID(102, 4), |
|||
kmini_servo_set_mid_point = CMDID(102, 7), |
|||
kmini_servo_read_io_state = CMDID(102, 8), |
|||
|
|||
kmini_servo_move_to = CMDID(102, 9), |
|||
kmini_servo_rotate = CMDID(102, 10), |
|||
kmini_servo_rotate_with_torque = CMDID(102, 11), |
|||
|
|||
/***********************************************************************************************************************
|
|||
* BOARD * |
|||
***********************************************************************************************************************/ |
|||
kextboard_read_inio = CMDID(103, 1), // para:{index}, ack:{state}
|
|||
kextboard_write_outio = CMDID(103, 2), // para:{index,state}, ack:{}
|
|||
kextboard_read_muti_inio = CMDID(103, 3), // para:{}, ack:{states}
|
|||
kextboard_read_inio_index_in_stm32 = CMDID(103, 4), // para:{index}, ack:{index_in_stm32}
|
|||
kextboard_read_outio_index_in_stm32 = CMDID(103, 5), // para:{index}, ack:{index_in_stm32}
|
|||
kextboard_read_outio = CMDID(103, 6), // para:{index}, ack:{state}
|
|||
|
|||
} cmdid_t; |
|||
|
|||
typedef struct { |
|||
int index; |
|||
const char* fnname; |
|||
} cmdinfo_t; |
|||
|
|||
const char* cmdid2str(int32_t code); |
|||
cmdinfo_t* cmdid_get_table(); |
|||
int cmdid_get_table_size(); |
|||
|
|||
} // namespace zcr
|
|||
} // namespace iflytop
|
@ -1,61 +0,0 @@ |
|||
#include "errorcode.hpp"
|
|||
|
|||
#define ERR2STR(code) \
|
|||
case code: \ |
|||
return #code; |
|||
|
|||
namespace iflytop { |
|||
namespace err { |
|||
|
|||
#define ERR_ITERM(enum) \
|
|||
{ enum, #enum } |
|||
|
|||
static ecode_table_item_t table[] = { |
|||
|
|||
ERR_ITERM(ksucc), |
|||
ERR_ITERM(kfail), |
|||
ERR_ITERM(kparam_out_of_range), |
|||
ERR_ITERM(kcmd_not_support), |
|||
ERR_ITERM(kdevice_is_busy), |
|||
ERR_ITERM(kdevice_is_offline), |
|||
ERR_ITERM(kovertime), |
|||
ERR_ITERM(knoack), |
|||
ERR_ITERM(kerrorack), |
|||
ERR_ITERM(kdevice_offline), |
|||
ERR_ITERM(ksubdevice_overtime), |
|||
ERR_ITERM(kbuffer_not_enough), |
|||
ERR_ITERM(kcmd_param_num_error), |
|||
ERR_ITERM(kcheckcode_is_error), |
|||
ERR_ITERM(kmodule_opeation_break_by_user), |
|||
ERR_ITERM(kmodule_not_find_reg), |
|||
ERR_ITERM(kstep_motor_not_found_zero_point), |
|||
ERR_ITERM(kstep_motor_not_go_zero), |
|||
ERR_ITERM(kstep_motor_over_temperature), |
|||
ERR_ITERM(kstep_motor_over_voltage), |
|||
ERR_ITERM(kstep_motor_run_overtime), |
|||
ERR_ITERM(kstep_motor_not_enable), |
|||
ERR_ITERM(kstep_motor_ioindex_out_of_range), |
|||
ERR_ITERM(kstep_motor_subic_reset), |
|||
ERR_ITERM(kstep_motor_drv_err), |
|||
ERR_ITERM(kstep_motor_uv_cp), |
|||
ERR_ITERM(kstep_motor_not_found_point_edge), |
|||
ERR_ITERM(kmini_servo_not_enable), |
|||
ERR_ITERM(kmini_servo_mode_not_support), |
|||
|
|||
|
|||
}; |
|||
|
|||
const char* error2str(int32_t code) { |
|||
for (int i = 0; i < sizeof(table) / sizeof(table[0]); i++) { |
|||
if (table[i].index == code) { |
|||
return table[i].info; |
|||
} |
|||
} |
|||
return "unknown error"; |
|||
} |
|||
|
|||
ecode_table_item_t* error_get_table() { return table; } |
|||
int error_get_table_size() { return sizeof(table) / sizeof(table[0]); } |
|||
|
|||
} // namespace err
|
|||
} // namespace iflytop
|
@ -1,72 +0,0 @@ |
|||
#pragma once
|
|||
#include <stdint.h>
|
|||
|
|||
namespace iflytop { |
|||
namespace err { |
|||
using namespace std; |
|||
|
|||
#define ERROR_CODE(errortype, suberrorcode) (errortype + suberrorcode)
|
|||
|
|||
typedef enum { |
|||
|
|||
ksucc = ERROR_CODE(0, 0), |
|||
kfail = ERROR_CODE(0, 1), |
|||
/***********************************************************************************************************************
|
|||
* 协议错误码 * |
|||
***********************************************************************************************************************/ |
|||
kparam_out_of_range = ERROR_CODE(100, 2), // 参数超出范围
|
|||
kcmd_not_support = ERROR_CODE(100, 3), // 操作不支持
|
|||
kdevice_is_busy = ERROR_CODE(100, 4), // 设备忙
|
|||
kdevice_is_offline = ERROR_CODE(100, 5), // 设备离线
|
|||
kovertime = ERROR_CODE(100, 6), |
|||
knoack = ERROR_CODE(100, 7), |
|||
kerrorack = ERROR_CODE(100, 8), |
|||
kdevice_offline = ERROR_CODE(100, 9), |
|||
ksubdevice_overtime = ERROR_CODE(100, 11), |
|||
kbuffer_not_enough = ERROR_CODE(100, 12), |
|||
kcmd_param_num_error = ERROR_CODE(100, 14), |
|||
kcheckcode_is_error = ERROR_CODE(100, 15), |
|||
|
|||
/***********************************************************************************************************************
|
|||
* 模块错误码 * |
|||
***********************************************************************************************************************/ |
|||
kmodule_opeation_break_by_user = ERROR_CODE(200, 2), // 用户中断
|
|||
kmodule_not_find_reg = ERROR_CODE(200, 7), // 未找到配置索引
|
|||
|
|||
|
|||
/***********************************************************************************************************************
|
|||
* 步进电机错误码 * |
|||
***********************************************************************************************************************/ |
|||
kstep_motor_not_found_zero_point = ERROR_CODE(600, 0), // 未找到零点
|
|||
kstep_motor_not_go_zero = ERROR_CODE(600, 1), // 设备未归零
|
|||
kstep_motor_over_temperature = ERROR_CODE(600, 2), // 过温
|
|||
kstep_motor_over_voltage = ERROR_CODE(600, 3), // 过压
|
|||
kstep_motor_run_overtime = ERROR_CODE(600, 4), // 运行超时
|
|||
kstep_motor_not_enable = ERROR_CODE(600, 5), // 电机未使能
|
|||
kstep_motor_ioindex_out_of_range = ERROR_CODE(600, 6), // IO超出范围
|
|||
kstep_motor_subic_reset = ERROR_CODE(600, 7), // 子IC复位
|
|||
kstep_motor_drv_err = ERROR_CODE(600, 8), // 驱动器异常
|
|||
kstep_motor_uv_cp = ERROR_CODE(600, 9), // 驱动器异常
|
|||
kstep_motor_not_found_point_edge = ERROR_CODE(600, 10), // 未找到零点
|
|||
|
|||
/***********************************************************************************************************************
|
|||
* 舵机错误码 * |
|||
***********************************************************************************************************************/ |
|||
kmini_servo_not_enable = ERROR_CODE(700, 0), //
|
|||
kmini_servo_mode_not_support = ERROR_CODE(700, 1), //
|
|||
|
|||
|
|||
} error_t; |
|||
|
|||
typedef struct { |
|||
int index; |
|||
const char* info; |
|||
} ecode_table_item_t; |
|||
|
|||
const char* error2str(int32_t code); |
|||
|
|||
ecode_table_item_t* error_get_table(); |
|||
int error_get_table_size(); |
|||
|
|||
} // namespace err
|
|||
} // namespace iflytop
|
@ -1,13 +0,0 @@ |
|||
#pragma once
|
|||
#include <stdint.h>
|
|||
|
|||
namespace iflytop { |
|||
typedef enum { |
|||
kuniversal_module = 0, // 通用模块
|
|||
khbot_module = 1, // hbot模块
|
|||
kmotor_module = 2, // 电机控制
|
|||
ktmc_step_motor = 10, // 步进电机
|
|||
kmini_servo_motor_module = 11, // 舵机
|
|||
kboard = 12, // 扩展板
|
|||
} module_type_t; |
|||
} |
@ -1,31 +0,0 @@ |
|||
#pragma once
|
|||
#include <stdint.h>
|
|||
|
|||
namespace iflytop { |
|||
namespace zcr { |
|||
#pragma pack(push, 1)
|
|||
typedef struct { |
|||
uint16_t packetindex; |
|||
uint16_t cmdMainId; // cmd main id
|
|||
uint8_t cmdSubId; // cmd sub id
|
|||
uint8_t packetType; //
|
|||
uint16_t subModuleid; // module id
|
|||
uint8_t data[]; |
|||
} zcr_cmd_header_t; |
|||
#pragma pack(pop)
|
|||
|
|||
typedef enum { |
|||
kptv2_cmd = 0, |
|||
kptv2_ack = 1, |
|||
kptv2_error_ack = 2, |
|||
kptv2_event = 3, |
|||
} zcan_cmd_packet_type_t; |
|||
|
|||
} // namespace zcr
|
|||
} // namespace iflytop
|
|||
|
|||
#define CMD_SUB_ID(cmdid) (cmdid & 0xff)
|
|||
#define MODULE_CMDID(cmdid) (cmdid >> 8)
|
|||
|
|||
#define STEP_MOTOR_ID_OFF 100
|
|||
#define XY_MOTOR_ID_OFF 200
|
@ -1 +0,0 @@ |
|||
#define ZCANCMD_READ_BUF_MAX_SIZE 512
|
@ -1,78 +0,0 @@ |
|||
|
|||
#include "reg_index.hpp"
|
|||
|
|||
#include <stdint.h>
|
|||
|
|||
namespace iflytop { |
|||
|
|||
#define REG_ITERM(enum) \
|
|||
{ enum, #enum } |
|||
|
|||
static reginfo_t table[] = { |
|||
REG_ITERM(kreg_module_version), |
|||
REG_ITERM(kreg_module_type), |
|||
REG_ITERM(kreg_module_status), |
|||
REG_ITERM(kreg_module_errorcode), |
|||
|
|||
REG_ITERM(kreg_opt_module_do_action0), |
|||
REG_ITERM(kreg_opt_module_action_param1), |
|||
REG_ITERM(kreg_opt_module_action_param2), |
|||
REG_ITERM(kreg_opt_module_action_param3), |
|||
REG_ITERM(kreg_opt_module_action_ack1), |
|||
REG_ITERM(kreg_opt_module_action_ack2), |
|||
|
|||
|
|||
REG_ITERM(kreg_step_motor_pos), |
|||
REG_ITERM(kreg_step_motor_dpos), |
|||
REG_ITERM(kreg_step_motor_shift), |
|||
REG_ITERM(kreg_step_motor_shaft), |
|||
REG_ITERM(kreg_step_motor_one_circle_pulse), |
|||
REG_ITERM(kreg_step_motor_one_circle_pulse_denominator), |
|||
REG_ITERM(kreg_step_motor_default_velocity), |
|||
REG_ITERM(kreg_step_motor_ihold), |
|||
REG_ITERM(kreg_step_motor_irun), |
|||
REG_ITERM(kreg_step_motor_iholddelay), |
|||
REG_ITERM(kreg_step_motor_iglobalscaler), |
|||
REG_ITERM(kreg_step_motor_run_to_zero_speed), |
|||
REG_ITERM(kreg_step_motor_look_zero_edge_speed), |
|||
REG_ITERM(kreg_step_motor_max_d), |
|||
REG_ITERM(kreg_step_motor_min_d), |
|||
REG_ITERM(kreg_step_motor_in_debug_mode), |
|||
REG_ITERM(kreg_step_motor_vstart), |
|||
REG_ITERM(kreg_step_motor_a1), |
|||
REG_ITERM(kreg_step_motor_amax), |
|||
REG_ITERM(kreg_step_motor_v1), |
|||
REG_ITERM(kreg_step_motor_dmax), |
|||
REG_ITERM(kreg_step_motor_d1), |
|||
REG_ITERM(kreg_step_motor_vstop), |
|||
REG_ITERM(kreg_step_motor_tzerowait), |
|||
REG_ITERM(kreg_mini_servo_pos), |
|||
REG_ITERM(kreg_mini_servo_limit_velocity), |
|||
REG_ITERM(kreg_mini_servo_limit_torque), |
|||
REG_ITERM(kreg_mini_servo_protective_torque), |
|||
|
|||
|
|||
}; |
|||
|
|||
reginfo_t *get_reginfo_by_index(int32_t index) { |
|||
for (int i = 0; i < sizeof(table) / sizeof(table[0]); i++) { |
|||
if (table[i].index == index) { |
|||
return &table[i]; |
|||
} |
|||
} |
|||
return nullptr; |
|||
} |
|||
|
|||
const char *regindex2str(int32_t index) { |
|||
for (int i = 0; i < sizeof(table) / sizeof(table[0]); i++) { |
|||
if (table[i].index == index) { |
|||
return table[i].regname; |
|||
} |
|||
} |
|||
return "unknown reg"; |
|||
} |
|||
|
|||
reginfo_t *reg_get_table() { return table; } |
|||
int reg_get_table_size() { return sizeof(table) / sizeof(table[0]); } |
|||
|
|||
} // namespace iflytop
|
@ -1,78 +0,0 @@ |
|||
#pragma once
|
|||
#include <stdint.h>
|
|||
|
|||
namespace iflytop { |
|||
using namespace std; |
|||
|
|||
#define REG_INDEX(type, offset, subconfigindex) (type * 100 + offset + subconfigindex)
|
|||
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_opt_module_do_action0 = REG_INDEX(0, 0, 40), // 方法0
|
|||
kreg_opt_module_action_param1 = REG_INDEX(0, 0, 41), // 方法1
|
|||
kreg_opt_module_action_param2 = REG_INDEX(0, 0, 42), // 方法2
|
|||
kreg_opt_module_action_param3 = REG_INDEX(0, 0, 43), // 方法3
|
|||
kreg_opt_module_action_ack1 = REG_INDEX(0, 0, 51), // ACK1
|
|||
kreg_opt_module_action_ack2 = REG_INDEX(0, 0, 52), // ACK2
|
|||
|
|||
|
|||
/***********************************************************************************************************************
|
|||
* step_motor * |
|||
***********************************************************************************************************************/ |
|||
kreg_step_motor_pos = REG_INDEX(101, 0, 1), // 机器人x坐标
|
|||
kreg_step_motor_dpos = REG_INDEX(101, 0, 3), // 执行完上一条指令后的相对位移
|
|||
|
|||
kreg_step_motor_shift = REG_INDEX(101, 50, 0), // x偏移
|
|||
kreg_step_motor_shaft = REG_INDEX(101, 50, 1), // x轴是否反转
|
|||
kreg_step_motor_one_circle_pulse = REG_INDEX(101, 50, 2), // x轴一圈脉冲数
|
|||
kreg_step_motor_one_circle_pulse_denominator = REG_INDEX(101, 50, 3), // 设置一圈脉冲数的分母
|
|||
kreg_step_motor_default_velocity = REG_INDEX(101, 50, 4), // 默认速度
|
|||
kreg_step_motor_ihold = REG_INDEX(101, 50, 8), // 步进电机电流配置
|
|||
kreg_step_motor_irun = REG_INDEX(101, 50, 9), // 步进电机电流配置
|
|||
kreg_step_motor_iholddelay = REG_INDEX(101, 50, 10), // 步进电机电流配置
|
|||
kreg_step_motor_iglobalscaler = REG_INDEX(101, 50, 11), // 步进电机电流配置
|
|||
kreg_step_motor_run_to_zero_speed = REG_INDEX(101, 50, 23), // 回零速度
|
|||
kreg_step_motor_look_zero_edge_speed = REG_INDEX(101, 50, 25), // 找零边缘速度
|
|||
kreg_step_motor_max_d = REG_INDEX(101, 50, 28), // 最大限制距离
|
|||
kreg_step_motor_min_d = REG_INDEX(101, 50, 29), // 最小限制距离
|
|||
kreg_step_motor_in_debug_mode = REG_INDEX(101, 50, 30), // 驱动器处于调试模式
|
|||
|
|||
kreg_step_motor_vstart = REG_INDEX(101, 50, 31), // a1起作用的速度
|
|||
kreg_step_motor_a1 = REG_INDEX(101, 50, 32), //
|
|||
kreg_step_motor_amax = REG_INDEX(101, 50, 33), |
|||
kreg_step_motor_v1 = REG_INDEX(101, 50, 34), |
|||
kreg_step_motor_dmax = REG_INDEX(101, 50, 35), |
|||
kreg_step_motor_d1 = REG_INDEX(101, 50, 36), |
|||
kreg_step_motor_vstop = REG_INDEX(101, 50, 37), |
|||
kreg_step_motor_tzerowait = REG_INDEX(101, 50, 38), |
|||
|
|||
/***********************************************************************************************************************
|
|||
* MINI_STEP_MOTOR * |
|||
***********************************************************************************************************************/ |
|||
|
|||
kreg_mini_servo_pos = REG_INDEX(102, 0, 1), // 位置
|
|||
kreg_mini_servo_limit_velocity = REG_INDEX(102, 50, 1), // 限制速度
|
|||
kreg_mini_servo_limit_torque = REG_INDEX(102, 50, 2), // 限制扭矩
|
|||
kreg_mini_servo_protective_torque = REG_INDEX(102, 50, 3), // 保护扭矩
|
|||
|
|||
} reg_index_t; |
|||
|
|||
typedef struct { |
|||
int index; |
|||
const char* regname; |
|||
} reginfo_t; |
|||
|
|||
const char* regindex2str(int32_t code); |
|||
reginfo_t* reg_get_table(); |
|||
int reg_get_table_size(); |
|||
|
|||
} // namespace iflytop
|
@ -1,20 +0,0 @@ |
|||
#pragma once
|
|||
#include <stdint.h>
|
|||
|
|||
#include <functional>
|
|||
|
|||
#include "apibasic/basic.hpp"
|
|||
|
|||
namespace iflytop { |
|||
using namespace std; |
|||
class ZIBoard { |
|||
public: |
|||
virtual ~ZIBoard() {} |
|||
virtual int32_t extboard_read_inio(int32_t ioindex, int32_t *val) = 0; |
|||
virtual int32_t kextboard_write_outio(int32_t ioindex, int32_t val) = 0; |
|||
virtual int32_t extboard_read_muti_inio(int32_t *val) = 0; |
|||
virtual int32_t extboard_read_inio_index_in_stm32(int32_t ioindex, int32_t *val) = 0; |
|||
virtual int32_t extboard_read_outio_index_in_stm32(int32_t ioindex, int32_t *val) = 0; |
|||
virtual int32_t extboard_read_outio(int32_t ioindex, int32_t *val) = 0; |
|||
}; |
|||
} // namespace iflytop
|
@ -1,14 +0,0 @@ |
|||
#pragma once
|
|||
#include <stdint.h>
|
|||
|
|||
#include <functional>
|
|||
#include "apibasic/basic.hpp"
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
namespace iflytop { |
|||
using namespace std; |
|||
|
|||
} // namespace iflytop
|
@ -1,26 +0,0 @@ |
|||
#pragma once
|
|||
#include <stdint.h>
|
|||
|
|||
#include <functional>
|
|||
|
|||
#include "apibasic/basic.hpp"
|
|||
|
|||
namespace iflytop { |
|||
using namespace std; |
|||
|
|||
class ZIMiniServo { |
|||
public: |
|||
virtual ~ZIMiniServo() {} |
|||
virtual int32_t mini_servo_enable(int32_t enable) = 0; |
|||
virtual int32_t mini_servo_read_pos(int32_t* pos) = 0; |
|||
virtual int32_t mini_servo_active_cfg() = 0; |
|||
virtual int32_t mini_servo_stop(int32_t breakstop) = 0; |
|||
|
|||
virtual int32_t mini_servo_move_to(int32_t pos3600) = 0; // 舵机模式
|
|||
virtual int32_t mini_servo_rotate(int32_t speed) = 0; // 速度模式
|
|||
virtual int32_t mini_servo_rotate_with_torque(int32_t torque) = 0; // 扭矩模式
|
|||
|
|||
virtual int32_t mini_servo_set_mid_point() = 0; |
|||
virtual int32_t mini_servo_read_io_state(int32_t ioindex, int32_t* val) = 0; |
|||
}; |
|||
} // namespace iflytop
|
@ -1,96 +0,0 @@ |
|||
|
|||
#include "zi_module.hpp"
|
|||
|
|||
#include <stdint.h>
|
|||
|
|||
#include <functional>
|
|||
|
|||
using namespace iflytop; |
|||
|
|||
int32_t ZIModule::getid() { |
|||
int32_t id = 0; |
|||
getid(&id); |
|||
return id; |
|||
}; |
|||
|
|||
int32_t ZIModule::module_ping() { return 0; }; |
|||
int32_t ZIModule::module_set_reg(int32_t param_id, int32_t param_value) { return _module_xxx_reg(param_id, false, param_value); } |
|||
int32_t ZIModule::module_get_reg(int32_t param_id, int32_t *param_value) { return _module_xxx_reg(param_id, true, *param_value); } |
|||
|
|||
int32_t ZIModule::_module_xxx_reg(int32_t param_id, bool read, int32_t &val) { |
|||
if (param_id == kreg_module_version) { |
|||
if (read) { |
|||
module_get_version(&val); |
|||
return 0; |
|||
} else { |
|||
return 0; |
|||
} |
|||
} |
|||
|
|||
else if (param_id == kreg_module_type) { |
|||
if (read) { |
|||
module_get_type(&val); |
|||
return 0; |
|||
} else { |
|||
return 0; |
|||
} |
|||
} |
|||
|
|||
else if (param_id == kreg_module_status) { |
|||
if (read) { |
|||
module_get_status(&val); |
|||
return 0; |
|||
} else { |
|||
return 0; |
|||
} |
|||
} |
|||
|
|||
else if (param_id == kreg_module_errorcode) { |
|||
if (read) { |
|||
val = creg.module_errorcode; |
|||
return 0; |
|||
} else { |
|||
return 0; |
|||
} |
|||
} |
|||
|
|||
return module_xxx_reg(param_id, read, val); |
|||
} |
|||
|
|||
int32_t ZIModule::_module_set_reg(int32_t regoff, int32_t *regval, int32_t val, int32_t min, int32_t max) { |
|||
if (val < min || val > max) { |
|||
return err::kparam_out_of_range; |
|||
} |
|||
*regval = val; |
|||
return 0; |
|||
} |
|||
int32_t ZIModule::_module_get_reg(int32_t regoff, int32_t regval, int32_t &val) { |
|||
val = regval; |
|||
return 0; |
|||
} |
|||
int32_t ZIModule::_module_set_reg_float(int32_t regoff, float *regval, int32_t val, float precision, int32_t min, int32_t max) { |
|||
if (val < min || val > max) { |
|||
return err::kparam_out_of_range; |
|||
} |
|||
*regval = val * precision; |
|||
return 0; |
|||
} |
|||
int32_t ZIModule::_module_get_reg_float(int32_t regoff, float regval, int32_t &val, float precision) { |
|||
val = regval / precision; |
|||
return 0; |
|||
} |
|||
|
|||
int32_t ZIModule::module_get_error(int32_t *iserror) { |
|||
*iserror = creg.module_errorcode; |
|||
return 0; |
|||
} |
|||
int32_t ZIModule::module_clear_error() { |
|||
creg.module_errorcode = 0; |
|||
creg.module_status = 0; |
|||
return 0; |
|||
} |
|||
|
|||
int32_t ZIModule::module_get_status(int32_t *status) { |
|||
*status = creg.module_status; |
|||
return 0; |
|||
} |
@ -1,83 +0,0 @@ |
|||
#pragma once
|
|||
#include <stdint.h>
|
|||
|
|||
#include <functional>
|
|||
|
|||
#include "apibasic/basic.hpp"
|
|||
|
|||
namespace iflytop { |
|||
using namespace std; |
|||
|
|||
#define REG_SET(reg, ...) _module_set_reg(param_id, ®, val, ##__VA_ARGS__)
|
|||
#define REG_GET(reg) _module_get_reg(param_id, reg, val)
|
|||
|
|||
#define REG_SET_FLOAT(reg, precision, ...) _module_set_reg_float(param_id, ®, val, precision, ##__VA_ARGS__)
|
|||
#define REG_GET_FLOAT(reg, precision) _module_get_reg_float(param_id, reg, val, precision)
|
|||
|
|||
#define ACTION_NONE 0
|
|||
#define PROCESS_REG(param_id, readaction, writeacton) \
|
|||
case param_id: { \ |
|||
if (read) { \ |
|||
return readaction; \ |
|||
} else { \ |
|||
return writeacton; \ |
|||
} \ |
|||
} break; |
|||
|
|||
#define ENABLE_MODULE(name, type, version) \
|
|||
public: \ |
|||
virtual int32_t module_get_version(int32_t *val) { \ |
|||
*val = version; \ |
|||
return 0; \ |
|||
} \ |
|||
virtual int32_t module_get_type(int32_t *val) { \ |
|||
*val = type; \ |
|||
return 0; \ |
|||
} |
|||
|
|||
#define MODULE_COMMON_PROCESS_REG_CB()
|
|||
|
|||
typedef struct { |
|||
int32_t module_errorcode; |
|||
int32_t module_status; |
|||
} module_common_reg_t; |
|||
|
|||
class ZIModule { |
|||
int32_t m_inited_flag = 0; |
|||
|
|||
protected: |
|||
module_common_reg_t creg; |
|||
|
|||
public: |
|||
virtual ~ZIModule() {} |
|||
|
|||
public: |
|||
virtual int32_t getid(); |
|||
virtual int32_t module_ping(); |
|||
virtual int32_t module_get_error(int32_t *iserror); |
|||
virtual int32_t module_clear_error(); |
|||
virtual int32_t module_set_reg(int32_t param_id, int32_t param_value); |
|||
virtual int32_t module_get_reg(int32_t param_id, int32_t *param_value); |
|||
virtual int32_t module_get_status(int32_t *status); |
|||
virtual int32_t module_get_version(int32_t *val) = 0; |
|||
virtual int32_t module_get_type(int32_t *val) = 0; |
|||
virtual int32_t module_stop() { return 0; } |
|||
virtual int32_t module_active_cfg() { return 0; } |
|||
|
|||
/***********************************************************************************************************************
|
|||
* 用户实现 * |
|||
***********************************************************************************************************************/ |
|||
virtual int32_t getid(int32_t *id) = 0; |
|||
virtual int32_t module_xxx_reg(int32_t param_id, bool read, int32_t &val) = 0; |
|||
|
|||
protected: |
|||
virtual int32_t _module_set_reg(int32_t regoff, int32_t *regval, int32_t val, int32_t min = INT32_MIN, int32_t max = INT32_MAX); |
|||
virtual int32_t _module_get_reg(int32_t regoff, int32_t regval, int32_t &val); |
|||
virtual int32_t _module_set_reg_float(int32_t regoff, float *regval, int32_t val, float precision, int32_t min = INT32_MIN, int32_t max = INT32_MAX); |
|||
virtual int32_t _module_get_reg_float(int32_t regoff, float regval, int32_t &val, float precision); |
|||
virtual int32_t _module_xxx_reg(int32_t param_id, bool read, int32_t &val); |
|||
|
|||
public: |
|||
public: |
|||
}; |
|||
} // namespace iflytop
|
@ -1,154 +0,0 @@ |
|||
#pragma once
|
|||
#include <stdint.h>
|
|||
|
|||
#include <functional>
|
|||
|
|||
#include "apibasic/basic.hpp"
|
|||
|
|||
typedef struct { |
|||
uint32_t sg_result : 10; |
|||
uint32_t reserved0 : 5; |
|||
uint32_t fsactive : 1; |
|||
uint32_t cs_actual : 5; |
|||
uint32_t reserved1 : 3; |
|||
uint32_t stallguard : 1; |
|||
uint32_t ot : 1; |
|||
uint32_t otpw : 1; |
|||
uint32_t s2ga : 1; |
|||
uint32_t s2gb : 1; |
|||
uint32_t ola : 1; |
|||
uint32_t olb : 1; |
|||
uint32_t stst : 1; |
|||
} TMC5130MotorStatus_t; |
|||
|
|||
typedef struct { |
|||
uint32_t reset : 1; // fatal error
|
|||
uint32_t drv_err : 1; // fatal error
|
|||
uint32_t uv_cp : 1; // fatal error
|
|||
} TMC5130MotorState_t; // R+C
|
|||
|
|||
typedef struct { |
|||
uint32_t sg_result : 10; |
|||
uint32_t reserved0 : 1; |
|||
uint32_t reserved1 : 1; |
|||
uint32_t s2vsa : 1; |
|||
uint32_t s2vsb : 1; |
|||
uint32_t stealth : 1; |
|||
uint32_t fsactive : 1; |
|||
uint32_t cs_actual : 5; |
|||
uint32_t reserved2 : 3; |
|||
uint32_t stallguard : 1; |
|||
uint32_t ot : 1; |
|||
uint32_t otpw : 1; |
|||
uint32_t s2ga : 1; |
|||
uint32_t s2gb : 1; |
|||
uint32_t ola : 1; |
|||
uint32_t olb : 1; |
|||
uint32_t stst : 1; |
|||
} TMC2160MotorDriverStatus_t; |
|||
|
|||
typedef struct { |
|||
uint32_t TARGET_REACHED_F : 1; // XACTUAL = XTARGET
|
|||
uint32_t POS_COMP_REACHED_F : 1; // XACTUAL = POS_COMP
|
|||
uint32_t VEL_REACHED_F : 1; // VACTUAL = |VMAX|
|
|||
uint32_t VEL_STATE_F : 2; // 0:VACTUAL = 0; 1:VACTUAL > 0; 2:VACTUAL < 0
|
|||
uint32_t RAMP_STATE_F : 2; // 0:AACTUAL = 0; 1:AACTUAL 增加(加速); 2:AACTUAL 减小(减速)
|
|||
uint32_t STOPL_ACTIVE_F : 1; // 左停止开关有效。
|
|||
|
|||
uint32_t STOPR_ACTIVE_F : 1; // 右停止开关有效。
|
|||
uint32_t VSTOPL_ACTIVE_F : 1; // 左虚拟停止开关有效。
|
|||
uint32_t VSTOPR_ACTIVE_F : 1; // 右虚拟停止开关有效。
|
|||
uint32_t ACTIVE_STALL_F : 1; // 电机堵转检测且 VACTUAL > VSTALL_LIMIT。
|
|||
uint32_t HOME_ERROR_F : 1; // 输入信号电平不等于预期的回零电平。
|
|||
uint32_t FS_ACTIVE_F : 1; // 全步有效。
|
|||
uint32_t ENC_FAIL_F : 1; // XACTUAL 和 ENC_POS 中间的差值超出容差。
|
|||
uint32_t N_ACTIVE_F : 1; // 事件有效
|
|||
|
|||
uint32_t ENC_LATCH_F : 1; // ENC_LATCH 被重置。
|
|||
uint32_t MULTI_CYCLE_FAIL_F : 1; // 仅适用于绝对编码器 MULTI_CYCLE_FAIL_F 表示上一个多圈数据出现故障。
|
|||
uint32_t ___ : 1; //
|
|||
uint32_t CL_FIT_F : 1; // 如果 ENC_POS_DEV < CL_COMPLATION,则有效。XACTUAL 和 ENC_POS 之间的差值在容许范围内
|
|||
uint32_t SERIAL_ENC_FLAGS : 4; // 仅适用于绝对编码器:从编码器接收的 SERIAL_ENC_FLAGS。新的编码器传输请求是会重置这些标志
|
|||
|
|||
uint32_t SG : 1; // 仅 TMC26x / TMC21x0 StallGuard2 状态。
|
|||
uint32_t OT : 1; // 过温关断。
|
|||
uint32_t OTPW : 1; // 过温预警。
|
|||
uint32_t S2GA : 1; // 线圈 A 高端 MOSFET 管对地短路检测位。
|
|||
uint32_t S2GB : 1; // 线圈 B 高端 MOSFET 管对地短路检测位。
|
|||
uint32_t OLA : 1; // 线圈 A 开路。
|
|||
uint32_t OLB : 1; // 线圈 B 开路。
|
|||
uint32_t STST : 1; // 仅 TMC26x / TMC21x0 静止状态。
|
|||
} TMC4361AMotorStatus_t; // R+CW 事件标志位
|
|||
|
|||
typedef struct { |
|||
uint32_t reset : 1; // fatal error
|
|||
uint32_t drv_err : 1; // fatal error
|
|||
uint32_t uv_cp : 1; // fatal error
|
|||
} TMC2160MotorGstate_t; // R+C
|
|||
|
|||
typedef struct { |
|||
uint32_t TARGET_REACHED : 1; //
|
|||
uint32_t POS_COMP_REACHED : 1; //
|
|||
uint32_t VEL_REACHED : 1; //
|
|||
uint32_t VEL_STATE_EQ_0 : 1; //
|
|||
uint32_t VEL_STATE_EQ_1 : 1; //
|
|||
uint32_t VEL_STATE_EQ_2 : 1; //
|
|||
uint32_t RAMP_STATE_EQ_0 : 1; //
|
|||
uint32_t RAMP_STATE_EQ_1 : 1; //
|
|||
uint32_t RAMP_STATE_EQ_2 : 1; //
|
|||
uint32_t MAX_PHASE_TRAP : 1; // 梯形斜坡已经达到其极限速度
|
|||
uint32_t FROZEN : 1; // 重置 TMC4361A,以便进一步运动。 fatal error
|
|||
uint32_t STOPL : 1; //
|
|||
uint32_t STOPR : 1; //
|
|||
uint32_t VSTOPL_ACTIVE : 1; //
|
|||
uint32_t VSTOPR_ACTIVE : 1; //
|
|||
uint32_t HOME_ERROR : 1; //
|
|||
uint32_t XLATCH_DONE : 1; //
|
|||
uint32_t FS_ACTIVE : 1; //
|
|||
uint32_t ENC_FAIL : 1; //
|
|||
uint32_t N_ACTIVE : 1; //
|
|||
uint32_t ENC_DONE : 1; //
|
|||
uint32_t SER_ENC_DATA_FAIL : 1; //
|
|||
uint32_t ___ : 1; //
|
|||
uint32_t SER_DATA_DONE : 1; //
|
|||
uint32_t SERIAL_ENC_Flags : 1; //
|
|||
uint32_t COVER_DONE : 1; //
|
|||
uint32_t ENC_VEL0 : 1; // 编码器速度到 0。
|
|||
uint32_t CL_MAX : 1; //
|
|||
uint32_t CL_FIT : 1; //
|
|||
uint32_t STOP_ON_STALL : 1; // 检测到电机堵转。电机斜坡已经停止。 fatal error
|
|||
uint32_t MOTOR_EV : 1; // 选定的 TMC 电机驱动器标志之一被触发。
|
|||
uint32_t RST_EV : 1; // 复位被触发。 fatal error
|
|||
} TMC4361AMotorEventState_t; |
|||
|
|||
namespace iflytop { |
|||
using namespace std; |
|||
class ZIStepMotor { |
|||
public: |
|||
virtual ~ZIStepMotor() {} |
|||
virtual int32_t step_motor_enable(int32_t enable) = 0; |
|||
virtual int32_t step_motor_stop(int32_t breakstop) = 0; |
|||
virtual int32_t step_motor_read_pos(int32_t* pos) = 0; |
|||
virtual int32_t step_motor_easy_rotate(int32_t direction) = 0; |
|||
virtual int32_t step_motor_easy_move_by(int32_t distance) = 0; |
|||
virtual int32_t step_motor_easy_move_to(int32_t position) = 0; |
|||
virtual int32_t step_motor_easy_move_to_zero() = 0; |
|||
virtual int32_t step_motor_easy_set_current_pos(int32_t pos) = 0; |
|||
virtual int32_t step_motor_easy_move_to_io(int32_t ioindex, int32_t direction) = 0; |
|||
virtual int32_t step_motor_active_cfg() = 0; |
|||
virtual int32_t step_motor_read_io_state(int32_t ioindex, int32_t* state) = 0; |
|||
virtual int32_t step_motor_easy_move_to_end_point() = 0; |
|||
|
|||
/***********************************************************************************************************************
|
|||
* DEBUG * |
|||
***********************************************************************************************************************/ |
|||
virtual int32_t step_motor_read_tmc5130_status(int32_t* status) = 0; |
|||
virtual int32_t step_motor_read_tmc5130_state(int32_t* status) = 0; |
|||
virtual int32_t step_motor_read_tmc4361a_status(int32_t* status) = 0; |
|||
virtual int32_t step_motor_read_tmc4361a_state(int32_t* gstate) = 0; |
|||
virtual int32_t step_motor_read_tmc2160_status(int32_t* status) = 0; |
|||
virtual int32_t step_motor_read_tmc2160_state(int32_t* status) = 0; |
|||
|
|||
virtual int32_t step_motor_read_io_index_in_stm32(int32_t ioindex, int32_t* index_in_stm32) = 0; |
|||
}; |
|||
} // namespace iflytop
|
@ -1,24 +0,0 @@ |
|||
//
|
|||
// Created by zwsd
|
|||
//
|
|||
#pragma once
|
|||
#include "api/api.hpp"
|
|||
namespace iflytop { |
|||
using namespace zcr; |
|||
|
|||
class IZCanReceiverListener { |
|||
public: |
|||
virtual void onRceivePacket(zcr_cmd_header_t *rxcmd, uint8_t *data, int32_t len) = 0; |
|||
}; |
|||
|
|||
class IZCanReceiver { |
|||
public: |
|||
public: |
|||
virtual void registerListener(IZCanReceiverListener *listener) = 0; |
|||
virtual int32_t sendBufAck(zcr_cmd_header_t *rx_cmd_header, uint8_t *data, int32_t len) = 0; |
|||
virtual int32_t sendAck(zcr_cmd_header_t *rx_cmd_header, int32_t *ackvar, int32_t nack) = 0; |
|||
virtual int32_t sendErrorAck(zcr_cmd_header_t *rx_cmd_header, int32_t errorcode) = 0; |
|||
virtual int32_t triggerEvent(zcr_cmd_header_t *rx_cmd_header, uint8_t *data, int32_t len) = 0; |
|||
}; |
|||
|
|||
} // namespace iflytop
|
@ -1,5 +0,0 @@ |
|||
#pragma once
|
|||
#include "api/api.hpp"
|
|||
//
|
|||
#include "i_zcanreceiver.hpp"
|
|||
//
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue