添加文件1和文件2

This commit is contained in:
SYW
2025-11-27 20:08:38 +08:00
parent 5d4099938c
commit edc427c423
1675 changed files with 1068907 additions and 2830 deletions
@@ -0,0 +1,33 @@
#ifndef __CToC_H
#define __CToC_H
#include "main.h"
#include "M3508.h"
#define CToC_MasterID1 0x019//ID1
#define CToC_SlaveID1 0x149//ID1
#define CToC_SlaveID2 0x189//ID2
//中断回调函数
//判断接受对象的ID-符合条件-完成解码-发送数据包
//motor_chassis:motor_measure_t 类型的数组,其中装有电机转子角度,电机转子转速,控制电流,温度
//定义函数
#define get_motor_measure(ptr, data) \
{ \
(ptr)->last_ecd = (ptr)->ecd; \
(ptr)->ecd = (uint16_t)((data)[0] << 8 | (data)[1]); \
(ptr)->speed_rpm = (uint16_t)((data)[2] << 8 | (data)[3]); \
(ptr)->given_current = (uint16_t)((data)[4] << 8 | (data)[5]); \
(ptr)->temperate = (data)[6]; \
}
extern uint8_t CToC_SlaveSendRefereeSystemData(void);
extern void can_filter_init(void);
extern void CToC_CANDataProcess(uint32_t ID,uint8_t *Data);
extern void Update_Motor_Measure(uint8_t motor_id, motor_measure_t* measure);
extern void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan);
#endif
@@ -0,0 +1,42 @@
#ifndef __M3508_H
#define __M3508_H
#include "main.h"
#include "PID.h"
// 底盘参数(根据实际机械结构调整)
#define WHEEL_RADIUS 0.075f// 轮子半径 (米)
#define WHEELBASE_WIDTH 0.21f // 轮距宽度/2 (米)
#define WHEELBASE_LENGTH 0.17f // 轮距长度/2 (米)
typedef struct
{
uint16_t ecd;//编码器值 -16384--+16384
int16_t speed_rpm;//转速 转每分钟
int16_t given_current;//输出电流值
uint8_t temperate;//电机温度
int16_t last_ecd;//上次编码器值
} motor_measure_t;
// 电机控制结构体
typedef struct {
motor_measure_t measure; // 电机测量值(速度单位:RPM)
PID_Controller_t speed_pid; // 速度环PID
float target_speed; // 目标速度 (rad/s)
} Motor_Controller_t;
extern motor_measure_t motor_chassis[4];
extern Motor_Controller_t motor_controller[4];
extern int16_t motor_commands[4];
extern void CAN_cmd_chassis(int16_t motor1, int16_t motor2, int16_t motor3, int16_t motor4);
extern float RPM_To_RadPerSec(int16_t rpm);
extern int16_t RadPerSec_To_RPM(float rad_per_sec);
extern void Set_Motor_Target_Speed(uint8_t motor_id, float target_speed_rad_s);
extern void Motor_Speed_Control_Task(float dt);
extern void Drive_Motor(float vx, float vy, float vz);
extern float Map_Remote_to_Speed(int16_t input, float max_speed);
extern void Process_Remote_Control(void);
#endif
@@ -0,0 +1,9 @@
#ifndef __RefreeSystem_H
#define __RefreeSystem_H
#include "main.h"
extern uint8_t RefereeSystem_Status;
extern uint8_t RefereeSystem_ShooterStatus;
#endif
@@ -0,0 +1,39 @@
#ifndef __Remote_H
#define __Remote_H
#include "main.h"
typedef struct
{
uint16_t Remote_R_RL;
uint16_t Remote_R_UD;
uint16_t Remote_L_RL;
uint16_t Remote_L_UD;
uint8_t Remote_LS;
uint8_t Remote_RS;
int16_t Remote_Mouse_RL;
int16_t Remote_Mouse_DU;
int16_t Remote_Mouse_Wheel;
uint8_t Remote_Mouse_KeyL;
uint8_t Remote_Mouse_KeyR;
uint8_t Remote_Key_W;
uint8_t Remote_Key_S;
uint8_t Remote_Key_A;
uint8_t Remote_Key_D;
uint8_t Remote_Key_Q;
uint8_t Remote_Key_E;
uint8_t Remote_Key_Shift;
uint8_t Remote_Key_Ctrl;
uint8_t Remote_KeyPush_Ctrl;
uint8_t Remote_KeyPush_Shift;
int16_t Remote_ThumbWheel;
}Remote_Data;
extern Remote_Data Remote_RxData;
extern uint8_t Remote_Status;
extern uint8_t Remote_StartFlag;
#endif
@@ -34,11 +34,14 @@ extern "C" {
extern CAN_HandleTypeDef hcan1;
extern CAN_HandleTypeDef hcan2;
/* USER CODE BEGIN Private defines */
/* USER CODE END Private defines */
void MX_CAN1_Init(void);
void MX_CAN2_Init(void);
/* USER CODE BEGIN Prototypes */
@@ -1,52 +0,0 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file dma.h
* @brief This file contains all the function prototypes for
* the dma.c file
******************************************************************************
* @attention
*
* Copyright (c) 2025 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __DMA_H__
#define __DMA_H__
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* DMA memory to memory transfer handles -------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* USER CODE BEGIN Private defines */
/* USER CODE END Private defines */
void MX_DMA_Init(void);
/* USER CODE BEGIN Prototypes */
/* USER CODE END Prototypes */
#ifdef __cplusplus
}
#endif
#endif /* __DMA_H__ */
+2 -27
View File
@@ -60,33 +60,8 @@ void Error_Handler(void);
/* Private defines -----------------------------------------------------------*/
/* USER CODE BEGIN Private defines */
#define DBUS_MAX_LEN (50)
#define DBUS_BUFLEN (18)
#define DBUS_HUART huart3
typedef __packed struct
{
int16_t ch0;
int16_t ch1;
int16_t ch2;
int16_t ch3;
int16_t roll;
uint8_t sw1;
uint8_t sw2;
} rc_info_t;
#define rc_Init \
{ \
0, \
0, \
0, \
0, \
0, \
0, \
0, \
}
void uart_receive_handler(UART_HandleTypeDef *huart);
void dbus_uart_init(void);
void rc_callback_handler(rc_info_t *rc, uint8_t *buff);
/* USER CODE END Private defines */
@@ -0,0 +1,22 @@
#ifndef __PID_H
#define __PID_H
#include "main.h"
typedef struct {
float kp; // ????
float ki; // ????
float kd; // ????
float integral; // ???
float prev_error; // ?????
float output; // ???
float integral_limit; // ????
float output_limit; // ????
} PID_Controller_t;
extern void PID_Init(PID_Controller_t* pid, float kp, float ki, float kd, float integral_limit, float output_limit);
extern float PID_Calculate(PID_Controller_t* pid, float error, float dt);
extern void Motor_PID_Init();
extern void PID_PositionClean(PID_Controller_t* pid);
#endif
@@ -64,7 +64,7 @@
/* #define HAL_MMC_MODULE_ENABLED */
/* #define HAL_SPI_MODULE_ENABLED */
/* #define HAL_TIM_MODULE_ENABLED */
#define HAL_UART_MODULE_ENABLED
/* #define HAL_UART_MODULE_ENABLED */
/* #define HAL_USART_MODULE_ENABLED */
/* #define HAL_IRDA_MODULE_ENABLED */
/* #define HAL_SMARTCARD_MODULE_ENABLED */
@@ -55,9 +55,8 @@ void SVC_Handler(void);
void DebugMon_Handler(void);
void PendSV_Handler(void);
void SysTick_Handler(void);
void DMA1_Stream1_IRQHandler(void);
void CAN1_RX0_IRQHandler(void);
void USART3_IRQHandler(void);
void CAN2_RX0_IRQHandler(void);
/* USER CODE BEGIN EFP */
/* USER CODE END EFP */
@@ -1,52 +0,0 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file usart.h
* @brief This file contains all the function prototypes for
* the usart.c file
******************************************************************************
* @attention
*
* Copyright (c) 2025 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __USART_H__
#define __USART_H__
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
extern UART_HandleTypeDef huart3;
/* USER CODE BEGIN Private defines */
/* USER CODE END Private defines */
void MX_USART3_UART_Init(void);
/* USER CODE BEGIN Prototypes */
/* USER CODE END Prototypes */
#ifdef __cplusplus
}
#endif
#endif /* __USART_H__ */