From 5abffb4cd18b8569c601ac1dfe3b91571ccf6c99 Mon Sep 17 00:00:00 2001
From: Robofish <1683502971@qq.com>
Date: Mon, 29 Sep 2025 03:35:01 +0800
Subject: [PATCH] shoot
---
CMakeLists.txt | 5 +
Core/Src/stm32f4xx_it.c | 1030 +++++++++++++++++++-------------------
User/bsp/bsp_config.yaml | 4 +-
User/bsp/uart.c | 8 +-
User/bsp/uart.h | 2 +-
User/module/config.c | 54 ++
User/module/config.h | 30 ++
User/module/gimbal.c | 0
User/module/gimbal.h | 0
User/module/shoot.c | 201 ++++++++
User/module/shoot.h | 176 +++++++
User/task/monitor.c | 14 +-
User/task/rc.c | 13 +-
debug.jdebug | 361 +++++++++++++
14 files changed, 1367 insertions(+), 531 deletions(-)
create mode 100644 User/module/config.c
create mode 100644 User/module/config.h
create mode 100644 User/module/gimbal.c
create mode 100644 User/module/gimbal.h
create mode 100644 User/module/shoot.c
create mode 100644 User/module/shoot.h
create mode 100644 debug.jdebug
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b4401dd..ec9e9fe 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -70,6 +70,11 @@ target_sources(${CMAKE_PROJECT_NAME} PRIVATE
User/device/motor.c
User/device/motor_rm.c
+ # User/module sources
+ User/module/config.c
+ User/module/gimbal.c
+ User/module/shoot.c
+
# User/task sources
User/task/ai.c
User/task/atti_esti.c
diff --git a/Core/Src/stm32f4xx_it.c b/Core/Src/stm32f4xx_it.c
index 200488b..3baef83 100644
--- a/Core/Src/stm32f4xx_it.c
+++ b/Core/Src/stm32f4xx_it.c
@@ -1,515 +1,515 @@
-/* USER CODE BEGIN Header */
-/**
- ******************************************************************************
- * @file stm32f4xx_it.c
- * @brief Interrupt Service Routines.
- ******************************************************************************
- * @attention
- *
- *
© Copyright (c) 2025 STMicroelectronics.
- * All rights reserved.
- *
- * This software component is licensed by ST under Ultimate Liberty license
- * SLA0044, the "License"; You may not use this file except in compliance with
- * the License. You may obtain a copy of the License at:
- * www.st.com/SLA0044
- *
- ******************************************************************************
- */
-/* USER CODE END Header */
-
-/* Includes ------------------------------------------------------------------*/
-#include "main.h"
-#include "stm32f4xx_it.h"
-#include "FreeRTOS.h"
-#include "task.h"
-/* Private includes ----------------------------------------------------------*/
-/* USER CODE BEGIN Includes */
-#include "bsp/uart.h"
-/* USER CODE END Includes */
-
-/* Private typedef -----------------------------------------------------------*/
-/* USER CODE BEGIN TD */
-
-/* USER CODE END TD */
-
-/* Private define ------------------------------------------------------------*/
-/* USER CODE BEGIN PD */
-
-/* USER CODE END PD */
-
-/* Private macro -------------------------------------------------------------*/
-/* USER CODE BEGIN PM */
-
-/* USER CODE END PM */
-
-/* Private variables ---------------------------------------------------------*/
-/* USER CODE BEGIN PV */
-
-/* USER CODE END PV */
-
-/* Private function prototypes -----------------------------------------------*/
-/* USER CODE BEGIN PFP */
-
-/* USER CODE END PFP */
-
-/* Private user code ---------------------------------------------------------*/
-/* USER CODE BEGIN 0 */
-
-/* USER CODE END 0 */
-
-/* External variables --------------------------------------------------------*/
-extern PCD_HandleTypeDef hpcd_USB_OTG_FS;
-extern CAN_HandleTypeDef hcan1;
-extern CAN_HandleTypeDef hcan2;
-extern DMA_HandleTypeDef hdma_i2c2_tx;
-extern DMA_HandleTypeDef hdma_i2c3_rx;
-extern DMA_HandleTypeDef hdma_spi1_rx;
-extern DMA_HandleTypeDef hdma_spi1_tx;
-extern TIM_HandleTypeDef htim1;
-extern TIM_HandleTypeDef htim7;
-extern DMA_HandleTypeDef hdma_usart1_tx;
-extern DMA_HandleTypeDef hdma_usart1_rx;
-extern DMA_HandleTypeDef hdma_usart3_rx;
-extern DMA_HandleTypeDef hdma_usart6_rx;
-extern DMA_HandleTypeDef hdma_usart6_tx;
-extern UART_HandleTypeDef huart1;
-extern UART_HandleTypeDef huart6;
-/* USER CODE BEGIN EV */
-
-/* USER CODE END EV */
-
-/******************************************************************************/
-/* Cortex-M4 Processor Interruption and Exception Handlers */
-/******************************************************************************/
-/**
- * @brief This function handles Non maskable interrupt.
- */
-void NMI_Handler(void)
-{
- /* USER CODE BEGIN NonMaskableInt_IRQn 0 */
-
- /* USER CODE END NonMaskableInt_IRQn 0 */
- /* USER CODE BEGIN NonMaskableInt_IRQn 1 */
- while (1)
- {
- }
- /* USER CODE END NonMaskableInt_IRQn 1 */
-}
-
-/**
- * @brief This function handles Hard fault interrupt.
- */
-void HardFault_Handler(void)
-{
- /* USER CODE BEGIN HardFault_IRQn 0 */
-
- /* USER CODE END HardFault_IRQn 0 */
- while (1)
- {
- /* USER CODE BEGIN W1_HardFault_IRQn 0 */
- /* USER CODE END W1_HardFault_IRQn 0 */
- }
-}
-
-/**
- * @brief This function handles Memory management fault.
- */
-void MemManage_Handler(void)
-{
- /* USER CODE BEGIN MemoryManagement_IRQn 0 */
-
- /* USER CODE END MemoryManagement_IRQn 0 */
- while (1)
- {
- /* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */
- /* USER CODE END W1_MemoryManagement_IRQn 0 */
- }
-}
-
-/**
- * @brief This function handles Pre-fetch fault, memory access fault.
- */
-void BusFault_Handler(void)
-{
- /* USER CODE BEGIN BusFault_IRQn 0 */
-
- /* USER CODE END BusFault_IRQn 0 */
- while (1)
- {
- /* USER CODE BEGIN W1_BusFault_IRQn 0 */
- /* USER CODE END W1_BusFault_IRQn 0 */
- }
-}
-
-/**
- * @brief This function handles Undefined instruction or illegal state.
- */
-void UsageFault_Handler(void)
-{
- /* USER CODE BEGIN UsageFault_IRQn 0 */
-
- /* USER CODE END UsageFault_IRQn 0 */
- while (1)
- {
- /* USER CODE BEGIN W1_UsageFault_IRQn 0 */
- /* USER CODE END W1_UsageFault_IRQn 0 */
- }
-}
-
-/**
- * @brief This function handles Debug monitor.
- */
-void DebugMon_Handler(void)
-{
- /* USER CODE BEGIN DebugMonitor_IRQn 0 */
-
- /* USER CODE END DebugMonitor_IRQn 0 */
- /* USER CODE BEGIN DebugMonitor_IRQn 1 */
-
- /* USER CODE END DebugMonitor_IRQn 1 */
-}
-
-/**
- * @brief This function handles System tick timer.
- */
-void SysTick_Handler(void)
-{
- /* USER CODE BEGIN SysTick_IRQn 0 */
-
- /* USER CODE END SysTick_IRQn 0 */
- HAL_IncTick();
-#if (INCLUDE_xTaskGetSchedulerState == 1 )
- if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED)
- {
-#endif /* INCLUDE_xTaskGetSchedulerState */
- xPortSysTickHandler();
-#if (INCLUDE_xTaskGetSchedulerState == 1 )
- }
-#endif /* INCLUDE_xTaskGetSchedulerState */
- /* USER CODE BEGIN SysTick_IRQn 1 */
-
- /* USER CODE END SysTick_IRQn 1 */
-}
-
-/******************************************************************************/
-/* STM32F4xx Peripheral Interrupt Handlers */
-/* Add here the Interrupt Handlers for the used peripherals. */
-/* For the available peripheral interrupt handler names, */
-/* please refer to the startup file (startup_stm32f4xx.s). */
-/******************************************************************************/
-
-/**
- * @brief This function handles EXTI line0 interrupt.
- */
-void EXTI0_IRQHandler(void)
-{
- /* USER CODE BEGIN EXTI0_IRQn 0 */
-
- /* USER CODE END EXTI0_IRQn 0 */
- HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_0);
- /* USER CODE BEGIN EXTI0_IRQn 1 */
-
- /* USER CODE END EXTI0_IRQn 1 */
-}
-
-/**
- * @brief This function handles EXTI line3 interrupt.
- */
-void EXTI3_IRQHandler(void)
-{
- /* USER CODE BEGIN EXTI3_IRQn 0 */
-
- /* USER CODE END EXTI3_IRQn 0 */
- HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_3);
- /* USER CODE BEGIN EXTI3_IRQn 1 */
-
- /* USER CODE END EXTI3_IRQn 1 */
-}
-
-/**
- * @brief This function handles EXTI line4 interrupt.
- */
-void EXTI4_IRQHandler(void)
-{
- /* USER CODE BEGIN EXTI4_IRQn 0 */
-
- /* USER CODE END EXTI4_IRQn 0 */
- HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_4);
- /* USER CODE BEGIN EXTI4_IRQn 1 */
-
- /* USER CODE END EXTI4_IRQn 1 */
-}
-
-/**
- * @brief This function handles DMA1 stream1 global interrupt.
- */
-void DMA1_Stream1_IRQHandler(void)
-{
- /* USER CODE BEGIN DMA1_Stream1_IRQn 0 */
-
- /* USER CODE END DMA1_Stream1_IRQn 0 */
- HAL_DMA_IRQHandler(&hdma_usart3_rx);
- /* USER CODE BEGIN DMA1_Stream1_IRQn 1 */
-
- /* USER CODE END DMA1_Stream1_IRQn 1 */
-}
-
-/**
- * @brief This function handles DMA1 stream2 global interrupt.
- */
-void DMA1_Stream2_IRQHandler(void)
-{
- /* USER CODE BEGIN DMA1_Stream2_IRQn 0 */
-
- /* USER CODE END DMA1_Stream2_IRQn 0 */
- HAL_DMA_IRQHandler(&hdma_i2c3_rx);
- /* USER CODE BEGIN DMA1_Stream2_IRQn 1 */
-
- /* USER CODE END DMA1_Stream2_IRQn 1 */
-}
-
-/**
- * @brief This function handles CAN1 RX0 interrupts.
- */
-void CAN1_RX0_IRQHandler(void)
-{
- /* USER CODE BEGIN CAN1_RX0_IRQn 0 */
-
- /* USER CODE END CAN1_RX0_IRQn 0 */
- HAL_CAN_IRQHandler(&hcan1);
- /* USER CODE BEGIN CAN1_RX0_IRQn 1 */
-
- /* USER CODE END CAN1_RX0_IRQn 1 */
-}
-
-/**
- * @brief This function handles CAN1 RX1 interrupt.
- */
-void CAN1_RX1_IRQHandler(void)
-{
- /* USER CODE BEGIN CAN1_RX1_IRQn 0 */
-
- /* USER CODE END CAN1_RX1_IRQn 0 */
- HAL_CAN_IRQHandler(&hcan1);
- /* USER CODE BEGIN CAN1_RX1_IRQn 1 */
-
- /* USER CODE END CAN1_RX1_IRQn 1 */
-}
-
-/**
- * @brief This function handles EXTI line[9:5] interrupts.
- */
-void EXTI9_5_IRQHandler(void)
-{
- /* USER CODE BEGIN EXTI9_5_IRQn 0 */
-
- /* USER CODE END EXTI9_5_IRQn 0 */
- HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_5);
- /* USER CODE BEGIN EXTI9_5_IRQn 1 */
-
- /* USER CODE END EXTI9_5_IRQn 1 */
-}
-
-/**
- * @brief This function handles TIM1 break interrupt and TIM9 global interrupt.
- */
-void TIM1_BRK_TIM9_IRQHandler(void)
-{
- /* USER CODE BEGIN TIM1_BRK_TIM9_IRQn 0 */
-
- /* USER CODE END TIM1_BRK_TIM9_IRQn 0 */
- HAL_TIM_IRQHandler(&htim1);
- /* USER CODE BEGIN TIM1_BRK_TIM9_IRQn 1 */
-
- /* USER CODE END TIM1_BRK_TIM9_IRQn 1 */
-}
-
-/**
- * @brief This function handles USART1 global interrupt.
- */
-void USART1_IRQHandler(void)
-{
- /* USER CODE BEGIN USART1_IRQn 0 */
-
- /* USER CODE END USART1_IRQn 0 */
- HAL_UART_IRQHandler(&huart1);
- /* USER CODE BEGIN USART1_IRQn 1 */
- BSP_UART_IRQHandler(&huart1);
-
- /* USER CODE END USART1_IRQn 1 */
-}
-
-/**
- * @brief This function handles DMA1 stream7 global interrupt.
- */
-void DMA1_Stream7_IRQHandler(void)
-{
- /* USER CODE BEGIN DMA1_Stream7_IRQn 0 */
-
- /* USER CODE END DMA1_Stream7_IRQn 0 */
- HAL_DMA_IRQHandler(&hdma_i2c2_tx);
- /* USER CODE BEGIN DMA1_Stream7_IRQn 1 */
-
- /* USER CODE END DMA1_Stream7_IRQn 1 */
-}
-
-/**
- * @brief This function handles TIM7 global interrupt.
- */
-void TIM7_IRQHandler(void)
-{
- /* USER CODE BEGIN TIM7_IRQn 0 */
-
- /* USER CODE END TIM7_IRQn 0 */
- HAL_TIM_IRQHandler(&htim7);
- /* USER CODE BEGIN TIM7_IRQn 1 */
-
- /* USER CODE END TIM7_IRQn 1 */
-}
-
-/**
- * @brief This function handles DMA2 stream1 global interrupt.
- */
-void DMA2_Stream1_IRQHandler(void)
-{
- /* USER CODE BEGIN DMA2_Stream1_IRQn 0 */
-
- /* USER CODE END DMA2_Stream1_IRQn 0 */
- HAL_DMA_IRQHandler(&hdma_usart6_rx);
- /* USER CODE BEGIN DMA2_Stream1_IRQn 1 */
-
- /* USER CODE END DMA2_Stream1_IRQn 1 */
-}
-
-/**
- * @brief This function handles DMA2 stream2 global interrupt.
- */
-void DMA2_Stream2_IRQHandler(void)
-{
- /* USER CODE BEGIN DMA2_Stream2_IRQn 0 */
-
- /* USER CODE END DMA2_Stream2_IRQn 0 */
- HAL_DMA_IRQHandler(&hdma_spi1_rx);
- /* USER CODE BEGIN DMA2_Stream2_IRQn 1 */
-
- /* USER CODE END DMA2_Stream2_IRQn 1 */
-}
-
-/**
- * @brief This function handles DMA2 stream3 global interrupt.
- */
-void DMA2_Stream3_IRQHandler(void)
-{
- /* USER CODE BEGIN DMA2_Stream3_IRQn 0 */
-
- /* USER CODE END DMA2_Stream3_IRQn 0 */
- HAL_DMA_IRQHandler(&hdma_spi1_tx);
- /* USER CODE BEGIN DMA2_Stream3_IRQn 1 */
-
- /* USER CODE END DMA2_Stream3_IRQn 1 */
-}
-
-/**
- * @brief This function handles CAN2 RX0 interrupts.
- */
-void CAN2_RX0_IRQHandler(void)
-{
- /* USER CODE BEGIN CAN2_RX0_IRQn 0 */
-
- /* USER CODE END CAN2_RX0_IRQn 0 */
- HAL_CAN_IRQHandler(&hcan2);
- /* USER CODE BEGIN CAN2_RX0_IRQn 1 */
-
- /* USER CODE END CAN2_RX0_IRQn 1 */
-}
-
-/**
- * @brief This function handles CAN2 RX1 interrupt.
- */
-void CAN2_RX1_IRQHandler(void)
-{
- /* USER CODE BEGIN CAN2_RX1_IRQn 0 */
-
- /* USER CODE END CAN2_RX1_IRQn 0 */
- HAL_CAN_IRQHandler(&hcan2);
- /* USER CODE BEGIN CAN2_RX1_IRQn 1 */
-
- /* USER CODE END CAN2_RX1_IRQn 1 */
-}
-
-/**
- * @brief This function handles USB On The Go FS global interrupt.
- */
-void OTG_FS_IRQHandler(void)
-{
- /* USER CODE BEGIN OTG_FS_IRQn 0 */
-
- /* USER CODE END OTG_FS_IRQn 0 */
- HAL_PCD_IRQHandler(&hpcd_USB_OTG_FS);
- /* USER CODE BEGIN OTG_FS_IRQn 1 */
-
- /* USER CODE END OTG_FS_IRQn 1 */
-}
-
-/**
- * @brief This function handles DMA2 stream5 global interrupt.
- */
-void DMA2_Stream5_IRQHandler(void)
-{
- /* USER CODE BEGIN DMA2_Stream5_IRQn 0 */
-
- /* USER CODE END DMA2_Stream5_IRQn 0 */
- HAL_DMA_IRQHandler(&hdma_usart1_rx);
- /* USER CODE BEGIN DMA2_Stream5_IRQn 1 */
-
- /* USER CODE END DMA2_Stream5_IRQn 1 */
-}
-
-/**
- * @brief This function handles DMA2 stream6 global interrupt.
- */
-void DMA2_Stream6_IRQHandler(void)
-{
- /* USER CODE BEGIN DMA2_Stream6_IRQn 0 */
-
- /* USER CODE END DMA2_Stream6_IRQn 0 */
- HAL_DMA_IRQHandler(&hdma_usart6_tx);
- /* USER CODE BEGIN DMA2_Stream6_IRQn 1 */
-
- /* USER CODE END DMA2_Stream6_IRQn 1 */
-}
-
-/**
- * @brief This function handles DMA2 stream7 global interrupt.
- */
-void DMA2_Stream7_IRQHandler(void)
-{
- /* USER CODE BEGIN DMA2_Stream7_IRQn 0 */
-
- /* USER CODE END DMA2_Stream7_IRQn 0 */
- HAL_DMA_IRQHandler(&hdma_usart1_tx);
- /* USER CODE BEGIN DMA2_Stream7_IRQn 1 */
-
- /* USER CODE END DMA2_Stream7_IRQn 1 */
-}
-
-/**
- * @brief This function handles USART6 global interrupt.
- */
-void USART6_IRQHandler(void)
-{
- /* USER CODE BEGIN USART6_IRQn 0 */
-
- /* USER CODE END USART6_IRQn 0 */
- HAL_UART_IRQHandler(&huart6);
- /* USER CODE BEGIN USART6_IRQn 1 */
- BSP_UART_IRQHandler(&huart6);
-
- /* USER CODE END USART6_IRQn 1 */
-}
-
-/* USER CODE BEGIN 1 */
-
-/* USER CODE END 1 */
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+/* USER CODE BEGIN Header */
+/**
+ ******************************************************************************
+ * @file stm32f4xx_it.c
+ * @brief Interrupt Service Routines.
+ ******************************************************************************
+ * @attention
+ *
+ * © Copyright (c) 2025 STMicroelectronics.
+ * All rights reserved.
+ *
+ * This software component is licensed by ST under Ultimate Liberty license
+ * SLA0044, the "License"; You may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at:
+ * www.st.com/SLA0044
+ *
+ ******************************************************************************
+ */
+/* USER CODE END Header */
+
+/* Includes ------------------------------------------------------------------*/
+#include "main.h"
+#include "stm32f4xx_it.h"
+#include "FreeRTOS.h"
+#include "task.h"
+/* Private includes ----------------------------------------------------------*/
+/* USER CODE BEGIN Includes */
+#include "bsp/uart.h"
+/* USER CODE END Includes */
+
+/* Private typedef -----------------------------------------------------------*/
+/* USER CODE BEGIN TD */
+
+/* USER CODE END TD */
+
+/* Private define ------------------------------------------------------------*/
+/* USER CODE BEGIN PD */
+
+/* USER CODE END PD */
+
+/* Private macro -------------------------------------------------------------*/
+/* USER CODE BEGIN PM */
+
+/* USER CODE END PM */
+
+/* Private variables ---------------------------------------------------------*/
+/* USER CODE BEGIN PV */
+
+/* USER CODE END PV */
+
+/* Private function prototypes -----------------------------------------------*/
+/* USER CODE BEGIN PFP */
+
+/* USER CODE END PFP */
+
+/* Private user code ---------------------------------------------------------*/
+/* USER CODE BEGIN 0 */
+
+/* USER CODE END 0 */
+
+/* External variables --------------------------------------------------------*/
+extern PCD_HandleTypeDef hpcd_USB_OTG_FS;
+extern CAN_HandleTypeDef hcan1;
+extern CAN_HandleTypeDef hcan2;
+extern DMA_HandleTypeDef hdma_i2c2_tx;
+extern DMA_HandleTypeDef hdma_i2c3_rx;
+extern DMA_HandleTypeDef hdma_spi1_rx;
+extern DMA_HandleTypeDef hdma_spi1_tx;
+extern TIM_HandleTypeDef htim1;
+extern TIM_HandleTypeDef htim7;
+extern DMA_HandleTypeDef hdma_usart1_tx;
+extern DMA_HandleTypeDef hdma_usart1_rx;
+extern DMA_HandleTypeDef hdma_usart3_rx;
+extern DMA_HandleTypeDef hdma_usart6_rx;
+extern DMA_HandleTypeDef hdma_usart6_tx;
+extern UART_HandleTypeDef huart1;
+extern UART_HandleTypeDef huart6;
+/* USER CODE BEGIN EV */
+
+/* USER CODE END EV */
+
+/******************************************************************************/
+/* Cortex-M4 Processor Interruption and Exception Handlers */
+/******************************************************************************/
+/**
+ * @brief This function handles Non maskable interrupt.
+ */
+void NMI_Handler(void)
+{
+ /* USER CODE BEGIN NonMaskableInt_IRQn 0 */
+
+ /* USER CODE END NonMaskableInt_IRQn 0 */
+ /* USER CODE BEGIN NonMaskableInt_IRQn 1 */
+ while (1)
+ {
+ }
+ /* USER CODE END NonMaskableInt_IRQn 1 */
+}
+
+/**
+ * @brief This function handles Hard fault interrupt.
+ */
+void HardFault_Handler(void)
+{
+ /* USER CODE BEGIN HardFault_IRQn 0 */
+
+ /* USER CODE END HardFault_IRQn 0 */
+ while (1)
+ {
+ /* USER CODE BEGIN W1_HardFault_IRQn 0 */
+ /* USER CODE END W1_HardFault_IRQn 0 */
+ }
+}
+
+/**
+ * @brief This function handles Memory management fault.
+ */
+void MemManage_Handler(void)
+{
+ /* USER CODE BEGIN MemoryManagement_IRQn 0 */
+
+ /* USER CODE END MemoryManagement_IRQn 0 */
+ while (1)
+ {
+ /* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */
+ /* USER CODE END W1_MemoryManagement_IRQn 0 */
+ }
+}
+
+/**
+ * @brief This function handles Pre-fetch fault, memory access fault.
+ */
+void BusFault_Handler(void)
+{
+ /* USER CODE BEGIN BusFault_IRQn 0 */
+
+ /* USER CODE END BusFault_IRQn 0 */
+ while (1)
+ {
+ /* USER CODE BEGIN W1_BusFault_IRQn 0 */
+ /* USER CODE END W1_BusFault_IRQn 0 */
+ }
+}
+
+/**
+ * @brief This function handles Undefined instruction or illegal state.
+ */
+void UsageFault_Handler(void)
+{
+ /* USER CODE BEGIN UsageFault_IRQn 0 */
+
+ /* USER CODE END UsageFault_IRQn 0 */
+ while (1)
+ {
+ /* USER CODE BEGIN W1_UsageFault_IRQn 0 */
+ /* USER CODE END W1_UsageFault_IRQn 0 */
+ }
+}
+
+/**
+ * @brief This function handles Debug monitor.
+ */
+void DebugMon_Handler(void)
+{
+ /* USER CODE BEGIN DebugMonitor_IRQn 0 */
+
+ /* USER CODE END DebugMonitor_IRQn 0 */
+ /* USER CODE BEGIN DebugMonitor_IRQn 1 */
+
+ /* USER CODE END DebugMonitor_IRQn 1 */
+}
+
+/**
+ * @brief This function handles System tick timer.
+ */
+void SysTick_Handler(void)
+{
+ /* USER CODE BEGIN SysTick_IRQn 0 */
+
+ /* USER CODE END SysTick_IRQn 0 */
+ HAL_IncTick();
+#if (INCLUDE_xTaskGetSchedulerState == 1 )
+ if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED)
+ {
+#endif /* INCLUDE_xTaskGetSchedulerState */
+ xPortSysTickHandler();
+#if (INCLUDE_xTaskGetSchedulerState == 1 )
+ }
+#endif /* INCLUDE_xTaskGetSchedulerState */
+ /* USER CODE BEGIN SysTick_IRQn 1 */
+
+ /* USER CODE END SysTick_IRQn 1 */
+}
+
+/******************************************************************************/
+/* STM32F4xx Peripheral Interrupt Handlers */
+/* Add here the Interrupt Handlers for the used peripherals. */
+/* For the available peripheral interrupt handler names, */
+/* please refer to the startup file (startup_stm32f4xx.s). */
+/******************************************************************************/
+
+/**
+ * @brief This function handles EXTI line0 interrupt.
+ */
+void EXTI0_IRQHandler(void)
+{
+ /* USER CODE BEGIN EXTI0_IRQn 0 */
+
+ /* USER CODE END EXTI0_IRQn 0 */
+ HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_0);
+ /* USER CODE BEGIN EXTI0_IRQn 1 */
+
+ /* USER CODE END EXTI0_IRQn 1 */
+}
+
+/**
+ * @brief This function handles EXTI line3 interrupt.
+ */
+void EXTI3_IRQHandler(void)
+{
+ /* USER CODE BEGIN EXTI3_IRQn 0 */
+
+ /* USER CODE END EXTI3_IRQn 0 */
+ HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_3);
+ /* USER CODE BEGIN EXTI3_IRQn 1 */
+
+ /* USER CODE END EXTI3_IRQn 1 */
+}
+
+/**
+ * @brief This function handles EXTI line4 interrupt.
+ */
+void EXTI4_IRQHandler(void)
+{
+ /* USER CODE BEGIN EXTI4_IRQn 0 */
+
+ /* USER CODE END EXTI4_IRQn 0 */
+ HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_4);
+ /* USER CODE BEGIN EXTI4_IRQn 1 */
+
+ /* USER CODE END EXTI4_IRQn 1 */
+}
+
+/**
+ * @brief This function handles DMA1 stream1 global interrupt.
+ */
+void DMA1_Stream1_IRQHandler(void)
+{
+ /* USER CODE BEGIN DMA1_Stream1_IRQn 0 */
+
+ /* USER CODE END DMA1_Stream1_IRQn 0 */
+ HAL_DMA_IRQHandler(&hdma_usart3_rx);
+ /* USER CODE BEGIN DMA1_Stream1_IRQn 1 */
+
+ /* USER CODE END DMA1_Stream1_IRQn 1 */
+}
+
+/**
+ * @brief This function handles DMA1 stream2 global interrupt.
+ */
+void DMA1_Stream2_IRQHandler(void)
+{
+ /* USER CODE BEGIN DMA1_Stream2_IRQn 0 */
+
+ /* USER CODE END DMA1_Stream2_IRQn 0 */
+ HAL_DMA_IRQHandler(&hdma_i2c3_rx);
+ /* USER CODE BEGIN DMA1_Stream2_IRQn 1 */
+
+ /* USER CODE END DMA1_Stream2_IRQn 1 */
+}
+
+/**
+ * @brief This function handles CAN1 RX0 interrupts.
+ */
+void CAN1_RX0_IRQHandler(void)
+{
+ /* USER CODE BEGIN CAN1_RX0_IRQn 0 */
+
+ /* USER CODE END CAN1_RX0_IRQn 0 */
+ HAL_CAN_IRQHandler(&hcan1);
+ /* USER CODE BEGIN CAN1_RX0_IRQn 1 */
+
+ /* USER CODE END CAN1_RX0_IRQn 1 */
+}
+
+/**
+ * @brief This function handles CAN1 RX1 interrupt.
+ */
+void CAN1_RX1_IRQHandler(void)
+{
+ /* USER CODE BEGIN CAN1_RX1_IRQn 0 */
+
+ /* USER CODE END CAN1_RX1_IRQn 0 */
+ HAL_CAN_IRQHandler(&hcan1);
+ /* USER CODE BEGIN CAN1_RX1_IRQn 1 */
+
+ /* USER CODE END CAN1_RX1_IRQn 1 */
+}
+
+/**
+ * @brief This function handles EXTI line[9:5] interrupts.
+ */
+void EXTI9_5_IRQHandler(void)
+{
+ /* USER CODE BEGIN EXTI9_5_IRQn 0 */
+
+ /* USER CODE END EXTI9_5_IRQn 0 */
+ HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_5);
+ /* USER CODE BEGIN EXTI9_5_IRQn 1 */
+
+ /* USER CODE END EXTI9_5_IRQn 1 */
+}
+
+/**
+ * @brief This function handles TIM1 break interrupt and TIM9 global interrupt.
+ */
+void TIM1_BRK_TIM9_IRQHandler(void)
+{
+ /* USER CODE BEGIN TIM1_BRK_TIM9_IRQn 0 */
+
+ /* USER CODE END TIM1_BRK_TIM9_IRQn 0 */
+ HAL_TIM_IRQHandler(&htim1);
+ /* USER CODE BEGIN TIM1_BRK_TIM9_IRQn 1 */
+
+ /* USER CODE END TIM1_BRK_TIM9_IRQn 1 */
+}
+
+/**
+ * @brief This function handles USART1 global interrupt.
+ */
+void USART1_IRQHandler(void)
+{
+ /* USER CODE BEGIN USART1_IRQn 0 */
+
+ /* USER CODE END USART1_IRQn 0 */
+ HAL_UART_IRQHandler(&huart1);
+ /* USER CODE BEGIN USART1_IRQn 1 */
+ BSP_UART_IRQHandler(&huart1);
+
+ /* USER CODE END USART1_IRQn 1 */
+}
+
+/**
+ * @brief This function handles DMA1 stream7 global interrupt.
+ */
+void DMA1_Stream7_IRQHandler(void)
+{
+ /* USER CODE BEGIN DMA1_Stream7_IRQn 0 */
+
+ /* USER CODE END DMA1_Stream7_IRQn 0 */
+ HAL_DMA_IRQHandler(&hdma_i2c2_tx);
+ /* USER CODE BEGIN DMA1_Stream7_IRQn 1 */
+
+ /* USER CODE END DMA1_Stream7_IRQn 1 */
+}
+
+/**
+ * @brief This function handles TIM7 global interrupt.
+ */
+void TIM7_IRQHandler(void)
+{
+ /* USER CODE BEGIN TIM7_IRQn 0 */
+
+ /* USER CODE END TIM7_IRQn 0 */
+ HAL_TIM_IRQHandler(&htim7);
+ /* USER CODE BEGIN TIM7_IRQn 1 */
+
+ /* USER CODE END TIM7_IRQn 1 */
+}
+
+/**
+ * @brief This function handles DMA2 stream1 global interrupt.
+ */
+void DMA2_Stream1_IRQHandler(void)
+{
+ /* USER CODE BEGIN DMA2_Stream1_IRQn 0 */
+
+ /* USER CODE END DMA2_Stream1_IRQn 0 */
+ HAL_DMA_IRQHandler(&hdma_usart6_rx);
+ /* USER CODE BEGIN DMA2_Stream1_IRQn 1 */
+
+ /* USER CODE END DMA2_Stream1_IRQn 1 */
+}
+
+/**
+ * @brief This function handles DMA2 stream2 global interrupt.
+ */
+void DMA2_Stream2_IRQHandler(void)
+{
+ /* USER CODE BEGIN DMA2_Stream2_IRQn 0 */
+
+ /* USER CODE END DMA2_Stream2_IRQn 0 */
+ HAL_DMA_IRQHandler(&hdma_spi1_rx);
+ /* USER CODE BEGIN DMA2_Stream2_IRQn 1 */
+
+ /* USER CODE END DMA2_Stream2_IRQn 1 */
+}
+
+/**
+ * @brief This function handles DMA2 stream3 global interrupt.
+ */
+void DMA2_Stream3_IRQHandler(void)
+{
+ /* USER CODE BEGIN DMA2_Stream3_IRQn 0 */
+
+ /* USER CODE END DMA2_Stream3_IRQn 0 */
+ HAL_DMA_IRQHandler(&hdma_spi1_tx);
+ /* USER CODE BEGIN DMA2_Stream3_IRQn 1 */
+
+ /* USER CODE END DMA2_Stream3_IRQn 1 */
+}
+
+/**
+ * @brief This function handles CAN2 RX0 interrupts.
+ */
+void CAN2_RX0_IRQHandler(void)
+{
+ /* USER CODE BEGIN CAN2_RX0_IRQn 0 */
+
+ /* USER CODE END CAN2_RX0_IRQn 0 */
+ HAL_CAN_IRQHandler(&hcan2);
+ /* USER CODE BEGIN CAN2_RX0_IRQn 1 */
+
+ /* USER CODE END CAN2_RX0_IRQn 1 */
+}
+
+/**
+ * @brief This function handles CAN2 RX1 interrupt.
+ */
+void CAN2_RX1_IRQHandler(void)
+{
+ /* USER CODE BEGIN CAN2_RX1_IRQn 0 */
+
+ /* USER CODE END CAN2_RX1_IRQn 0 */
+ HAL_CAN_IRQHandler(&hcan2);
+ /* USER CODE BEGIN CAN2_RX1_IRQn 1 */
+
+ /* USER CODE END CAN2_RX1_IRQn 1 */
+}
+
+/**
+ * @brief This function handles USB On The Go FS global interrupt.
+ */
+void OTG_FS_IRQHandler(void)
+{
+ /* USER CODE BEGIN OTG_FS_IRQn 0 */
+
+ /* USER CODE END OTG_FS_IRQn 0 */
+ HAL_PCD_IRQHandler(&hpcd_USB_OTG_FS);
+ /* USER CODE BEGIN OTG_FS_IRQn 1 */
+
+ /* USER CODE END OTG_FS_IRQn 1 */
+}
+
+/**
+ * @brief This function handles DMA2 stream5 global interrupt.
+ */
+void DMA2_Stream5_IRQHandler(void)
+{
+ /* USER CODE BEGIN DMA2_Stream5_IRQn 0 */
+
+ /* USER CODE END DMA2_Stream5_IRQn 0 */
+ HAL_DMA_IRQHandler(&hdma_usart1_rx);
+ /* USER CODE BEGIN DMA2_Stream5_IRQn 1 */
+
+ /* USER CODE END DMA2_Stream5_IRQn 1 */
+}
+
+/**
+ * @brief This function handles DMA2 stream6 global interrupt.
+ */
+void DMA2_Stream6_IRQHandler(void)
+{
+ /* USER CODE BEGIN DMA2_Stream6_IRQn 0 */
+
+ /* USER CODE END DMA2_Stream6_IRQn 0 */
+ HAL_DMA_IRQHandler(&hdma_usart6_tx);
+ /* USER CODE BEGIN DMA2_Stream6_IRQn 1 */
+
+ /* USER CODE END DMA2_Stream6_IRQn 1 */
+}
+
+/**
+ * @brief This function handles DMA2 stream7 global interrupt.
+ */
+void DMA2_Stream7_IRQHandler(void)
+{
+ /* USER CODE BEGIN DMA2_Stream7_IRQn 0 */
+
+ /* USER CODE END DMA2_Stream7_IRQn 0 */
+ HAL_DMA_IRQHandler(&hdma_usart1_tx);
+ /* USER CODE BEGIN DMA2_Stream7_IRQn 1 */
+
+ /* USER CODE END DMA2_Stream7_IRQn 1 */
+}
+
+/**
+ * @brief This function handles USART6 global interrupt.
+ */
+void USART6_IRQHandler(void)
+{
+ /* USER CODE BEGIN USART6_IRQn 0 */
+
+ /* USER CODE END USART6_IRQn 0 */
+ HAL_UART_IRQHandler(&huart6);
+ /* USER CODE BEGIN USART6_IRQn 1 */
+ BSP_UART_IRQHandler(&huart6);
+
+ /* USER CODE END USART6_IRQn 1 */
+}
+
+/* USER CODE BEGIN 1 */
+
+/* USER CODE END 1 */
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/User/bsp/bsp_config.yaml b/User/bsp/bsp_config.yaml
index cbc057c..d0e0770 100644
--- a/User/bsp/bsp_config.yaml
+++ b/User/bsp/bsp_config.yaml
@@ -128,7 +128,7 @@ uart:
- instance: USART6
name: AI
- instance: USART1
- name: DR16
- - instance: USART3
name: REF
+ - instance: USART3
+ name: DR16
enabled: true
diff --git a/User/bsp/uart.c b/User/bsp/uart.c
index a0eb265..cf096c7 100644
--- a/User/bsp/uart.c
+++ b/User/bsp/uart.c
@@ -26,9 +26,9 @@ static BSP_UART_t UART_Get(UART_HandleTypeDef *huart) {
if (huart->Instance == USART6)
return BSP_UART_AI;
else if (huart->Instance == USART1)
- return BSP_UART_DR16;
- else if (huart->Instance == USART3)
return BSP_UART_REF;
+ else if (huart->Instance == USART3)
+ return BSP_UART_DR16;
else
return BSP_UART_ERR;
}
@@ -119,9 +119,9 @@ UART_HandleTypeDef *BSP_UART_GetHandle(BSP_UART_t uart) {
switch (uart) {
case BSP_UART_AI:
return &huart6;
- case BSP_UART_DR16:
- return &huart1;
case BSP_UART_REF:
+ return &huart1;
+ case BSP_UART_DR16:
return &huart3;
default:
return NULL;
diff --git a/User/bsp/uart.h b/User/bsp/uart.h
index 385c55e..040e3ed 100644
--- a/User/bsp/uart.h
+++ b/User/bsp/uart.h
@@ -28,8 +28,8 @@ extern "C" {
/* UART实体枚举,与设备对应 */
typedef enum {
BSP_UART_AI,
- BSP_UART_DR16,
BSP_UART_REF,
+ BSP_UART_DR16,
BSP_UART_NUM,
BSP_UART_ERR,
} BSP_UART_t;
diff --git a/User/module/config.c b/User/module/config.c
new file mode 100644
index 0000000..0d75200
--- /dev/null
+++ b/User/module/config.c
@@ -0,0 +1,54 @@
+/*
+ * 配置相关
+ */
+
+/* Includes ----------------------------------------------------------------- */
+#include "module/config.h"
+#include "bsp/can.h"
+#include "device/motor_rm.h"
+#include "component/pid.h"
+#include "component/user_math.h"
+
+/* Private typedef ---------------------------------------------------------- */
+/* Private define ----------------------------------------------------------- */
+/* Private macro ------------------------------------------------------------ */
+/* Private variables -------------------------------------------------------- */
+
+/* Exported variables ------------------------------------------------------- */
+
+// 机器人参数配置
+Config_RobotParam_t robot_config = {
+ .shoot_param = {
+ .trig_motor_param = {
+ .can = BSP_CAN_1,
+ .id = 0x201,
+ .module = MOTOR_M2006,
+ .reverse = false,
+ .gear = true,
+ },
+ .trig_pid_param = {
+ .k = 12.0f,
+ .p = 1.0f,
+ .i = 0.0f,
+ .d = 0.0450000018f,
+ .i_limit = 1.0f,
+ .out_limit = 1.0f,
+ .d_cutoff_freq = -1.0f,
+ .range = M_2PI,
+ },
+ .num_trig_tooth = 8.0f,
+ .fric_radius = 0.03f,
+ .min_shoot_delay = (uint32_t)(1000.0f / 10.0f),
+ }
+};
+
+/* Private function prototypes ---------------------------------------------- */
+/* Exported functions ------------------------------------------------------- */
+
+/**
+ * @brief 获取机器人配置参数
+ * @return 机器人配置参数指针
+ */
+Config_RobotParam_t* Config_GetRobotParam(void) {
+ return &robot_config;
+}
\ No newline at end of file
diff --git a/User/module/config.h b/User/module/config.h
new file mode 100644
index 0000000..400c3ef
--- /dev/null
+++ b/User/module/config.h
@@ -0,0 +1,30 @@
+/*
+ * 配置相关
+ */
+
+#pragma once
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include
+#include "module/shoot.h"
+#include "module/gimbal.h"
+
+
+typedef struct {
+ Shoot_Params_t shoot_param; /* 射击参数 */
+} Config_RobotParam_t;
+
+/* Exported functions prototypes -------------------------------------------- */
+
+/**
+ * @brief 获取机器人配置参数
+ * @return 机器人配置参数指针
+ */
+Config_RobotParam_t* Config_GetRobotParam(void);
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/User/module/gimbal.c b/User/module/gimbal.c
new file mode 100644
index 0000000..e69de29
diff --git a/User/module/gimbal.h b/User/module/gimbal.h
new file mode 100644
index 0000000..e69de29
diff --git a/User/module/shoot.c b/User/module/shoot.c
new file mode 100644
index 0000000..0c9a585
--- /dev/null
+++ b/User/module/shoot.c
@@ -0,0 +1,201 @@
+/*
+ * 射击模组
+ */
+
+/* Includes ----------------------------------------------------------------- */
+#include "shoot.h"
+
+#include "bsp/pwm.h"
+#include "bsp/time.h"
+#include "bsp/can.h"
+#include "component/pid.h"
+#include "component/limiter.h"
+#include "component/user_math.h"
+#include "device/motor_rm.h"
+#include
+/* Private typedef ---------------------------------------------------------- */
+/* Private define ----------------------------------------------------------- */
+
+#define BULLET_SPEED_LIMIT_17MM (25.0)
+
+/* Private macro ------------------------------------------------------------ */
+/* Private variables -------------------------------------------------------- */
+/* Private function -------------------------------------------------------- */
+
+/**
+ * \brief 设置射击模式
+ *
+ * \param c 包含射击数据的结构体
+ * \param mode 要设置的模式
+ *
+ * \return 函数运行结果
+ */
+static int8_t Shoot_SetMode(Shoot_t *s, CMD_ShootMode_t mode) {
+ if (s == NULL) return -1;
+
+ if (mode == s->mode) return SHOOT_OK;
+
+ /* 切换模式后重置PID和滤波器 */
+// for (uint8_t i = 0; i < 2; i++) {
+// PID_Reset(s->pid.fric + i);
+// LowPassFilter2p_Reset(s->filter.in.fric + i, 0.0f);
+// LowPassFilter2p_Reset(s->filter.out.fric + i, 0.0f);
+// }
+// PID_Reset(&(s->pid.trig));
+// LowPassFilter2p_Reset(&(s->filter.in.trig), 0.0f);
+// LowPassFilter2p_Reset(&(s->filter.out.trig), 0.0f);
+ PID_Reset(&(s->pid.fric[0]));
+ PID_Reset(&(s->pid.fric[1]));
+ LowPassFilter2p_Reset(&(s->filter.in.fric[0]), 0.0f);
+ LowPassFilter2p_Reset(&(s->filter.in.fric[1]), 0.0f);
+ LowPassFilter2p_Reset(&(s->filter.out.fric[0]), 0.0f);
+ LowPassFilter2p_Reset(&(s->filter.out.fric[1]), 0.0f);
+ PID_Reset(&(s->pid.trig));
+ LowPassFilter2p_Reset(&(s->filter.in.trig), 0.0f);
+ LowPassFilter2p_Reset(&(s->filter.out.trig), 0.0f);
+
+// while (fabsf(CircleError(s->setpoint.trig_angle, s->feedback.trig_angle,
+// M_2PI)) >= M_2PI / s->param->num_trig_tooth / 2.0f) {
+// CircleAdd(&(s->setpoint.trig_angle), M_2PI / s->param->num_trig_tooth,
+// M_2PI);
+// }
+
+ if (mode == SHOOT_MODE_LOADED) s->fire_ctrl.to_shoot = 0;
+ s->mode = mode;
+ return 0;
+}
+
+// static float Shoot_CalcRPMFromSpeed(float speed, float radius, float *rpm) {
+// if (rpm == NULL) return -1;
+// if (radius <= 0.0f) return -2;
+
+// /* 限制弹丸速度 */
+// speed = Limit_Abs(speed, BULLET_SPEED_LIMIT_17MM);
+
+// /* 计算转速 */
+// *rpm = speed / (2.0f * M_PI * radius) * 60.0f;
+
+// return 0;
+// }
+
+/* Exported functions ------------------------------------------------------- */
+
+/**
+ * \brief 初始化射击
+ *
+ * \param s 包含射击数据的结构体
+ * \param param 包含射击参数的结构体指针
+ * \param target_freq 任务预期的运行频率
+ *
+ * \return 函数运行结果
+ */
+int8_t Shoot_Init(Shoot_t *s, const Shoot_Params_t *param, float target_freq) {
+ if (s == NULL) return -1;
+
+ s->param = param; /* 初始化参数 */
+ s->mode = SHOOT_MODE_RELAX; /* 设置默认模式 */
+
+ PID_Init(&(s->pid.fric[0]), KPID_MODE_NO_D, target_freq,
+ &(param->fric_pid_param));
+ PID_Init(&(s->pid.fric[1]), KPID_MODE_NO_D, target_freq,
+ &(param->fric_pid_param));
+ PID_Init(&(s->pid.trig), KPID_MODE_CALC_D, target_freq,
+ &(param->trig_pid_param));
+
+ LowPassFilter2p_Init(&(s->filter.in.fric[0]), target_freq,
+ param->low_pass_cutoff_freq.in.fric);
+ LowPassFilter2p_Init(&(s->filter.in.fric[1]), target_freq,
+ param->low_pass_cutoff_freq.in.fric);
+ LowPassFilter2p_Init(&(s->filter.out.fric[0]), target_freq,
+ param->low_pass_cutoff_freq.out.fric);
+ LowPassFilter2p_Init(&(s->filter.out.fric[1]), target_freq,
+ param->low_pass_cutoff_freq.out.fric);
+ LowPassFilter2p_Init(&(s->filter.in.trig), target_freq,
+ param->low_pass_cutoff_freq.in.trig);
+ LowPassFilter2p_Init(&(s->filter.out.trig), target_freq,
+ param->low_pass_cutoff_freq.out.trig);
+
+ BSP_CAN_Init();
+ MOTOR_RM_Register(s->param->fric_motor_param[0]);
+ MOTOR_RM_Register(s->param->fric_motor_param[1]);
+ MOTOR_RM_Register(s->param->trig_motor_param);
+
+ return SHOOT_OK;
+}
+
+/**
+ * \brief 更新射击的反馈信息
+ *
+ * \param s 包含射击数据的结构体
+ *
+ * \return 函数运行结果
+ */
+int8_t Shoot_UpdateFeedback(Shoot_t *s) {
+ if (s == NULL) return -1;
+ MOTOR_RM_Update(s->param->fric_motor_param[0]);
+ MOTOR_RM_Update(s->param->fric_motor_param[1]);
+ MOTOR_RM_Update(s->param->trig_motor_param);
+
+ MOTOR_RM_t *motor;
+ motor = MOTOR_RM_GetMotor(s->param->fric_motor_param[0]);
+ s->feedback.fric[0] = motor->feedback;
+ motor = MOTOR_RM_GetMotor(s->param->fric_motor_param[1]);
+ s->feedback.fric[1] = motor->feedback;
+ motor = MOTOR_RM_GetMotor(s->param->trig_motor_param);
+ s->feedback.trig = motor->feedback;
+
+ return SHOOT_OK;
+}
+
+/**
+ * \brief 运行射击控制逻辑
+ *
+ * \param s 包含射击数据的结构体
+ * \param s_cmd 射击控制指令
+ *
+ * \return 函数运行结果
+ */
+int8_t Shoot_Control(Shoot_t *s, Shoot_CMD_t *s_cmd) {
+ if (s == NULL) return -1;
+ if (s_cmd == NULL) return -1;
+
+ Shoot_SetMode(s, s_cmd->mode); /* 设置射击模式 */
+
+ /* 计算摩擦轮转速的目标值 */
+ // 根据弹丸射速计算转速,这里需要实现具体的计算逻辑
+ // s->setpoint.fric_rpm[0] = calculate_rpm_from_speed(s_cmd->bullet_speed);
+ // s->setpoint.fric_rpm[1] = -s->setpoint.fric_rpm[0];
+
+ switch (s->mode) {
+ case SHOOT_MODE_RELAX:
+ MOTOR_RM_SetOutput(s->param->fric_motor_param[0], 0.0f);
+ MOTOR_RM_SetOutput(s->param->fric_motor_param[1], 0.0f);
+ MOTOR_RM_SetOutput(s->param->trig_motor_param, 0.0f);
+ break;
+ case SHOOT_MODE_SAFE:
+ /*摩擦轮速度环到0,拨弹位置环到设定位置*/
+ s->setpoint.fric_rpm[0] = 0.0f;
+ s->setpoint.fric_rpm[1] = 0.0f;
+
+
+
+ break;
+
+ case SHOOT_MODE_LOADED:
+ // TODO: 实现上膛模式的控制逻辑
+ break;
+ }
+ return SHOOT_OK;
+}
+
+/**
+ * \brief 射击输出值
+ *
+ * \param s 包含射击数据的结构体
+ */
+void Shoot_Output(Shoot_t *s) {
+ if (s == NULL) return;
+ MOTOR_RM_Ctrl(s->param->fric_motor_param[0]);
+}
+
+
diff --git a/User/module/shoot.h b/User/module/shoot.h
new file mode 100644
index 0000000..a9a82a0
--- /dev/null
+++ b/User/module/shoot.h
@@ -0,0 +1,176 @@
+/*
+ * 射击模组
+ */
+
+#pragma once
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Includes ----------------------------------------------------------------- */
+#include
+
+#include "component/filter.h"
+#include "component/pid.h"
+#include "device/motor_rm.h"
+#include "device/motor.h"
+
+/* Exported constants ------------------------------------------------------- */
+#define SHOOT_OK (0) /* 运行正常 */
+#define SHOOT_ERR (-1) /* 运行时发现了其他错误 */
+#define SHOOT_ERR_NULL (-2) /* 运行时发现NULL指针 */
+#define SHOOT_ERR_MODE (-3) /* 运行时配置了错误的CMD_ShootMode_t */
+
+/* Exported macro ----------------------------------------------------------- */
+/* Exported types ----------------------------------------------------------- */
+
+typedef enum {
+ SHOOT_MODE_RELAX = 0, /* 放松模式,电机不工作 */
+ SHOOT_MODE_SAFE = 1, /* 安全模式,电机工作但不允许射击 */
+ SHOOT_MODE_LOADED = 2 /* 上膛模式,电机工作并允许射击 */
+}Shoot_Mode_t;
+
+typedef struct {
+ Shoot_Mode_t mode; /*射击模式*/
+ float bullet_speed; /*弹丸射速*/
+ uint32_t bullet_num; /*要发射的弹丸数*/
+}Shoot_CMD_t;
+
+/* 射击参数的结构体,包含所有初始化用的参数,通常是const,存好几组。*/
+typedef struct {
+ MOTOR_RM_Param_t fric_motor_param[2]; /* 摩擦轮电机参数 */
+ MOTOR_RM_Param_t trig_motor_param; /* 拨弹电机参数 */
+
+
+ KPID_Params_t fric_pid_param; /* 摩擦轮电机控制PID的参数 */
+ KPID_Params_t trig_pid_param; /* 扳机电机控制PID的参数 */
+ /* 低通滤波器截止频率 */
+ struct {
+ /* 输入 */
+ struct {
+ float fric; /* 摩擦轮电机 */
+ float trig; /* 扳机电机 */
+ } in;
+
+ /* 输出 */
+ struct {
+ float fric; /* 摩擦轮电机 */
+ float trig; /* 扳机电机 */
+ } out;
+ } low_pass_cutoff_freq;
+
+ float num_trig_tooth; /* 拨弹盘中一圈能存储几颗弹丸 */
+ float fric_radius; /* 摩擦轮半径,单位:米 */
+ float cover_open_duty; /* 弹舱盖打开时舵机PWM占空比 */
+ float cover_close_duty; /* 弹舱盖关闭时舵机PWM占空比 */
+ float bullet_speed; /* 弹丸初速度 */
+ uint32_t min_shoot_delay; /* 通过设置最小射击间隔来设置最大射频 */
+} Shoot_Params_t;
+
+
+typedef struct {
+ uint32_t last_shoot; /* 上次射击时间 单位:ms */
+ bool last_fire; /* 上次开火状态 */
+ bool first_fire; /* 第一次收到开火指令 */
+ uint32_t shooted; /* 已经发射的弹丸 */
+ uint32_t to_shoot; /* 计划发射的弹丸 */
+ float bullet_speed; /* 弹丸初速度 */
+ uint32_t period_ms; /* 弹丸击发延迟 */
+} Shoot_FireCtrl_t;
+
+/*
+ * 运行的主结构体,所有这个文件里的函数都在操作这个结构体。
+ * 包含了初始化参数,中间变量,输出变量。
+ */
+typedef struct {
+ uint64_t lask_wakeup;
+ float dt;
+
+ const Shoot_Params_t *param; /* 射击的参数,用Shoot_Init设定 */
+ Shoot_FireCtrl_t fire_ctrl;
+ /* 模块通用 */
+ Shoot_Mode_t mode; /* 当前模式 */
+
+ /* 反馈信息 */
+ struct {
+ MOTOR_Feedback_t fric[2]; /* 摩擦轮电机反馈 */
+ MOTOR_Feedback_t trig; /* 拨弹电机反馈 */
+ } feedback;
+
+ /* PID计算的目标值 */
+ struct {
+ float fric_rpm[2]; /* 摩擦轮电机转速,单位:RPM */
+ float trig_angle; /* 拨弹电机角度,单位:弧度 */
+ } setpoint;
+
+ /* 反馈控制用的PID */
+ struct {
+ KPID_t fric[2]; /* 控制摩擦轮 */
+ KPID_t trig; /* 控制拨弹电机 */
+ } pid;
+
+ /* 过滤器 */
+ struct {
+ /* 反馈值滤波器 */
+ struct {
+ LowPassFilter2p_t fric[2]; /* 过滤摩擦轮 */
+ LowPassFilter2p_t trig; /* 过滤拨弹电机 */
+ } in;
+
+ /* 输出值滤波器 */
+ struct {
+ LowPassFilter2p_t fric[2]; /* 过滤摩擦轮 */
+ LowPassFilter2p_t trig; /* 过滤拨弹电机 */
+ } out;
+ } filter;
+
+} Shoot_t;
+
+/* Exported functions prototypes -------------------------------------------- */
+
+/**
+ * \brief 初始化射击
+ *
+ * \param s 包含射击数据的结构体
+ * \param param 包含射击参数的结构体指针
+ * \param target_freq 任务预期的运行频率
+ *
+ * \return 函数运行结果
+ */
+int8_t Shoot_Init(Shoot_t *s, const Shoot_Params_t *param, float target_freq);
+
+/**
+ * \brief 更新射击的反馈信息
+ *
+ * \param s 包含射击数据的结构体
+ * \param can CAN设备结构体
+ *
+ * \return 函数运行结果
+ */
+int8_t Shoot_UpdateFeedback(Shoot_t *s);
+
+/**
+ * \brief 运行射击控制逻辑
+ *
+ * \param s 包含射击数据的结构体
+ * \param s_cmd 射击控制指令
+ * \param s_ref 裁判系统数据
+ * \param dt_sec 两次调用的时间间隔
+ *
+ * \return 函数运行结果
+ */
+int8_t Shoot_Control(Shoot_t *s,Shoot_CMD_t *s_cmd);
+
+/**
+ * \brief 射击输出值
+ *
+ * \param s 包含射击数据的结构体
+ * \param out CAN设备射击输出结构体
+ */
+void Shoot_Output(Shoot_t *s);
+
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/User/task/monitor.c b/User/task/monitor.c
index 55d5bd3..82302c6 100644
--- a/User/task/monitor.c
+++ b/User/task/monitor.c
@@ -1,12 +1,14 @@
/*
monitor Task
-
*/
/* Includes ----------------------------------------------------------------- */
#include "task/user_task.h"
/* USER INCLUDE BEGIN */
-
+#include "bsp/time.h"
+#include "bsp/pwm.h"
+#include "component/user_math.h"
+#include
/* USER INCLUDE END */
/* Private typedef ---------------------------------------------------------- */
@@ -14,7 +16,7 @@
/* Private macro ------------------------------------------------------------ */
/* Private variables -------------------------------------------------------- */
/* USER STRUCT BEGIN */
-
+float led = 0.0f;
/* USER STRUCT END */
/* Private function --------------------------------------------------------- */
@@ -30,13 +32,15 @@ void Task_monitor(void *argument) {
uint32_t tick = osKernelGetTickCount(); /* 控制任务运行频率的计时 */
/* USER CODE INIT BEGIN */
-
+ BSP_PWM_SetComp(BSP_PWM_LED_G, led);
+ BSP_PWM_Start(BSP_PWM_LED_G);
/* USER CODE INIT END */
while (1) {
tick += delay_tick; /* 计算下一个唤醒时刻 */
/* USER CODE BEGIN */
-
+ led = fAbs(sinf(BSP_TIME_Get_ms()/1000.0f));
+ BSP_PWM_SetComp(BSP_PWM_LED_G, led);
/* USER CODE END */
osDelayUntil(tick); /* 运行结束,等待下一次唤醒 */
}
diff --git a/User/task/rc.c b/User/task/rc.c
index 8a154a0..4b40471 100644
--- a/User/task/rc.c
+++ b/User/task/rc.c
@@ -6,7 +6,7 @@
/* Includes ----------------------------------------------------------------- */
#include "task/user_task.h"
/* USER INCLUDE BEGIN */
-
+#include "device/dr16.h"
/* USER INCLUDE END */
/* Private typedef ---------------------------------------------------------- */
@@ -14,7 +14,7 @@
/* Private macro ------------------------------------------------------------ */
/* Private variables -------------------------------------------------------- */
/* USER STRUCT BEGIN */
-
+DR16_t dr16;
/* USER STRUCT END */
/* Private function --------------------------------------------------------- */
@@ -26,12 +26,17 @@ void Task_rc(void *argument) {
osDelay(RC_INIT_DELAY); /* 延时一段时间再开启任务 */
/* USER CODE INIT BEGIN */
-
+ DR16_Init(&dr16);
/* USER CODE INIT END */
while (1) {
/* USER CODE BEGIN */
-
+ DR16_StartDmaRecv(&dr16);
+ if (DR16_WaitDmaCplt(20)) {
+ DR16_ParseData(&dr16);
+ } else {
+ DR16_Offline(&dr16);
+ }
/* USER CODE END */
}
diff --git a/debug.jdebug b/debug.jdebug
new file mode 100644
index 0000000..022f68e
--- /dev/null
+++ b/debug.jdebug
@@ -0,0 +1,361 @@
+/*********************************************************************
+* (c) SEGGER Microcontroller GmbH *
+* The Embedded Experts *
+* www.segger.com *
+**********************************************************************
+
+File : /Users/lvzucheng/Documents/R/balance_infantry/debug.jdebug
+Created : 28 Sep 2025 16:36
+Ozone Version : V3.38d
+*/
+
+/*********************************************************************
+*
+* OnProjectLoad
+*
+* Function description
+* Project load routine. Required.
+*
+**********************************************************************
+*/
+void OnProjectLoad (void) {
+ //
+ // Dialog-generated settings
+ //
+ Project.AddPathSubstitute ("/Users/lvzucheng/Documents/R/balance_infantry", "$(ProjectDir)");
+ Project.AddPathSubstitute ("/users/lvzucheng/documents/r/balance_infantry", "$(ProjectDir)");
+ Project.SetDevice ("STM32F407IG");
+ Project.SetHostIF ("USB", "207400620");
+ Project.SetTargetIF ("SWD");
+ Project.SetTIFSpeed ("4 MHz");
+ Project.AddSvdFile ("$(InstallDir)/Config/CPU/Cortex-M4F.svd");
+ //
+ // User settings
+ //
+ File.Open ("$(ProjectDir)/build/Debug/DevC.elf");
+}
+
+/*********************************************************************
+*
+* OnStartupComplete
+*
+* Function description
+* Called when program execution has reached/passed
+* the startup completion point. Optional.
+*
+**********************************************************************
+*/
+//void OnStartupComplete (void) {
+//}
+
+/*********************************************************************
+*
+* TargetReset
+*
+* Function description
+* Replaces the default target device reset routine. Optional.
+*
+* Notes
+* This example demonstrates the usage when
+* debugging an application in RAM on a Cortex-M target device.
+*
+**********************************************************************
+*/
+//void TargetReset (void) {
+//
+// unsigned int SP;
+// unsigned int PC;
+// unsigned int VectorTableAddr;
+//
+// VectorTableAddr = Elf.GetBaseAddr();
+// //
+// // Set up initial stack pointer
+// //
+// if (VectorTableAddr != 0xFFFFFFFF) {
+// SP = Target.ReadU32(VectorTableAddr);
+// Target.SetReg("SP", SP);
+// }
+// //
+// // Set up entry point PC
+// //
+// PC = Elf.GetEntryPointPC();
+//
+// if (PC != 0xFFFFFFFF) {
+// Target.SetReg("PC", PC);
+// } else if (VectorTableAddr != 0xFFFFFFFF) {
+// PC = Target.ReadU32(VectorTableAddr + 4);
+// Target.SetReg("PC", PC);
+// } else {
+// Util.Error("Project file error: failed to set entry point PC", 1);
+// }
+//}
+
+/*********************************************************************
+*
+* BeforeTargetReset
+*
+* Function description
+* Event handler routine. Optional.
+*
+**********************************************************************
+*/
+//void BeforeTargetReset (void) {
+//}
+
+/*********************************************************************
+*
+* AfterTargetReset
+*
+* Function description
+* Event handler routine. Optional.
+* The default implementation initializes SP and PC to reset values.
+**
+**********************************************************************
+*/
+void AfterTargetReset (void) {
+ _SetupTarget();
+}
+
+/*********************************************************************
+*
+* DebugStart
+*
+* Function description
+* Replaces the default debug session startup routine. Optional.
+*
+**********************************************************************
+*/
+//void DebugStart (void) {
+//}
+
+/*********************************************************************
+*
+* TargetConnect
+*
+* Function description
+* Replaces the default target IF connection routine. Optional.
+*
+**********************************************************************
+*/
+//void TargetConnect (void) {
+//}
+
+/*********************************************************************
+*
+* BeforeTargetConnect
+*
+* Function description
+* Event handler routine. Optional.
+*
+**********************************************************************
+*/
+//void BeforeTargetConnect (void) {
+//}
+
+/*********************************************************************
+*
+* AfterTargetConnect
+*
+* Function description
+* Event handler routine. Optional.
+*
+**********************************************************************
+*/
+//void AfterTargetConnect (void) {
+//}
+
+/*********************************************************************
+*
+* TargetDownload
+*
+* Function description
+* Replaces the default program download routine. Optional.
+*
+**********************************************************************
+*/
+//void TargetDownload (void) {
+//}
+
+/*********************************************************************
+*
+* BeforeTargetDownload
+*
+* Function description
+* Event handler routine. Optional.
+*
+**********************************************************************
+*/
+//void BeforeTargetDownload (void) {
+//}
+
+/*********************************************************************
+*
+* AfterTargetDownload
+*
+* Function description
+* Event handler routine. Optional.
+* The default implementation initializes SP and PC to reset values.
+*
+**********************************************************************
+*/
+void AfterTargetDownload (void) {
+ _SetupTarget();
+}
+
+/*********************************************************************
+*
+* BeforeTargetDisconnect
+*
+* Function description
+* Event handler routine. Optional.
+*
+**********************************************************************
+*/
+//void BeforeTargetDisconnect (void) {
+//}
+
+/*********************************************************************
+*
+* AfterTargetDisconnect
+*
+* Function description
+* Event handler routine. Optional.
+*
+**********************************************************************
+*/
+//void AfterTargetDisconnect (void) {
+//}
+
+/*********************************************************************
+*
+* AfterTargetHalt
+*
+* Function description
+* Event handler routine. Optional.
+*
+**********************************************************************
+*/
+//void AfterTargetHalt (void) {
+//}
+
+/*********************************************************************
+*
+* BeforeTargetResume
+*
+* Function description
+* Event handler routine. Optional.
+*
+**********************************************************************
+*/
+//void BeforeTargetResume (void) {
+//}
+
+/*********************************************************************
+*
+* OnSnapshotLoad
+*
+* Function description
+* Called upon loading a snapshot. Optional.
+*
+* Additional information
+* This function is used to restore the target state in cases
+* where values cannot simply be written to the target.
+* Typical use: GPIO clock needs to be enabled, before
+* GPIO is configured.
+*
+**********************************************************************
+*/
+//void OnSnapshotLoad (void) {
+//}
+
+/*********************************************************************
+*
+* OnSnapshotSave
+*
+* Function description
+* Called upon saving a snapshot. Optional.
+*
+* Additional information
+* This function is usually used to save values of the target
+* state which can either not be trivially read,
+* or need to be restored in a specific way or order.
+* Typically use: Memory Mapped Registers,
+* such as PLL and GPIO configuration.
+*
+**********************************************************************
+*/
+//void OnSnapshotSave (void) {
+//}
+
+/*********************************************************************
+*
+* OnError
+*
+* Function description
+* Called when an error ocurred. Optional.
+*
+**********************************************************************
+*/
+//void OnError (void) {
+//}
+
+/*********************************************************************
+*
+* AfterProjectLoad
+*
+* Function description
+* After Project load routine. Optional.
+*
+**********************************************************************
+*/
+//void AfterProjectLoad (void) {
+//}
+
+/*********************************************************************
+*
+* OnDebugStartBreakSymbolReached
+*
+* Function description
+* Called when program execution has reached/passed
+* the symbol to be breaked at during debug start. Optional.
+*
+**********************************************************************
+*/
+//void OnDebugStartBreakSymReached (void) {
+//}
+
+/*********************************************************************
+*
+* _SetupTarget
+*
+* Function description
+* Setup the target.
+* Called by AfterTargetReset() and AfterTargetDownload().
+*
+* Auto-generated function. May be overridden by Ozone.
+*
+**********************************************************************
+*/
+void _SetupTarget(void) {
+ unsigned int SP;
+ unsigned int PC;
+ unsigned int VectorTableAddr;
+
+ VectorTableAddr = Elf.GetBaseAddr();
+ //
+ // Set up initial stack pointer
+ //
+ SP = Target.ReadU32(VectorTableAddr);
+ if (SP != 0xFFFFFFFF) {
+ Target.SetReg("SP", SP);
+ }
+ //
+ // Set up entry point PC
+ //
+ PC = Elf.GetEntryPointPC();
+ if (PC != 0xFFFFFFFF) {
+ Target.SetReg("PC", PC);
+ } else {
+ Util.Error("Project script error: failed to set up entry point PC", 1);
+ }
+}
\ No newline at end of file