From f1c6b085a48fb0c5d8aae8de6a897b5da474baf8 Mon Sep 17 00:00:00 2001 From: Robofish <1683502971@qq.com> Date: Sat, 6 Sep 2025 13:04:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=A7=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/settings.json | 8 +- assets/.DS_Store | Bin 6148 -> 6148 bytes assets/User_code/component/ballistics.c | 12 -- assets/User_code/component/ballistics.h | 23 --- assets/User_code/component/capacity.c | 1 - assets/User_code/component/cmd.h | 2 +- assets/User_code/component/dependencies.csv | 9 +- assets/User_code/component/describe.csv | 14 +- assets/User_code/config.csv | 2 +- assets/User_code/device/.DS_Store | Bin 8196 -> 8196 bytes assets/User_code/device/bmi088.c | 3 +- assets/User_code/device/config.yaml | 110 ++++++++++- assets/User_code/device/dm_imu.c | 2 +- assets/User_code/device/dr16.c | 2 +- assets/User_code/device/ist8310.c | 3 +- assets/User_code/device/motor.c | 20 +- assets/User_code/device/motor_lz.c | 5 - assets/User_code/device/motor_odrive.c | 3 +- assets/User_code/device/motor_rm.c | 3 +- assets/User_code/device/motor_vesc.c | 3 +- assets/User_code/device/motor_vesc.h | 208 ++++++++++---------- assets/User_code/device/vofa.c | 50 +++-- 22 files changed, 277 insertions(+), 206 deletions(-) delete mode 100644 assets/User_code/component/ballistics.c delete mode 100644 assets/User_code/component/ballistics.h diff --git a/.vscode/settings.json b/.vscode/settings.json index 4da8f7d..e5eccc8 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -11,6 +11,12 @@ "device.h": "c", "gpio.h": "c", "uart.h": "c", - "motor_rm.h": "c" + "motor_rm.h": "c", + "mm.h": "c", + "capacity.h": "c", + "error_detect.h": "c", + "bmi088.h": "c", + "time.h": "c", + "motor.h": "c" } } \ No newline at end of file diff --git a/assets/.DS_Store b/assets/.DS_Store index 90d92e106155253174d1803bbac4fef65b9a3d8e..f40f665f4a74be6ff485f427fcce0249d491cc1a 100644 GIT binary patch delta 32 ocmZoMXfc@J&&awlU^gQp>t-IN4#v$_n2lK`HaKi%=lIJH0H%BjI{*Lx delta 83 zcmZoMXfc@J&&akhU^gQp+h!i74n|X6hERrLhE#?khIoc#hJ1z;AX|^2iXoGsz%wU5 hIVmSUiGhJZfPsOr8%XQ@2ZPNMneA9Mvvd6A2LO1f7y1AI diff --git a/assets/User_code/component/ballistics.c b/assets/User_code/component/ballistics.c deleted file mode 100644 index 4b5572f..0000000 --- a/assets/User_code/component/ballistics.c +++ /dev/null @@ -1,12 +0,0 @@ -/* - 弹道补偿算法。 -*/ - -#include "ballistics.h" - -void Ballistics_Init(Ballistics_t *b) { (void)b; } -void Ballistics_Apply(Ballistics_t *b, float bullet_speed) { - (void)b; - (void)bullet_speed; -} -void Ballistics_Reset(Ballistics_t *b) { (void)b; } diff --git a/assets/User_code/component/ballistics.h b/assets/User_code/component/ballistics.h deleted file mode 100644 index 3b9faa6..0000000 --- a/assets/User_code/component/ballistics.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - 弹道补偿算法。 -*/ - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#include "ahrs.h" - -typedef struct { - AHRS_Eulr_t *eulr; -} Ballistics_t; - -void Ballistics_Init(Ballistics_t *b); -void Ballistics_Apply(Ballistics_t *b, float bullet_speed); -void Ballistics_Reset(Ballistics_t *b); - -#ifdef __cplusplus -} -#endif diff --git a/assets/User_code/component/capacity.c b/assets/User_code/component/capacity.c index 6865e54..a7bf801 100644 --- a/assets/User_code/component/capacity.c +++ b/assets/User_code/component/capacity.c @@ -1,6 +1,5 @@ /* 剩余电量算法。 - 通过电压值计算剩余电量。 */ diff --git a/assets/User_code/component/cmd.h b/assets/User_code/component/cmd.h index 0b352dd..8561239 100644 --- a/assets/User_code/component/cmd.h +++ b/assets/User_code/component/cmd.h @@ -11,7 +11,7 @@ extern "C" { #include #include -#include "ahrs.h" +#include "component/ahrs.h" #define CMD_REFEREE_MAX_NUM (3) /* 发送命令限定的最大数量 */ diff --git a/assets/User_code/component/dependencies.csv b/assets/User_code/component/dependencies.csv index a39df2c..c3f1e6d 100644 --- a/assets/User_code/component/dependencies.csv +++ b/assets/User_code/component/dependencies.csv @@ -1,3 +1,8 @@ +ahrs,component/user_math.h +capacity,component/user_math.h +cmd,component/ahrs +error_detect,bsp/mm pid,component/filter -ahrs,component/filter -filter,component/ahrs \ No newline at end of file +filter,component/ahrs +mixer,component/user_math.h +ui,component/user_math.h \ No newline at end of file diff --git a/assets/User_code/component/describe.csv b/assets/User_code/component/describe.csv index 1110872..2752291 100644 --- a/assets/User_code/component/describe.csv +++ b/assets/User_code/component/describe.csv @@ -1,2 +1,14 @@ pid,好用的 -ahrs,开源的 \ No newline at end of file +ahrs,开源的AHRS算法,MadgwickAHRS +capacity,电池容量计算 +cmd,通用控制命令 +crc8,CRC8校验rm +crc16,CRC16校验rm +error_detect,错误检测 +filter,各类滤波器 +FreeRTOS_CLI,FreeRTOS命令行接口 +limiter,限幅器 +mixer,混控器 +ui,用户交互 +user_math,用户自定义数学函数 +pid,PID控制器 \ No newline at end of file diff --git a/assets/User_code/config.csv b/assets/User_code/config.csv index 6d57c2e..d17e078 100644 --- a/assets/User_code/config.csv +++ b/assets/User_code/config.csv @@ -1,4 +1,4 @@ bsp,can,dwt,gpio,i2c,mm,spi,uart,pwm,time -component,ahrs,ballistics,capacity,cmd,crc8,crc16,error_detect,filter,FreeRTOS_CLI,limiter,mixer,pid,ui,user_math +component,ahrs,capacity,cmd,crc8,crc16,error_detect,filter,FreeRTOS_CLI,limiter,mixer,pid,ui,user_math device,dr16,bmi088,ist8310,motor,motor_rm,motor_vesc,motor_lk,motor_lz,motor_odrive,dm_imu,servo,buzzer,led,ws2812 module, \ No newline at end of file diff --git a/assets/User_code/device/.DS_Store b/assets/User_code/device/.DS_Store index 96266418d89d5df716d0ac2f3facbf4da6b81218..f5ef0ae210ea84bdd794ca8459fac3b95d731f87 100644 GIT binary patch delta 46 zcmZp1XmOa}&nUMsU^hRb+-4pDO~%QtLJ6Byg&(nOY?#2fnO))=%jRCOD#ncsy^H{1 C;t!($ delta 274 zcmZp1XmOa}C7U^hRb%4Qw`O-4l_h7^WWhBAgshGZZe&yd7W%1{M_sSHI78VrUE znv-7%D-)qgPe^RCjR-FRl}14GHUL#d2oj_69#Cb6An#;T!30?WpgVJc?#l#{r9e8B zp@Jb1$Sz>WVMv`U1azYSgA0Q%P{tETh63pz23H10u$U`@9#Cbreverse) { - return -motor->feedback.rotor_abs_angle; - }else{ - return motor->feedback.rotor_abs_angle; - } + motor->feedback.rotor_abs_angle; } float MOTOR_GetRotorSpeed(const MOTOR_t *motor) { if (motor == NULL) return DEVICE_ERR_NULL; - if (motor->reverse) { - return -motor->feedback.rotor_speed; - }else{ - return motor->feedback.rotor_speed; - } + return motor->feedback.rotor_speed; } float MOTOR_GetTorqueCurrent(const MOTOR_t *motor) { if (motor == NULL) return DEVICE_ERR_NULL; - if (motor->reverse) { - return -motor->feedback.torque_current; - }else{ - return motor->feedback.torque_current; - } + return motor->feedback.torque_current; } float MOTOR_GetTemp(const MOTOR_t *motor) { diff --git a/assets/User_code/device/motor_lz.c b/assets/User_code/device/motor_lz.c index 45f7f76..e9b6607 100644 --- a/assets/User_code/device/motor_lz.c +++ b/assets/User_code/device/motor_lz.c @@ -1,10 +1,5 @@ /* 灵足电机驱动 - - 灵足电机通信协议: - - CAN 2.0通信接口,波特率1Mbps - - 采用扩展帧格式(29位ID) - - ID格式:Bit28~24(通信类型) + Bit23~8(数据区2) + Bit7~0(目标地址) */ /* Includes ----------------------------------------------------------------- */ #include "motor_lz.h" diff --git a/assets/User_code/device/motor_odrive.c b/assets/User_code/device/motor_odrive.c index 6394600..74b9319 100644 --- a/assets/User_code/device/motor_odrive.c +++ b/assets/User_code/device/motor_odrive.c @@ -1,6 +1,5 @@ /* - CAN总线上的设备 - 将所有CAN总线上挂载的设备抽象成一个设备进行配置和控制 + Odrive电机驱动 */ /* Includes ----------------------------------------------------------------- */ #include "motor_odrive.h" diff --git a/assets/User_code/device/motor_rm.c b/assets/User_code/device/motor_rm.c index 5db245c..49a867e 100644 --- a/assets/User_code/device/motor_rm.c +++ b/assets/User_code/device/motor_rm.c @@ -1,6 +1,5 @@ /* - CAN总线上的设备 - 将所有CAN总线上挂载的设备抽象成一个设备进行配置和控制 + RM电机驱动 */ /* Includes ----------------------------------------------------------------- */ #include "motor_rm.h" diff --git a/assets/User_code/device/motor_vesc.c b/assets/User_code/device/motor_vesc.c index 1947b62..68333f7 100644 --- a/assets/User_code/device/motor_vesc.c +++ b/assets/User_code/device/motor_vesc.c @@ -1,6 +1,5 @@ /* - CAN总线上的设备 - 将所有CAN总线上挂载的设备抽象成一个设备进行配置和控制 + VESC电机驱动 */ /* Includes ----------------------------------------------------------------- */ #include "motor_vesc.h" diff --git a/assets/User_code/device/motor_vesc.h b/assets/User_code/device/motor_vesc.h index eaea852..7209218 100644 --- a/assets/User_code/device/motor_vesc.h +++ b/assets/User_code/device/motor_vesc.h @@ -20,125 +20,125 @@ extern "C" // VESC数量根据实际情况调整 #define VESC_MAX_MOTORS 4 - /* Exported constants ------------------------------------------------------- */ +/* Exported constants ------------------------------------------------------- */ - /* Exported macro ----------------------------------------------------------- */ - /* Exported types ----------------------------------------------------------- */ +/* Exported macro ----------------------------------------------------------- */ +/* Exported types ----------------------------------------------------------- */ - typedef enum - { - VESC_1 = 1, - VESC_2 = 2, - VESC_3 = 3, - VESC_4 = 4, - CAN_VESC5065_M1_MSG1 = 0x901, // vesc的数据回传使用了扩展id,[0:7]为驱动器id,[8:15]为帧类型 - CAN_VESC5065_M2_MSG1 = 0x902, - CAN_VESC5065_M3_MSG1 = 0x903, - CAN_VESC5065_M4_MSG1 = 0x904, - }VESC_ID; +typedef enum +{ + VESC_1 = 1, + VESC_2 = 2, + VESC_3 = 3, + VESC_4 = 4, + CAN_VESC5065_M1_MSG1 = 0x901, // vesc的数据回传使用了扩展id,[0:7]为驱动器id,[8:15]为帧类型 + CAN_VESC5065_M2_MSG1 = 0x902, + CAN_VESC5065_M3_MSG1 = 0x903, + CAN_VESC5065_M4_MSG1 = 0x904, +}VESC_ID; - typedef enum - { - CAN_PACKET_SET_DUTY = 0, - CAN_PACKET_SET_CURRENT = 1, - CAN_PACKET_SET_CURRENT_BRAKE = 2, - CAN_PACKET_SET_RPM = 3, - CAN_PACKET_SET_POS = 4, - CAN_PACKET_FILL_RX_BUFFER = 5, - CAN_PACKET_FILL_RX_BUFFER_LONG = 6, - CAN_PACKET_PROCESS_RX_BUFFER = 7, - CAN_PACKET_PROCESS_SHORT_BUFFER = 8, - CAN_PACKET_STATUS = 9, - CAN_PACKET_SET_CURRENT_REL = 10, - CAN_PACKET_SET_CURRENT_BRAKE_REL = 11, - CAN_PACKET_SET_CURRENT_HANDBRAKE = 12, - CAN_PACKET_SET_CURRENT_HANDBRAKE_REL = 13 - } CAN_PACKET_ID; +typedef enum +{ + CAN_PACKET_SET_DUTY = 0, + CAN_PACKET_SET_CURRENT = 1, + CAN_PACKET_SET_CURRENT_BRAKE = 2, + CAN_PACKET_SET_RPM = 3, + CAN_PACKET_SET_POS = 4, + CAN_PACKET_FILL_RX_BUFFER = 5, + CAN_PACKET_FILL_RX_BUFFER_LONG = 6, + CAN_PACKET_PROCESS_RX_BUFFER = 7, + CAN_PACKET_PROCESS_SHORT_BUFFER = 8, + CAN_PACKET_STATUS = 9, + CAN_PACKET_SET_CURRENT_REL = 10, + CAN_PACKET_SET_CURRENT_BRAKE_REL = 11, + CAN_PACKET_SET_CURRENT_HANDBRAKE = 12, + CAN_PACKET_SET_CURRENT_HANDBRAKE_REL = 13 +} CAN_PACKET_ID; - // Control Modes - typedef enum - { - DUTY_CONTROL = 0x0, - RPM_CONTROL = 0x1, - CURRENT_CONTROL = 0x2, - POSITION_CONTROL = 0x3 - } Control_Mode; +// Control Modes +typedef enum +{ + DUTY_CONTROL = 0x0, + RPM_CONTROL = 0x1, + CURRENT_CONTROL = 0x2, + POSITION_CONTROL = 0x3 +} Control_Mode; - /*每个电机需要的参数*/ - typedef struct - { - BSP_CAN_t can; - uint16_t id; - uint16_t mode; - bool reverse; - } VESC_Param_t; +/*每个电机需要的参数*/ +typedef struct +{ + BSP_CAN_t can; + uint16_t id; + uint16_t mode; + bool reverse; +} VESC_Param_t; - /*电机实例*/ - typedef struct ODrive_t - { - VESC_Param_t param; - MOTOR_t motor; - } VESC_t; +/*电机实例*/ +typedef struct ODrive_t +{ + VESC_Param_t param; + MOTOR_t motor; +} VESC_t; - /*CAN管理器,管理一个CAN总线上所有的电机*/ - typedef struct - { - BSP_CAN_t can; - VESC_t *motors[VESC_MAX_MOTORS]; - uint8_t motor_count; - } VESC_CANManager_t; +/*CAN管理器,管理一个CAN总线上所有的电机*/ +typedef struct +{ + BSP_CAN_t can; + VESC_t *motors[VESC_MAX_MOTORS]; + uint8_t motor_count; +} VESC_CANManager_t; - /* Exported functions prototypes -------------------------------------------- */ +/* Exported functions prototypes -------------------------------------------- */ - /** - * @brief 注册一个vesc电机 - * @param param 电机参数 - * @return - */ - int8_t VESC_Register(VESC_Param_t *param); +/** + * @brief 注册一个vesc电机 + * @param param 电机参数 + * @return + */ +int8_t VESC_Register(VESC_Param_t *param); - /** - * @brief 更新指定电机数据 - * @param param 电机参数 - * @return - */ - int8_t VESC_Update(VESC_Param_t *param); +/** + * @brief 更新指定电机数据 + * @param param 电机参数 + * @return + */ +int8_t VESC_Update(VESC_Param_t *param); - /** - * @brief 更新所有电机数据 - * @return - */ - int8_t VESC_UpdateAll(void); - - /** - * @brief 设置一个电机的输出 - * @param param 电机参数 - * @param value 输出值 - * @return - */ +/** + * @brief 更新所有电机数据 + * @return + */ +int8_t VESC_UpdateAll(void); - int8_t VESC_SetOutput(VESC_Param_t *param, float value); +/** + * @brief 设置一个电机的输出 + * @param param 电机参数 + * @param value 输出值 + * @return + */ - /** - * @brief 获取指定电机的实例指针 - * @param param 电机参数 - * @return - */ +int8_t VESC_SetOutput(VESC_Param_t *param, float value); - VESC_t* VESC_GetMotor(VESC_Param_t *param); +/** + * @brief 获取指定电机的实例指针 + * @param param 电机参数 + * @return + */ - /** - * @brief 使电机松弛(设置输出为0) - * @param param - * @return - */ - int8_t VESC_Relax(VESC_Param_t *param); - /** - * @brief 使电机离线(设置在线状态为false) - * @param param - * @return - */ - int8_t VESC_Offine(VESC_Param_t *param); +VESC_t* VESC_GetMotor(VESC_Param_t *param); + +/** + * @brief 使电机松弛(设置输出为0) + * @param param + * @return + */ +int8_t VESC_Relax(VESC_Param_t *param); +/** + * @brief 使电机离线(设置在线状态为false) + * @param param + * @return + */ +int8_t VESC_Offine(VESC_Param_t *param); #ifdef __cplusplus diff --git a/assets/User_code/device/vofa.c b/assets/User_code/device/vofa.c index 662a406..bfc3b5a 100644 --- a/assets/User_code/device/vofa.c +++ b/assets/User_code/device/vofa.c @@ -1,14 +1,10 @@ /* Includes ----------------------------------------------------------------- */ #include #include -#include "vofa.h" +#include "device/vofa.h" #include "bsp/uart.h" /* Private define ----------------------------------------------------------- */ -//#define PROTOCOL_RAWDATA -#define PROTOCOL_FIREWATER -//#define PROTOCOL_JUSTFLOAT - #define MAX_CHANNEL 64u // ʵͨ #define JUSTFLOAT_TAIL 0x7F800000 @@ -16,6 +12,7 @@ /* Private typedef ---------------------------------------------------------- */ /* Private variables -------------------------------------------------------- */ static uint8_t vofa_tx_buf[sizeof(float) * MAX_CHANNEL + sizeof(uint32_t)]; +static VOFA_Protocol_t current_protocol = VOFA_PROTOCOL_FIREWATER; // ĬЭ /* Private function -------------------------------------------------------- */ @@ -59,19 +56,34 @@ void VOFA_JustFloat_Send(float *channels, uint8_t channel_count, bool dma) } /* Exported functions ------------------------------------------------------- */ -init8_t VOFA_Send(float* channels, uint8_t channel_count, bool dma) { -#ifdef PROTOCOL_RAWDATA - sprintf(vofa_tx_buf, "Channel1:%.2f,Channel2:%.2f\n", channels[0],channels[1]); - VOFA_RawData_Send(vofa_tx_buf, dma); -#elif defined(PROTOCOL_FIREWATER) - VOFA_FireWater_Send(channels, channel_count, dma); -#elif defined(PROTOCOL_JUSTFLOAT) - VOFA_JustFloat_Send(channels, channel_count, dma); -#else - // ĬʹRawDataЭ - char data[256]; - sprintf(data, "Channel1: %.2f, Channel2: %.2f\n", channels[0], channels[1]); - VOFA_RawData_Send(data, dma); -#endif +int8_t VOFA_init(VOFA_Protocol_t protocol) { + current_protocol = protocol; + return DEVICE_OK; +} + +int8_t VOFA_Send(float* channels, uint8_t channel_count, bool dma) { + switch (current_protocol) { + case VOFA_PROTOCOL_RAWDATA: + { + char data[256]; + if (channel_count >= 1) { + sprintf(data, "Channel1: %.2f", channels[0]); + if (channel_count >= 2) { + sprintf(data + strlen(data), ", Channel2: %.2f", channels[1]); + } + strcat(data, "\n"); + VOFA_RawData_Send(data, dma); + } + } + break; + case VOFA_PROTOCOL_FIREWATER: + VOFA_FireWater_Send(channels, channel_count, dma); + break; + case VOFA_PROTOCOL_JUSTFLOAT: + VOFA_JustFloat_Send(channels, channel_count, dma); + break; + default: + return DEVICE_ERR; + } return DEVICE_OK; }