include.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. #ifndef __INCLUDE_H
  2. #define __INCLUDE_H
  3. #include "stm32f4xx.h"
  4. //结构体
  5. typedef struct
  6. {
  7. float time_lime;
  8. float max_current_lime;
  9. float high_speed_mag;
  10. float low_speed_mag;
  11. float dividi_rpm;
  12. }PROTECT_PARAMETERS;
  13. typedef struct
  14. {
  15. float P;
  16. float I;
  17. float D;
  18. }PID_PARAMETERS;
  19. typedef struct
  20. {
  21. u8 buff[10];
  22. u8 buff_cnt;
  23. u16 rpm; //串口读取的转速(乘以一定公式)
  24. float temperature; //串口读取的电调温度
  25. float voltage; //串口读取的电调电压
  26. float consumption; //功率
  27. }USART_DATA;
  28. typedef struct
  29. {
  30. s16 aim_speed; //目标pwm
  31. s16 new_speed;
  32. s16 last_aim;
  33. float err;
  34. float last_err;
  35. float pret_err;
  36. float integral;
  37. s16 pwm;
  38. s16 dshot_pwm;
  39. u32 dshot_data[18];
  40. }PID_DATA;
  41. typedef struct
  42. {
  43. s8 stop_flag;
  44. u8 stall;
  45. u8 overload; //过载次数
  46. u16 stall_cnt;
  47. u16 normal_cnt;
  48. u16 unormal_cnt;
  49. u8 stall_err; //堵转异常标志位
  50. }STALL_PROTECT_DATA;
  51. typedef struct
  52. {
  53. u8 block_err; //缠绕标志位
  54. s8 speed_lim; //功率输出削弱参数
  55. u16 block_cnt; //缠绕累计值
  56. u16 twin_cnt;
  57. u32 avg_sum; //计算平均电流时的累计ADC值
  58. float STcurrent; //根据转速获取的标准电流
  59. double current; //ADC检测的实际电流
  60. double current_correct;
  61. }TWIN_PROTECT_DATA;
  62. typedef struct
  63. {
  64. u8 numble; //编号
  65. PID_DATA pid_data; //PID用数据
  66. USART_DATA usart_data;
  67. TWIN_PROTECT_DATA twin_data;
  68. STALL_PROTECT_DATA stal_data;
  69. }MOTOR;
  70. //头文件
  71. #include "delay.h"
  72. #include "dshot.h"
  73. #include "iwag.h"
  74. #include "time.h"
  75. #include "adc.h"
  76. #include "usart.h"
  77. #include "can.h"
  78. #include "led.h"
  79. #include "flash.h"
  80. #include "delay.h"
  81. #include "ntc.h"
  82. //全局变量
  83. #ifdef __GLOBALS__
  84. #define EXT
  85. #else
  86. #define EXT extern
  87. #endif
  88. EXT u8 Updata_requre;
  89. EXT u8 Pixhawk_requre;
  90. EXT u16 light_pwm;
  91. EXT u16 usbl_opendown;
  92. //电机堵转标识
  93. EXT u16 Motor_err_flag;
  94. EXT u8 DMA400Finishi;
  95. EXT float temperature;
  96. EXT float Voltage;
  97. EXT u32 Voltage_sum;
  98. //推进器和履带电机结构体
  99. EXT MOTOR left_thruster;
  100. EXT MOTOR right_thruster;
  101. EXT MOTOR left_track_motor;
  102. EXT MOTOR right_track_motor;
  103. //左右履带转向
  104. EXT s32 left_trank_direction;
  105. EXT s32 right_trank_direction;
  106. //PID
  107. EXT PID_PARAMETERS track_PID;
  108. //堵转参数
  109. EXT PROTECT_PARAMETERS protect_parameters;
  110. //宏
  111. #define max(x,y) (x>y?x:y)
  112. #define min(x,y) (x<y?x:y)
  113. //PB6 右推进器
  114. #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);
  115. //PB7 右履带
  116. #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)
  117. //PA7 左推进器
  118. #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)
  119. //PA5 左履带
  120. #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)
  121. #define LED_ON GPIO_SetBits(GPIOF, GPIO_Pin_0)
  122. #define LED_OFF GPIO_ResetBits(GPIOF, GPIO_Pin_0)
  123. #define LED_TURN GPIO_ToggleBits(GPIOF, GPIO_Pin_0)
  124. #define USBL_ON GPIO_SetBits(GPIOA, GPIO_Pin_15)
  125. #define USBL_OFF GPIO_ResetBits(GPIOA, GPIO_Pin_15)
  126. #define USBL_TURN GPIO_ToggleBits(GPIOA, GPIO_Pin_15)
  127. #define LIGHT_ON GPIO_SetBits(GPIOF, GPIO_Pin_15)
  128. #define LIGHT_OFF GPIO_ResetBits(GPIOF, GPIO_Pin_15)
  129. #define LIGHT_TURN GPIO_ToggleBits(GPIOF, GPIO_Pin_15)
  130. void SoftReset(void);
  131. void ADC_Config(void);
  132. void LED_Config(void);
  133. void CAN_Config(void);
  134. void TIM_Config(void);
  135. void USBL_Config(void);
  136. void Dshot_Config(void);
  137. void Light_Config(void);
  138. void USART_Config(void);
  139. void All_motor_Config(void);
  140. void Single_Motor_Config(MOTOR *motor,u8 num);
  141. void Motor_AD_correct(void);
  142. void Motor_Stall_check(void);
  143. void AnaMotorData(MOTOR *Motor);
  144. u16 GetDShotValue(int16_t value, int8_t lime);
  145. void GetMotorData(USART_TypeDef* USARTx, MOTOR *Motor);
  146. void Motor_Control(MOTOR* Motor,PID_PARAMETERS* MotorPID, u8 usePID);
  147. void Send_Updata_requre(void);
  148. void Send_Pixhawk_requre(void);
  149. void SysTick_10ms_Task(void);
  150. void SysTick_20ms_Task(void);
  151. void SysTick_100ms_Task(void);
  152. void SysTick_500ms_Task(void);
  153. void Other_Task(void);
  154. extern u8 hv_motor1_data[8];
  155. extern u8 hv_motor2_data[8];
  156. extern u8 hv_motor3_data[8];
  157. #endif