mirror of
https://github.com/goldenfishs/MRobot.git
synced 2025-09-14 12:54:33 +08:00
大更新
This commit is contained in:
parent
d626e4e656
commit
f1c6b085a4
8
.vscode/settings.json
vendored
8
.vscode/settings.json
vendored
@ -11,6 +11,12 @@
|
|||||||
"device.h": "c",
|
"device.h": "c",
|
||||||
"gpio.h": "c",
|
"gpio.h": "c",
|
||||||
"uart.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"
|
||||||
}
|
}
|
||||||
}
|
}
|
BIN
assets/.DS_Store
vendored
BIN
assets/.DS_Store
vendored
Binary file not shown.
@ -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; }
|
|
@ -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
|
|
@ -1,6 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
剩余电量算法。
|
剩余电量算法。
|
||||||
|
|
||||||
通过电压值计算剩余电量。
|
通过电压值计算剩余电量。
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ extern "C" {
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "ahrs.h"
|
#include "component/ahrs.h"
|
||||||
|
|
||||||
#define CMD_REFEREE_MAX_NUM (3) /* 发送命令限定的最大数量 */
|
#define CMD_REFEREE_MAX_NUM (3) /* 发送命令限定的最大数量 */
|
||||||
|
|
||||||
|
@ -1,3 +1,8 @@
|
|||||||
|
ahrs,component/user_math.h
|
||||||
|
capacity,component/user_math.h
|
||||||
|
cmd,component/ahrs
|
||||||
|
error_detect,bsp/mm
|
||||||
pid,component/filter
|
pid,component/filter
|
||||||
ahrs,component/filter
|
|
||||||
filter,component/ahrs
|
filter,component/ahrs
|
||||||
|
mixer,component/user_math.h
|
||||||
|
ui,component/user_math.h
|
|
@ -1,2 +1,14 @@
|
|||||||
pid,好用的
|
pid,好用的
|
||||||
ahrs,开源的
|
ahrs,开源的AHRS算法,MadgwickAHRS
|
||||||
|
capacity,电池容量计算
|
||||||
|
cmd,通用控制命令
|
||||||
|
crc8,CRC8校验rm
|
||||||
|
crc16,CRC16校验rm
|
||||||
|
error_detect,错误检测
|
||||||
|
filter,各类滤波器
|
||||||
|
FreeRTOS_CLI,FreeRTOS命令行接口
|
||||||
|
limiter,限幅器
|
||||||
|
mixer,混控器
|
||||||
|
ui,用户交互
|
||||||
|
user_math,用户自定义数学函数
|
||||||
|
pid,PID控制器
|
|
@ -1,4 +1,4 @@
|
|||||||
bsp,can,dwt,gpio,i2c,mm,spi,uart,pwm,time
|
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
|
device,dr16,bmi088,ist8310,motor,motor_rm,motor_vesc,motor_lk,motor_lz,motor_odrive,dm_imu,servo,buzzer,led,ws2812
|
||||||
module,
|
module,
|
|
BIN
assets/User_code/device/.DS_Store
vendored
BIN
assets/User_code/device/.DS_Store
vendored
Binary file not shown.
@ -1,6 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
BMI088 陀螺仪+加速度计传感器。
|
BMI088 陀螺仪+加速度计传感器。
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Includes ----------------------------------------------------------------- */
|
/* Includes ----------------------------------------------------------------- */
|
||||||
|
@ -79,7 +79,10 @@ devices:
|
|||||||
name: "VESC 电调"
|
name: "VESC 电调"
|
||||||
description: "VESC 电调驱动"
|
description: "VESC 电调驱动"
|
||||||
dependencies:
|
dependencies:
|
||||||
bsp: ["can", "time"]
|
bsp: ["can", "time", "mm"]
|
||||||
|
component: ["user_math"]
|
||||||
|
thread_signals:
|
||||||
|
- name: "SIGNAL_VESC_DATA_REDY"
|
||||||
files:
|
files:
|
||||||
header: "motor_vesc.h"
|
header: "motor_vesc.h"
|
||||||
source: "motor_vesc.c"
|
source: "motor_vesc.c"
|
||||||
@ -88,7 +91,10 @@ devices:
|
|||||||
name: "ODrive 电机"
|
name: "ODrive 电机"
|
||||||
description: "ODrive 电机驱动"
|
description: "ODrive 电机驱动"
|
||||||
dependencies:
|
dependencies:
|
||||||
bsp: ["can", "time"]
|
bsp: ["can", "time", "mm"]
|
||||||
|
component: ["user_math"]
|
||||||
|
thread_signals:
|
||||||
|
- name: "SIGNAL_ODRIVE_DATA_REDY"
|
||||||
files:
|
files:
|
||||||
header: "motor_odrive.h"
|
header: "motor_odrive.h"
|
||||||
source: "motor_odrive.c"
|
source: "motor_odrive.c"
|
||||||
@ -97,7 +103,10 @@ devices:
|
|||||||
name: "RM 电机"
|
name: "RM 电机"
|
||||||
description: "RM 电机驱动"
|
description: "RM 电机驱动"
|
||||||
dependencies:
|
dependencies:
|
||||||
bsp: ["can", "time"]
|
bsp: ["can", "time", "mm"]
|
||||||
|
component: ["user_math"]
|
||||||
|
thread_signals:
|
||||||
|
- name: "SIGNAL_RM_MOTOR_DATA_REDY"
|
||||||
files:
|
files:
|
||||||
header: "motor_rm.h"
|
header: "motor_rm.h"
|
||||||
source: "motor_rm.c"
|
source: "motor_rm.c"
|
||||||
@ -105,6 +114,11 @@ devices:
|
|||||||
motor:
|
motor:
|
||||||
name: "通用电机"
|
name: "通用电机"
|
||||||
description: "通用电机驱动"
|
description: "通用电机驱动"
|
||||||
|
dependencies:
|
||||||
|
bsp: []
|
||||||
|
component: []
|
||||||
|
bsp_requirements: []
|
||||||
|
thread_signals: []
|
||||||
files:
|
files:
|
||||||
header: "motor.h"
|
header: "motor.h"
|
||||||
source: "motor.c"
|
source: "motor.c"
|
||||||
@ -115,11 +129,91 @@ devices:
|
|||||||
dependencies:
|
dependencies:
|
||||||
bsp: ["pwm", "time"]
|
bsp: ["pwm", "time"]
|
||||||
component: []
|
component: []
|
||||||
bsp_requirements:
|
|
||||||
- type: "pwm"
|
|
||||||
var_name: "BSP_PWM_WS2812"
|
|
||||||
description: "用于WS2812数据传输的PWM通道"
|
|
||||||
thread_signals: []
|
thread_signals: []
|
||||||
files:
|
files:
|
||||||
header: "ws2812.h"
|
header: "ws2812.h"
|
||||||
source: "ws2812.c"
|
source: "ws2812.c"
|
||||||
|
|
||||||
|
buzzer:
|
||||||
|
name: "蜂鸣器"
|
||||||
|
description: "蜂鸣器驱动"
|
||||||
|
dependencies:
|
||||||
|
bsp: ["pwm"]
|
||||||
|
component: []
|
||||||
|
bsp_requirements:
|
||||||
|
- type: "pwm"
|
||||||
|
var_name: "BSP_PWM_BUZZER"
|
||||||
|
description: "用于蜂鸣器的PWM通道"
|
||||||
|
thread_signals: []
|
||||||
|
files:
|
||||||
|
header: "buzzer.h"
|
||||||
|
source: "buzzer.c"
|
||||||
|
|
||||||
|
dm_imu:
|
||||||
|
name: "DM IMU"
|
||||||
|
description: "DM IMU 传感器"
|
||||||
|
dependencies:
|
||||||
|
bsp: ["can", "time"]
|
||||||
|
component: ["user_math"]
|
||||||
|
thread_signals:
|
||||||
|
- name: "SIGNAL_DM_IMU_DATA_REDY"
|
||||||
|
files:
|
||||||
|
header: "dm_imu.h"
|
||||||
|
source: "dm_imu.c"
|
||||||
|
|
||||||
|
led:
|
||||||
|
name: "LED 灯"
|
||||||
|
description: "LED 灯驱动"
|
||||||
|
dependencies:
|
||||||
|
bsp: ["gpio", "pwm"]
|
||||||
|
component: []
|
||||||
|
thread_signals: []
|
||||||
|
files:
|
||||||
|
header: "led.h"
|
||||||
|
source: "led.c"
|
||||||
|
|
||||||
|
motor_lk:
|
||||||
|
name: "LK 电机"
|
||||||
|
description: "LK 电机驱动"
|
||||||
|
dependencies:
|
||||||
|
bsp: ["can", "time", "mm"]
|
||||||
|
component: ["user_math"]
|
||||||
|
thread_signals:
|
||||||
|
- name: "SIGNAL_LK_MOTOR_DATA_REDY"
|
||||||
|
files:
|
||||||
|
header: "motor_lk.h"
|
||||||
|
source: "motor_lk.c"
|
||||||
|
|
||||||
|
motor_lz:
|
||||||
|
name: "LZ 电机"
|
||||||
|
description: "LZ 电机驱动"
|
||||||
|
dependencies:
|
||||||
|
bsp: ["can", "time", "mm"]
|
||||||
|
component: ["user_math"]
|
||||||
|
thread_signals:
|
||||||
|
- name: "SIGNAL_LZ_MOTOR_DATA_REDY"
|
||||||
|
files:
|
||||||
|
header: "motor_lz.h"
|
||||||
|
source: "motor_lz.c"
|
||||||
|
|
||||||
|
servo:
|
||||||
|
name: "舵机"
|
||||||
|
description: "舵机驱动"
|
||||||
|
dependencies:
|
||||||
|
bsp: ["pwm"]
|
||||||
|
component: []
|
||||||
|
thread_signals: []
|
||||||
|
files:
|
||||||
|
header: "servo.h"
|
||||||
|
source: "servo.c"
|
||||||
|
|
||||||
|
vofa:
|
||||||
|
name: "VOFA"
|
||||||
|
description: "VOFA 数据传输协议"
|
||||||
|
dependencies:
|
||||||
|
bsp: ["uart"]
|
||||||
|
component: []
|
||||||
|
thread_signals: []
|
||||||
|
files:
|
||||||
|
header: "vofa.h"
|
||||||
|
source: "vofa.c"
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
DM_IMU数据获取
|
DM_IMU数据获取(CAN)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Includes ----------------------------------------------------------------- */
|
/* Includes ----------------------------------------------------------------- */
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
IST8310 地磁传感器。
|
IST8310 地磁传感器。
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Includes ----------------------------------------------------------------- */
|
/* Includes ----------------------------------------------------------------- */
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
DR16接收机
|
电机通用函数
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Includes ----------------------------------------------------------------- */
|
/* Includes ----------------------------------------------------------------- */
|
||||||
@ -18,30 +18,18 @@
|
|||||||
/* Exported functions ------------------------------------------------------- */
|
/* Exported functions ------------------------------------------------------- */
|
||||||
float MOTOR_GetRotorAbsAngle(const MOTOR_t *motor) {
|
float MOTOR_GetRotorAbsAngle(const MOTOR_t *motor) {
|
||||||
if (motor == NULL) return DEVICE_ERR_NULL;
|
if (motor == NULL) return DEVICE_ERR_NULL;
|
||||||
if (motor->reverse) {
|
motor->feedback.rotor_abs_angle;
|
||||||
return -motor->feedback.rotor_abs_angle;
|
|
||||||
}else{
|
|
||||||
return motor->feedback.rotor_abs_angle;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float MOTOR_GetRotorSpeed(const MOTOR_t *motor) {
|
float MOTOR_GetRotorSpeed(const MOTOR_t *motor) {
|
||||||
if (motor == NULL) return DEVICE_ERR_NULL;
|
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) {
|
float MOTOR_GetTorqueCurrent(const MOTOR_t *motor) {
|
||||||
if (motor == NULL) return DEVICE_ERR_NULL;
|
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) {
|
float MOTOR_GetTemp(const MOTOR_t *motor) {
|
||||||
if (motor == NULL) return DEVICE_ERR_NULL;
|
if (motor == NULL) return DEVICE_ERR_NULL;
|
||||||
|
@ -1,10 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
灵足电机驱动
|
灵足电机驱动
|
||||||
|
|
||||||
灵足电机通信协议:
|
|
||||||
- CAN 2.0通信接口,波特率1Mbps
|
|
||||||
- 采用扩展帧格式(29位ID)
|
|
||||||
- ID格式:Bit28~24(通信类型) + Bit23~8(数据区2) + Bit7~0(目标地址)
|
|
||||||
*/
|
*/
|
||||||
/* Includes ----------------------------------------------------------------- */
|
/* Includes ----------------------------------------------------------------- */
|
||||||
#include "motor_lz.h"
|
#include "motor_lz.h"
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
CAN总线上的设备
|
Odrive电机驱动
|
||||||
将所有CAN总线上挂载的设备抽象成一个设备进行配置和控制
|
|
||||||
*/
|
*/
|
||||||
/* Includes ----------------------------------------------------------------- */
|
/* Includes ----------------------------------------------------------------- */
|
||||||
#include "motor_odrive.h"
|
#include "motor_odrive.h"
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
CAN总线上的设备
|
RM电机驱动
|
||||||
将所有CAN总线上挂载的设备抽象成一个设备进行配置和控制
|
|
||||||
*/
|
*/
|
||||||
/* Includes ----------------------------------------------------------------- */
|
/* Includes ----------------------------------------------------------------- */
|
||||||
#include "motor_rm.h"
|
#include "motor_rm.h"
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
CAN总线上的设备
|
VESC电机驱动
|
||||||
将所有CAN总线上挂载的设备抽象成一个设备进行配置和控制
|
|
||||||
*/
|
*/
|
||||||
/* Includes ----------------------------------------------------------------- */
|
/* Includes ----------------------------------------------------------------- */
|
||||||
#include "motor_vesc.h"
|
#include "motor_vesc.h"
|
||||||
|
@ -1,14 +1,10 @@
|
|||||||
/* Includes ----------------------------------------------------------------- */
|
/* Includes ----------------------------------------------------------------- */
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "vofa.h"
|
#include "device/vofa.h"
|
||||||
#include "bsp/uart.h"
|
#include "bsp/uart.h"
|
||||||
/* Private define ----------------------------------------------------------- */
|
/* Private define ----------------------------------------------------------- */
|
||||||
|
|
||||||
//#define PROTOCOL_RAWDATA
|
|
||||||
#define PROTOCOL_FIREWATER
|
|
||||||
//#define PROTOCOL_JUSTFLOAT
|
|
||||||
|
|
||||||
#define MAX_CHANNEL 64u // 根据实际最大通道数调整
|
#define MAX_CHANNEL 64u // 根据实际最大通道数调整
|
||||||
|
|
||||||
#define JUSTFLOAT_TAIL 0x7F800000
|
#define JUSTFLOAT_TAIL 0x7F800000
|
||||||
@ -16,6 +12,7 @@
|
|||||||
/* Private typedef ---------------------------------------------------------- */
|
/* Private typedef ---------------------------------------------------------- */
|
||||||
/* Private variables -------------------------------------------------------- */
|
/* Private variables -------------------------------------------------------- */
|
||||||
static uint8_t vofa_tx_buf[sizeof(float) * MAX_CHANNEL + sizeof(uint32_t)];
|
static uint8_t vofa_tx_buf[sizeof(float) * MAX_CHANNEL + sizeof(uint32_t)];
|
||||||
|
static VOFA_Protocol_t current_protocol = VOFA_PROTOCOL_FIREWATER; // ĬÈÏÐÒé
|
||||||
|
|
||||||
/* Private function -------------------------------------------------------- */
|
/* Private function -------------------------------------------------------- */
|
||||||
|
|
||||||
@ -59,19 +56,34 @@ void VOFA_JustFloat_Send(float *channels, uint8_t channel_count, bool dma)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Exported functions ------------------------------------------------------- */
|
/* Exported functions ------------------------------------------------------- */
|
||||||
init8_t VOFA_Send(float* channels, uint8_t channel_count, bool dma) {
|
int8_t VOFA_init(VOFA_Protocol_t protocol) {
|
||||||
#ifdef PROTOCOL_RAWDATA
|
current_protocol = protocol;
|
||||||
sprintf(vofa_tx_buf, "Channel1:%.2f,Channel2:%.2f\n", channels[0],channels[1]);
|
return DEVICE_OK;
|
||||||
VOFA_RawData_Send(vofa_tx_buf, dma);
|
}
|
||||||
#elif defined(PROTOCOL_FIREWATER)
|
|
||||||
VOFA_FireWater_Send(channels, channel_count, dma);
|
int8_t VOFA_Send(float* channels, uint8_t channel_count, bool dma) {
|
||||||
#elif defined(PROTOCOL_JUSTFLOAT)
|
switch (current_protocol) {
|
||||||
VOFA_JustFloat_Send(channels, channel_count, dma);
|
case VOFA_PROTOCOL_RAWDATA:
|
||||||
#else
|
{
|
||||||
// ĬÈÏʹÓÃRawDataÐÒé
|
char data[256];
|
||||||
char data[256];
|
if (channel_count >= 1) {
|
||||||
sprintf(data, "Channel1: %.2f, Channel2: %.2f\n", channels[0], channels[1]);
|
sprintf(data, "Channel1: %.2f", channels[0]);
|
||||||
VOFA_RawData_Send(data, dma);
|
if (channel_count >= 2) {
|
||||||
#endif
|
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;
|
return DEVICE_OK;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user