123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- #ifndef __INCLUDE_H
- #define __INCLUDE_H
- #include "stm32f4xx.h"
- //结构体
- typedef struct
- {
- float time_lime;
- float max_current_lime;
- float high_speed_mag;
- float low_speed_mag;
- float dividi_rpm;
- }PROTECT_PARAMETERS;
- typedef struct
- {
- float P;
- float I;
- float D;
- }PID_PARAMETERS;
- typedef struct
- {
- u8 buff[10];
- u8 buff_cnt;
- u16 rpm; //串口读取的转速(乘以一定公式)
- float temperature; //串口读取的电调温度
- float voltage; //串口读取的电调电压
- float consumption; //功率
- }USART_DATA;
- typedef struct
- {
- s16 aim_speed; //目标pwm
- s16 new_speed;
- s16 last_aim;
- float err;
- float last_err;
- float pret_err;
- float integral;
- s16 pwm;
- s16 dshot_pwm;
- u32 dshot_data[18];
- }PID_DATA;
- typedef struct
- {
- s8 stop_flag;
- u8 stall;
- u8 overload; //过载次数
- u16 stall_cnt;
- u16 normal_cnt;
- u16 unormal_cnt;
- u8 stall_err; //堵转异常标志位
- }STALL_PROTECT_DATA;
- typedef struct
- {
- u8 block_err; //缠绕标志位
- s8 speed_lim; //功率输出削弱参数
- u16 block_cnt; //缠绕累计值
- u16 twin_cnt;
- u32 avg_sum; //计算平均电流时的累计ADC值
- float STcurrent; //根据转速获取的标准电流
- double current; //ADC检测的实际电流
- double current_correct;
- }TWIN_PROTECT_DATA;
- typedef struct
- {
- u8 numble; //编号
- PID_DATA pid_data; //PID用数据
- USART_DATA usart_data;
- TWIN_PROTECT_DATA twin_data;
- STALL_PROTECT_DATA stal_data;
- }MOTOR;
- //头文件
- #include "delay.h"
- #include "dshot.h"
- #include "iwag.h"
- #include "time.h"
- #include "adc.h"
- #include "usart.h"
- #include "can.h"
- #include "led.h"
- #include "flash.h"
- #include "delay.h"
- #include "ntc.h"
- //全局变量
- #ifdef __GLOBALS__
- #define EXT
- #else
- #define EXT extern
- #endif
- EXT u8 Updata_requre;
- EXT u8 Pixhawk_requre;
- EXT u16 light_pwm;
- EXT u16 usbl_opendown;
- //电机堵转标识
- EXT u16 Motor_err_flag;
- EXT u8 DMA400Finishi;
- EXT float temperature;
- EXT float Voltage;
- EXT u32 Voltage_sum;
- //推进器和履带电机结构体
- EXT MOTOR left_thruster;
- EXT MOTOR right_thruster;
- EXT MOTOR left_track_motor;
- EXT MOTOR right_track_motor;
- //左右履带转向
- EXT s32 left_trank_direction;
- EXT s32 right_trank_direction;
- //PID
- EXT PID_PARAMETERS track_PID;
- //堵转参数
- EXT PROTECT_PARAMETERS protect_parameters;
- //宏
- #define max(x,y) (x>y?x:y)
- #define min(x,y) (x<y?x:y)
- //PB6 右推进器
- #define RThruster_DSHOT_DMA_Config() DSHOT_DMA_Config(TIM4,TIM_DMA_CC1,DMA1_Stream0,DMA_Channel_2,(uint32_t)&(TIM4->CCR1),(uint32_t)right_thruster.pid_data.dshot_data);
- //PB7 右履带
- #define RTrack_DSHOT_DMA_Config() DSHOT_DMA_Config(TIM4,TIM_DMA_CC2,DMA1_Stream3,DMA_Channel_2,(uint32_t)&(TIM4->CCR2),(uint32_t)right_track_motor.pid_data.dshot_data)
- //PA7 左推进器
- #define LThruster_DSHOT_DMA_Config() DSHOT_DMA_Config(TIM3,TIM_DMA_CC2,DMA1_Stream5,DMA_Channel_5,(uint32_t)&(TIM3->CCR2),(uint32_t)left_thruster.pid_data.dshot_data)
- //PA5 左履带
- #define LTrack_DSHOT_DMA_Config() DSHOT_DMA_Config(TIM2,TIM_DMA_CC1,DMA1_Stream5,DMA_Channel_3,(uint32_t)&(TIM2->CCR1),(uint32_t)left_track_motor.pid_data.dshot_data)
- #define LED_ON GPIO_SetBits(GPIOF, GPIO_Pin_0)
- #define LED_OFF GPIO_ResetBits(GPIOF, GPIO_Pin_0)
- #define LED_TURN GPIO_ToggleBits(GPIOF, GPIO_Pin_0)
-
- #define USBL_ON GPIO_SetBits(GPIOA, GPIO_Pin_15)
- #define USBL_OFF GPIO_ResetBits(GPIOA, GPIO_Pin_15)
- #define USBL_TURN GPIO_ToggleBits(GPIOA, GPIO_Pin_15)
- #define LIGHT_ON GPIO_SetBits(GPIOF, GPIO_Pin_15)
- #define LIGHT_OFF GPIO_ResetBits(GPIOF, GPIO_Pin_15)
- #define LIGHT_TURN GPIO_ToggleBits(GPIOF, GPIO_Pin_15)
- void SoftReset(void);
- void ADC_Config(void);
- void LED_Config(void);
- void CAN_Config(void);
- void TIM_Config(void);
- void USBL_Config(void);
- void Dshot_Config(void);
- void Light_Config(void);
- void USART_Config(void);
- void All_motor_Config(void);
- void Single_Motor_Config(MOTOR *motor,u8 num);
- void Motor_AD_correct(void);
- void Motor_Stall_check(void);
- void AnaMotorData(MOTOR *Motor);
- u16 GetDShotValue(int16_t value, int8_t lime);
- void GetMotorData(USART_TypeDef* USARTx, MOTOR *Motor);
- void Motor_Control(MOTOR* Motor,PID_PARAMETERS* MotorPID, u8 usePID);
- void Send_Updata_requre(void);
- void Send_Pixhawk_requre(void);
- void SysTick_10ms_Task(void);
- void SysTick_20ms_Task(void);
- void SysTick_100ms_Task(void);
- void SysTick_500ms_Task(void);
- void Other_Task(void);
- extern u8 hv_motor1_data[8];
- extern u8 hv_motor2_data[8];
- extern u8 hv_motor3_data[8];
- #endif
|