include.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. u16 dshot_limit;
  41. }PID_DATA;
  42. typedef struct
  43. {
  44. s8 stop_flag;
  45. u8 stall;
  46. u8 overload; //过载次数
  47. u16 stall_cnt;
  48. u16 normal_cnt;
  49. u16 unormal_cnt;
  50. u8 stall_err; //堵转异常标志位
  51. }STALL_PROTECT_DATA;
  52. typedef struct
  53. {
  54. u8 block_err; //缠绕标志位
  55. s8 speed_lim; //功率输出削弱参数
  56. u16 block_cnt; //缠绕累计值
  57. u16 twin_cnt;
  58. u32 avg_sum; //计算平均电流时的累计ADC值
  59. float STcurrent; //根据转速获取的标准电流
  60. double current; //ADC检测的实际电流
  61. double current_correct;
  62. }TWIN_PROTECT_DATA;
  63. typedef struct
  64. {
  65. u8 numble; //编号
  66. PID_DATA pid_data; //PID用数据
  67. USART_DATA usart_data;
  68. TWIN_PROTECT_DATA twin_data;
  69. STALL_PROTECT_DATA stal_data;
  70. }MOTOR;
  71. //头文件
  72. #include "delay.h"
  73. #include "dshot.h"
  74. #include "iwag.h"
  75. #include "time.h"
  76. #include "adc.h"
  77. #include "usart.h"
  78. #include "can.h"
  79. #include "led.h"
  80. #include "flash.h"
  81. #include "delay.h"
  82. #include "ntc.h"
  83. //全局变量
  84. #ifdef __GLOBALS__
  85. #define EXT
  86. #else
  87. #define EXT extern
  88. #endif
  89. EXT u8 Updata_requre;
  90. EXT u8 Pixhawk_requre;
  91. EXT u16 light_pwm;
  92. EXT u8 light_err;
  93. EXT u16 usbl_opendown;
  94. EXT u8 usbl_err;
  95. //电机堵转标识
  96. EXT u16 Motor_err_flag;
  97. EXT u8 DMA400Finishi;
  98. EXT float temperature;
  99. EXT float Voltage;
  100. EXT u32 Voltage_sum;
  101. EXT u32 humidity;
  102. EXT u32 humidity_sum;
  103. EXT u8 humidity_err;
  104. //推进器和履带电机结构体
  105. EXT MOTOR left_thruster;
  106. EXT MOTOR right_thruster;
  107. EXT MOTOR left_track_motor;
  108. EXT MOTOR right_track_motor;
  109. //左右履带转向
  110. EXT s32 left_trank_direction;
  111. EXT s32 right_trank_direction;
  112. //PID
  113. EXT PID_PARAMETERS track_PID;
  114. //堵转参数
  115. EXT PROTECT_PARAMETERS protect_parameters;
  116. //宏
  117. #define max(x,y) (x>y?x:y)
  118. #define min(x,y) (x<y?x:y)
  119. //PB6 右推进器
  120. #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);
  121. //PB7 右履带
  122. #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)
  123. //PA7 左推进器
  124. #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)
  125. //PA5 左履带
  126. #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)
  127. #define LED_ON GPIO_SetBits(GPIOF, GPIO_Pin_0)
  128. #define LED_OFF GPIO_ResetBits(GPIOF, GPIO_Pin_0)
  129. #define LED_TURN GPIO_ToggleBits(GPIOF, GPIO_Pin_0)
  130. #define USBL_ON GPIO_SetBits(GPIOA, GPIO_Pin_15)
  131. #define USBL_OFF GPIO_ResetBits(GPIOA, GPIO_Pin_15)
  132. #define USBL_TURN GPIO_ToggleBits(GPIOA, GPIO_Pin_15)
  133. #define LIGHT_ON GPIO_SetBits(GPIOF, GPIO_Pin_15)
  134. #define LIGHT_OFF GPIO_ResetBits(GPIOF, GPIO_Pin_15)
  135. #define LIGHT_TURN GPIO_ToggleBits(GPIOF, GPIO_Pin_15)
  136. #define Read_LIGHT GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_9)
  137. #define Read_USBL GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_8)
  138. #define Read_VIDEO GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_2)
  139. #define CUT_LIGHT GPIO_ResetBits(GPIOF, GPIO_Pin_15)
  140. #define CUT_USBL GPIO_ResetBits(GPIOA, GPIO_Pin_15)
  141. #define CUT_VIDEO GPIO_ResetBits(GPIOA, GPIO_Pin_1)
  142. void SoftReset(void);
  143. void ADC_Config(void);
  144. void LED_Config(void);
  145. void CAN_Config(void);
  146. void TIM_Config(void);
  147. void USBL_Config(void);
  148. void Dshot_Config(void);
  149. void Light_Config(void);
  150. void USART_Config(void);
  151. void All_motor_Config(void);
  152. void Single_Motor_Config(MOTOR *motor,u8 num);
  153. void Motor_AD_correct(void);
  154. void Motor_Stall_check(void);
  155. void AnaMotorData(MOTOR *Motor);
  156. u16 GetDShotValue(int16_t value, int8_t lime);
  157. void GetMotorData(USART_TypeDef* USARTx, MOTOR *Motor);
  158. void Motor_Control(MOTOR* Motor,PID_PARAMETERS* MotorPID, u8 usePID);
  159. void Send_Updata_requre(void);
  160. void Send_Pixhawk_requre(void);
  161. void SysTick_1ms_Task(void);
  162. void SysTick_10ms_Task(void);
  163. void SysTick_20ms_Task(void);
  164. void SysTick_100ms_Task(void);
  165. void SysTick_500ms_Task(void);
  166. void Other_Task(void);
  167. void Overcurrent_Detection_Config(void);
  168. extern u8 hv_motor1_data[8];
  169. extern u8 hv_motor2_data[8];
  170. extern u8 hv_motor3_data[8];
  171. #endif