include.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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 "iwag.h"
  73. #include "adc.h"
  74. #include "time.h"
  75. #include "can.h"
  76. #include "led.h"
  77. #include "usart.h"
  78. #include "delay.h"
  79. #include "ntc.h"
  80. //全局变量
  81. #ifdef __GLOBALS__
  82. #define EXT
  83. #else
  84. #define EXT extern
  85. #endif
  86. EXT uint16_t Rntc;
  87. EXT u8 Updata_requre;
  88. EXT u8 Pixhawk_requre;
  89. //电机堵转标识
  90. EXT u16 Motor_err_flag;
  91. EXT u8 DMA400Finishi;
  92. EXT float temperature_board;
  93. EXT float Voltage;
  94. EXT u32 Voltage_sum;
  95. //推进器和履带电机结构体
  96. EXT MOTOR left_thruster;
  97. EXT MOTOR right_thruster;
  98. EXT MOTOR left_track_motor;
  99. EXT MOTOR right_track_motor;
  100. //左右履带转向
  101. EXT s32 left_trank_direction;
  102. EXT s32 right_trank_direction;
  103. //PID
  104. EXT PID_PARAMETERS track_PID;
  105. //堵转参数
  106. EXT PROTECT_PARAMETERS protect_parameters;
  107. //宏
  108. #define max(x,y) (x>y?x:y)
  109. #define min(x,y) (x<y?x:y)
  110. //PB6 右推进器
  111. #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);
  112. //PB7 右履带
  113. #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)
  114. //PA7 左推进器
  115. #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)
  116. //PA5 左履带
  117. #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)
  118. #define LED_ON GPIO_SetBits(GPIOF, GPIO_Pin_0)
  119. #define LED_OFF GPIO_ResetBits(GPIOF, GPIO_Pin_0)
  120. #define LED_TURN GPIO_ToggleBits(GPIOF, GPIO_Pin_0)
  121. #define USBL_ON GPIO_SetBits(GPIOB, GPIO_Pin_14)
  122. #define USBL_OFF GPIO_ResetBits(GPIOB, GPIO_Pin_14)
  123. #define USBL_TURN GPIO_ToggleBits(GPIOB, GPIO_Pin_14)
  124. //两线大灯
  125. #define BIG_LIGHT_ON GPIO_SetBits(GPIOD, GPIO_Pin_2)
  126. #define BIG_LIGHT_OFF GPIO_ResetBits(GPIOD, GPIO_Pin_2)
  127. #define BIG_LIGHT_TURN GPIO_ToggleBits(GPIOD, GPIO_Pin_2)
  128. //三线小灯
  129. #define SMG_LIGHT_ON GPIO_SetBits(GPIOB, GPIO_Pin_15)
  130. #define SMG_LIGHT_OFF GPIO_ResetBits(GPIOB, GPIO_Pin_15)
  131. #define SMG_LIGHT_TURN GPIO_ToggleBits(GPIOB, GPIO_Pin_15)
  132. #define Read_BIG_LIGHT GPIO_ReadInputDataBit(GPIOG, GPIO_Pin_11)
  133. #define Read_SMG_LIGHT GPIO_ReadInputDataBit(GPIOG, GPIO_Pin_0)
  134. #define Read_USBL GPIO_ReadInputDataBit(GPIOG, GPIO_Pin_1)
  135. #define Read_CAMERA1 GPIO_ReadInputDataBit(GPIOG, GPIO_Pin_10)
  136. #define Read_CAMERA2 GPIO_ReadInputDataBit(GPIOG, GPIO_Pin_9)
  137. #define Read_CAMERA3 GPIO_ReadInputDataBit(GPIOF, GPIO_Pin_15)
  138. #define Read_CAMERA4 GPIO_ReadInputDataBit(GPIOF, GPIO_Pin_14)
  139. #define Read_MOTOR2 GPIO_ReadInputDataBit(GPIOG, GPIO_Pin_13)
  140. #define Read_MOTOR1 GPIO_ReadInputDataBit(GPIOG, GPIO_Pin_12)
  141. #define CUT_BIG_LIGHT GPIO_ResetBits(GPIOD, GPIO_Pin_2)
  142. #define CUT_SMG_LIGHT GPIO_ResetBits(GPIOB, GPIO_Pin_15)
  143. #define CUT_USBL GPIO_ResetBits(GPIOB, GPIO_Pin_14)
  144. #define CUT_CAMERA1 GPIO_ResetBits(GPIOD, GPIO_Pin_1)
  145. #define CUT_CAMERA2 GPIO_ResetBits(GPIOD, GPIO_Pin_0)
  146. #define CUT_CAMERA3 GPIO_ResetBits(GPIOB, GPIO_Pin_12)
  147. #define CUT_CAMERA4 GPIO_ResetBits(GPIOB, GPIO_Pin_13)
  148. #define CUT_Motor2 GPIO_ResetBits(GPIOD, GPIO_Pin_4)
  149. #define CUT_Motor1 GPIO_ResetBits(GPIOD, GPIO_Pin_3)
  150. void SoftReset(void);
  151. void ADC_Config(void);
  152. void LED_Config(void);
  153. void CAN_Config(void);
  154. void TIM_Config(void);
  155. void USBL_Config(void);
  156. void Dshot_Config(void);
  157. void Light_Config(void);
  158. void USART_Config(void);
  159. void All_motor_Config(void);
  160. void Single_Motor_Config(MOTOR *motor,u8 num);
  161. void Overcurrent_Detection_Config(void);
  162. void Motor_AD_correct(void);
  163. void Motor_Stall_check(void);
  164. void AnaMotorData(MOTOR *Motor);
  165. u16 GetDShotValue(int16_t value, int8_t lime);
  166. void GetMotorData(USART_TypeDef* USARTx, MOTOR *Motor);
  167. void Motor_Control(MOTOR* Motor,PID_PARAMETERS* MotorPID, u8 usePID);
  168. void Send_Updata_requre(void);
  169. void Send_Pixhawk_requre(void);
  170. void SysTick_10ms_Task(void);
  171. void SysTick_20ms_Task(void);
  172. void SysTick_100ms_Task(void);
  173. void SysTick_500ms_Task(void);
  174. void Other_Task(void);
  175. extern u8 hv_motor1_data[8];
  176. extern u8 hv_motor2_data[8];
  177. extern u8 hv_motor3_data[8];
  178. void USART_Config(void);
  179. #endif