添加music
This commit is contained in:
parent
e0dd2ed84a
commit
dd27f0ba8b
@ -77,7 +77,11 @@ target_sources(${CMAKE_PROJECT_NAME} PRIVATE
|
|||||||
|
|
||||||
# User/task sources
|
# User/task sources
|
||||||
User/task/atti_esit.c
|
User/task/atti_esit.c
|
||||||
|
User/task/blink.c
|
||||||
|
User/task/ctrl_chassis.c
|
||||||
|
User/task/ctrl_gimbal.c
|
||||||
User/task/init.c
|
User/task/init.c
|
||||||
|
User/task/monitor.c
|
||||||
User/task/rc.c
|
User/task/rc.c
|
||||||
User/task/user_task.c
|
User/task/user_task.c
|
||||||
)
|
)
|
||||||
|
|||||||
@ -67,6 +67,8 @@ void Error_Handler(void);
|
|||||||
#define ACCL_CS_GPIO_Port GPIOC
|
#define ACCL_CS_GPIO_Port GPIOC
|
||||||
#define GYRO_CS_Pin GPIO_PIN_3
|
#define GYRO_CS_Pin GPIO_PIN_3
|
||||||
#define GYRO_CS_GPIO_Port GPIOC
|
#define GYRO_CS_GPIO_Port GPIOC
|
||||||
|
#define WS2812_Pin GPIO_PIN_7
|
||||||
|
#define WS2812_GPIO_Port GPIOA
|
||||||
#define DCMI_PWDN_Pin GPIO_PIN_5
|
#define DCMI_PWDN_Pin GPIO_PIN_5
|
||||||
#define DCMI_PWDN_GPIO_Port GPIOC
|
#define DCMI_PWDN_GPIO_Port GPIOC
|
||||||
#define IMU_HEAT_Pin GPIO_PIN_1
|
#define IMU_HEAT_Pin GPIO_PIN_1
|
||||||
|
|||||||
@ -180,6 +180,10 @@ void MX_TIM3_Init(void)
|
|||||||
sConfigOC.Pulse = 0;
|
sConfigOC.Pulse = 0;
|
||||||
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
|
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
|
||||||
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
|
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
|
||||||
|
if (HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_2) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
if (HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_4) != HAL_OK)
|
if (HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_4) != HAL_OK)
|
||||||
{
|
{
|
||||||
Error_Handler();
|
Error_Handler();
|
||||||
@ -336,10 +340,19 @@ void HAL_TIM_MspPostInit(TIM_HandleTypeDef* timHandle)
|
|||||||
|
|
||||||
/* USER CODE END TIM3_MspPostInit 0 */
|
/* USER CODE END TIM3_MspPostInit 0 */
|
||||||
|
|
||||||
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||||
/**TIM3 GPIO Configuration
|
/**TIM3 GPIO Configuration
|
||||||
|
PA7 ------> TIM3_CH2
|
||||||
PB1 ------> TIM3_CH4
|
PB1 ------> TIM3_CH4
|
||||||
*/
|
*/
|
||||||
|
GPIO_InitStruct.Pin = WS2812_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||||
|
GPIO_InitStruct.Alternate = GPIO_AF2_TIM3;
|
||||||
|
HAL_GPIO_Init(WS2812_GPIO_Port, &GPIO_InitStruct);
|
||||||
|
|
||||||
GPIO_InitStruct.Pin = IMU_HEAT_Pin;
|
GPIO_InitStruct.Pin = IMU_HEAT_Pin;
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
|||||||
@ -182,63 +182,64 @@ Mcu.Pin12=PA1
|
|||||||
Mcu.Pin13=PA2
|
Mcu.Pin13=PA2
|
||||||
Mcu.Pin14=PA3
|
Mcu.Pin14=PA3
|
||||||
Mcu.Pin15=PA5
|
Mcu.Pin15=PA5
|
||||||
Mcu.Pin16=PC4
|
Mcu.Pin16=PA7
|
||||||
Mcu.Pin17=PC5
|
Mcu.Pin17=PC4
|
||||||
Mcu.Pin18=PB0
|
Mcu.Pin18=PC5
|
||||||
Mcu.Pin19=PB1
|
Mcu.Pin19=PB0
|
||||||
Mcu.Pin2=PC13
|
Mcu.Pin2=PC13
|
||||||
Mcu.Pin20=PB2
|
Mcu.Pin20=PB1
|
||||||
Mcu.Pin21=PE7
|
Mcu.Pin21=PB2
|
||||||
Mcu.Pin22=PE8
|
Mcu.Pin22=PE7
|
||||||
Mcu.Pin23=PE9
|
Mcu.Pin23=PE8
|
||||||
Mcu.Pin24=PE10
|
Mcu.Pin24=PE9
|
||||||
Mcu.Pin25=PE11
|
Mcu.Pin25=PE10
|
||||||
Mcu.Pin26=PE12
|
Mcu.Pin26=PE11
|
||||||
Mcu.Pin27=PE13
|
Mcu.Pin27=PE12
|
||||||
Mcu.Pin28=PE15
|
Mcu.Pin28=PE13
|
||||||
Mcu.Pin29=PB10
|
Mcu.Pin29=PE15
|
||||||
Mcu.Pin3=PC14-OSC32_IN
|
Mcu.Pin3=PC14-OSC32_IN
|
||||||
Mcu.Pin30=PB11
|
Mcu.Pin30=PB10
|
||||||
Mcu.Pin31=PB12
|
Mcu.Pin31=PB11
|
||||||
Mcu.Pin32=PB13
|
Mcu.Pin32=PB12
|
||||||
Mcu.Pin33=PB14
|
Mcu.Pin33=PB13
|
||||||
Mcu.Pin34=PB15
|
Mcu.Pin34=PB14
|
||||||
Mcu.Pin35=PD8
|
Mcu.Pin35=PB15
|
||||||
Mcu.Pin36=PD9
|
Mcu.Pin36=PD8
|
||||||
Mcu.Pin37=PD10
|
Mcu.Pin37=PD9
|
||||||
Mcu.Pin38=PD11
|
Mcu.Pin38=PD10
|
||||||
Mcu.Pin39=PD12
|
Mcu.Pin39=PD11
|
||||||
Mcu.Pin4=PC15-OSC32_OUT
|
Mcu.Pin4=PC15-OSC32_OUT
|
||||||
Mcu.Pin40=PD13
|
Mcu.Pin40=PD12
|
||||||
Mcu.Pin41=PA8
|
Mcu.Pin41=PD13
|
||||||
Mcu.Pin42=PA9
|
Mcu.Pin42=PA8
|
||||||
Mcu.Pin43=PA10
|
Mcu.Pin43=PA9
|
||||||
Mcu.Pin44=PA11
|
Mcu.Pin44=PA10
|
||||||
Mcu.Pin45=PA12
|
Mcu.Pin45=PA11
|
||||||
Mcu.Pin46=PA13(JTMS/SWDIO)
|
Mcu.Pin46=PA12
|
||||||
Mcu.Pin47=PA14(JTCK/SWCLK)
|
Mcu.Pin47=PA13(JTMS/SWDIO)
|
||||||
Mcu.Pin48=PA15(JTDI)
|
Mcu.Pin48=PA14(JTCK/SWCLK)
|
||||||
Mcu.Pin49=PC12
|
Mcu.Pin49=PA15(JTDI)
|
||||||
Mcu.Pin5=PH0-OSC_IN
|
Mcu.Pin5=PH0-OSC_IN
|
||||||
Mcu.Pin50=PD0
|
Mcu.Pin50=PC12
|
||||||
Mcu.Pin51=PD1
|
Mcu.Pin51=PD0
|
||||||
Mcu.Pin52=PD2
|
Mcu.Pin52=PD1
|
||||||
Mcu.Pin53=PD4
|
Mcu.Pin53=PD2
|
||||||
Mcu.Pin54=PD5
|
Mcu.Pin54=PD4
|
||||||
Mcu.Pin55=PD6
|
Mcu.Pin55=PD5
|
||||||
Mcu.Pin56=PD7
|
Mcu.Pin56=PD6
|
||||||
Mcu.Pin57=PB3(JTDO/TRACESWO)
|
Mcu.Pin57=PD7
|
||||||
Mcu.Pin58=PB5
|
Mcu.Pin58=PB3(JTDO/TRACESWO)
|
||||||
Mcu.Pin59=PB6
|
Mcu.Pin59=PB5
|
||||||
Mcu.Pin6=PH1-OSC_OUT
|
Mcu.Pin6=PH1-OSC_OUT
|
||||||
Mcu.Pin60=VP_FREERTOS_VS_CMSIS_V2
|
Mcu.Pin60=PB6
|
||||||
Mcu.Pin61=VP_OCTOSPI1_VS_octo
|
Mcu.Pin61=VP_FREERTOS_VS_CMSIS_V2
|
||||||
Mcu.Pin62=VP_SYS_VS_tim23
|
Mcu.Pin62=VP_OCTOSPI1_VS_octo
|
||||||
Mcu.Pin63=VP_MEMORYMAP_VS_MEMORYMAP
|
Mcu.Pin63=VP_SYS_VS_tim23
|
||||||
|
Mcu.Pin64=VP_MEMORYMAP_VS_MEMORYMAP
|
||||||
Mcu.Pin7=PC0
|
Mcu.Pin7=PC0
|
||||||
Mcu.Pin8=PC1
|
Mcu.Pin8=PC1
|
||||||
Mcu.Pin9=PC2_C
|
Mcu.Pin9=PC2_C
|
||||||
Mcu.PinsNb=64
|
Mcu.PinsNb=65
|
||||||
Mcu.ThirdPartyNb=0
|
Mcu.ThirdPartyNb=0
|
||||||
Mcu.UserConstants=
|
Mcu.UserConstants=
|
||||||
Mcu.UserName=STM32H723VGTx
|
Mcu.UserName=STM32H723VGTx
|
||||||
@ -306,6 +307,10 @@ PA3.Mode=OCTOSPI1_IOL_Port1L
|
|||||||
PA3.Signal=OCTOSPIM_P1_IO2
|
PA3.Signal=OCTOSPIM_P1_IO2
|
||||||
PA5.Locked=true
|
PA5.Locked=true
|
||||||
PA5.Signal=ADCx_INP19
|
PA5.Signal=ADCx_INP19
|
||||||
|
PA7.GPIOParameters=GPIO_Label
|
||||||
|
PA7.GPIO_Label=WS2812
|
||||||
|
PA7.Locked=true
|
||||||
|
PA7.Signal=S_TIM3_CH2
|
||||||
PA8.Locked=true
|
PA8.Locked=true
|
||||||
PA8.Mode=Clock-out-1
|
PA8.Mode=Clock-out-1
|
||||||
PA8.Signal=RCC_MCO_1
|
PA8.Signal=RCC_MCO_1
|
||||||
@ -609,6 +614,8 @@ SH.S_TIM2_CH1_ETR.0=TIM2_CH1,PWM Generation1 CH1
|
|||||||
SH.S_TIM2_CH1_ETR.ConfNb=1
|
SH.S_TIM2_CH1_ETR.ConfNb=1
|
||||||
SH.S_TIM2_CH3.0=TIM2_CH3,PWM Generation3 CH3
|
SH.S_TIM2_CH3.0=TIM2_CH3,PWM Generation3 CH3
|
||||||
SH.S_TIM2_CH3.ConfNb=1
|
SH.S_TIM2_CH3.ConfNb=1
|
||||||
|
SH.S_TIM3_CH2.0=TIM3_CH2,PWM Generation2 CH2
|
||||||
|
SH.S_TIM3_CH2.ConfNb=1
|
||||||
SH.S_TIM3_CH4.0=TIM3_CH4,PWM Generation4 CH4
|
SH.S_TIM3_CH4.0=TIM3_CH4,PWM Generation4 CH4
|
||||||
SH.S_TIM3_CH4.ConfNb=1
|
SH.S_TIM3_CH4.ConfNb=1
|
||||||
SPI1.BaudRatePrescaler=SPI_BAUDRATEPRESCALER_4
|
SPI1.BaudRatePrescaler=SPI_BAUDRATEPRESCALER_4
|
||||||
@ -647,8 +654,9 @@ TIM2.Prescaler=24
|
|||||||
TIM2.Pulse-PWM\ Generation1\ CH1=5000
|
TIM2.Pulse-PWM\ Generation1\ CH1=5000
|
||||||
TIM2.Pulse-PWM\ Generation3\ CH3=5000
|
TIM2.Pulse-PWM\ Generation3\ CH3=5000
|
||||||
TIM3.AutoReloadPreload=TIM_AUTORELOAD_PRELOAD_ENABLE
|
TIM3.AutoReloadPreload=TIM_AUTORELOAD_PRELOAD_ENABLE
|
||||||
|
TIM3.Channel-PWM\ Generation2\ CH2=TIM_CHANNEL_2
|
||||||
TIM3.Channel-PWM\ Generation4\ CH4=TIM_CHANNEL_4
|
TIM3.Channel-PWM\ Generation4\ CH4=TIM_CHANNEL_4
|
||||||
TIM3.IPParameters=Channel-PWM Generation4 CH4,Prescaler,Period,AutoReloadPreload
|
TIM3.IPParameters=Channel-PWM Generation4 CH4,Prescaler,Period,AutoReloadPreload,Channel-PWM Generation2 CH2
|
||||||
TIM3.Period=10000-1
|
TIM3.Period=10000-1
|
||||||
TIM3.Prescaler=24-1
|
TIM3.Prescaler=24-1
|
||||||
UART5.BaudRate=100000
|
UART5.BaudRate=100000
|
||||||
@ -683,3 +691,4 @@ VP_OCTOSPI1_VS_octo.Signal=OCTOSPI1_VS_octo
|
|||||||
VP_SYS_VS_tim23.Mode=TIM23
|
VP_SYS_VS_tim23.Mode=TIM23
|
||||||
VP_SYS_VS_tim23.Signal=SYS_VS_tim23
|
VP_SYS_VS_tim23.Signal=SYS_VS_tim23
|
||||||
board=custom
|
board=custom
|
||||||
|
rtos.0.ip=FREERTOS
|
||||||
|
|||||||
@ -92,6 +92,10 @@ pwm:
|
|||||||
custom_name: TIM2_CH3
|
custom_name: TIM2_CH3
|
||||||
label: TIM2_CH3
|
label: TIM2_CH3
|
||||||
timer: TIM2
|
timer: TIM2
|
||||||
|
- channel: TIM_CHANNEL_2
|
||||||
|
custom_name: WS2812
|
||||||
|
label: WS2812
|
||||||
|
timer: TIM3
|
||||||
- channel: TIM_CHANNEL_4
|
- channel: TIM_CHANNEL_4
|
||||||
custom_name: IMU_HEAT
|
custom_name: IMU_HEAT
|
||||||
label: IMU_HEAT
|
label: IMU_HEAT
|
||||||
|
|||||||
@ -27,6 +27,7 @@ typedef struct {
|
|||||||
static const BSP_PWM_Config_t PWM_Map[BSP_PWM_NUM] = {
|
static const BSP_PWM_Config_t PWM_Map[BSP_PWM_NUM] = {
|
||||||
{&htim2, TIM_CHANNEL_1},
|
{&htim2, TIM_CHANNEL_1},
|
||||||
{&htim2, TIM_CHANNEL_3},
|
{&htim2, TIM_CHANNEL_3},
|
||||||
|
{&htim3, TIM_CHANNEL_2},
|
||||||
{&htim3, TIM_CHANNEL_4},
|
{&htim3, TIM_CHANNEL_4},
|
||||||
{&htim12, TIM_CHANNEL_2},
|
{&htim12, TIM_CHANNEL_2},
|
||||||
{&htim1, TIM_CHANNEL_3},
|
{&htim1, TIM_CHANNEL_3},
|
||||||
|
|||||||
@ -25,6 +25,7 @@ extern "C" {
|
|||||||
typedef enum {
|
typedef enum {
|
||||||
BSP_PWM_TIM2_CH1,
|
BSP_PWM_TIM2_CH1,
|
||||||
BSP_PWM_TIM2_CH3,
|
BSP_PWM_TIM2_CH3,
|
||||||
|
BSP_PWM_WS2812,
|
||||||
BSP_PWM_IMU_HEAT,
|
BSP_PWM_IMU_HEAT,
|
||||||
BSP_PWM_BUZZER,
|
BSP_PWM_BUZZER,
|
||||||
BSP_PWM_TIM1_CH3,
|
BSP_PWM_TIM1_CH3,
|
||||||
|
|||||||
@ -8,7 +8,7 @@ bmi088:
|
|||||||
enabled: true
|
enabled: true
|
||||||
buzzer:
|
buzzer:
|
||||||
bsp_config:
|
bsp_config:
|
||||||
BSP_PWM_BUZZER: BSP_PWM_TIM2_CH1
|
BSP_PWM_BUZZER: BSP_PWM_BUZZER
|
||||||
enabled: true
|
enabled: true
|
||||||
dr16:
|
dr16:
|
||||||
bsp_config:
|
bsp_config:
|
||||||
|
|||||||
@ -111,21 +111,11 @@ static int8_t MOTOR_DM_SendMITCmd(MOTOR_DM_t *motor, MOTOR_MIT_Output_t *output)
|
|||||||
uint16_t pos_tmp,vel_tmp,kp_tmp,kd_tmp,tor_tmp;
|
uint16_t pos_tmp,vel_tmp,kp_tmp,kd_tmp,tor_tmp;
|
||||||
uint16_t id = motor->param.can_id;
|
uint16_t id = motor->param.can_id;
|
||||||
|
|
||||||
/* 根据 reverse 参数调整控制值 */
|
pos_tmp = float_to_uint(output->angle, DM_P_MIN , DM_P_MAX, 16);
|
||||||
float angle = output->angle;
|
vel_tmp = float_to_uint(output->velocity, DM_V_MIN , DM_V_MAX, 12);
|
||||||
float velocity = output->velocity;
|
|
||||||
float torque = output->torque;
|
|
||||||
if (motor->param.reverse) {
|
|
||||||
angle = -angle;
|
|
||||||
velocity = -velocity;
|
|
||||||
torque = -torque;
|
|
||||||
}
|
|
||||||
|
|
||||||
pos_tmp = float_to_uint(angle, DM_P_MIN , DM_P_MAX, 16);
|
|
||||||
vel_tmp = float_to_uint(velocity, DM_V_MIN , DM_V_MAX, 12);
|
|
||||||
kp_tmp = float_to_uint(output->kp, DM_KP_MIN, DM_KP_MAX, 12);
|
kp_tmp = float_to_uint(output->kp, DM_KP_MIN, DM_KP_MAX, 12);
|
||||||
kd_tmp = float_to_uint(output->kd, DM_KD_MIN, DM_KD_MAX, 12);
|
kd_tmp = float_to_uint(output->kd, DM_KD_MIN, DM_KD_MAX, 12);
|
||||||
tor_tmp = float_to_uint(torque, DM_T_MIN , DM_T_MAX, 12);
|
tor_tmp = float_to_uint(output->torque, DM_T_MIN , DM_T_MAX, 12);
|
||||||
|
|
||||||
/* 打包数据 */
|
/* 打包数据 */
|
||||||
data[0] = (pos_tmp >> 8);
|
data[0] = (pos_tmp >> 8);
|
||||||
@ -161,11 +151,6 @@ static int8_t MOTOR_DM_SendPosVelCmd(MOTOR_DM_t *motor, float pos, float vel) {
|
|||||||
|
|
||||||
uint8_t data[8] = {0};
|
uint8_t data[8] = {0};
|
||||||
|
|
||||||
/* 根据 reverse 参数调整控制值 */
|
|
||||||
if (motor->param.reverse) {
|
|
||||||
pos = -pos;
|
|
||||||
vel = -vel;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 直接发送浮点数数据 */
|
/* 直接发送浮点数数据 */
|
||||||
memcpy(&data[0], &pos, 4); // 位置,低位在前
|
memcpy(&data[0], &pos, 4); // 位置,低位在前
|
||||||
@ -194,11 +179,6 @@ static int8_t MOTOR_DM_SendVelCmd(MOTOR_DM_t *motor, float vel) {
|
|||||||
|
|
||||||
uint8_t data[4] = {0};
|
uint8_t data[4] = {0};
|
||||||
|
|
||||||
/* 根据 reverse 参数调整控制值 */
|
|
||||||
if (motor->param.reverse) {
|
|
||||||
vel = -vel;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 直接发送浮点数数据 */
|
/* 直接发送浮点数数据 */
|
||||||
memcpy(&data[0], &vel, 4); // 速度,低位在前
|
memcpy(&data[0], &vel, 4); // 速度,低位在前
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
atti_esit Task
|
atti_esit Task
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Includes ----------------------------------------------------------------- */
|
/* Includes ----------------------------------------------------------------- */
|
||||||
@ -49,6 +49,7 @@ static const KPID_Params_t imu_temp_ctrl_pid_param = {
|
|||||||
void Task_atti_esit(void *argument) {
|
void Task_atti_esit(void *argument) {
|
||||||
(void)argument; /* 未使用argument,消除警告 */
|
(void)argument; /* 未使用argument,消除警告 */
|
||||||
|
|
||||||
|
|
||||||
osDelay(ATTI_ESIT_INIT_DELAY); /* 延时一段时间再开启任务 */
|
osDelay(ATTI_ESIT_INIT_DELAY); /* 延时一段时间再开启任务 */
|
||||||
|
|
||||||
/* USER CODE INIT BEGIN */
|
/* USER CODE INIT BEGIN */
|
||||||
@ -86,4 +87,5 @@ void Task_atti_esit(void *argument) {
|
|||||||
|
|
||||||
/* USER CODE END */
|
/* USER CODE END */
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
57
User/task/blink.c
Normal file
57
User/task/blink.c
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
blink Task
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Includes ----------------------------------------------------------------- */
|
||||||
|
#include "task/user_task.h"
|
||||||
|
/* USER INCLUDE BEGIN */
|
||||||
|
#include "device/buzzer.h"
|
||||||
|
#include <stdint.h>
|
||||||
|
/* USER INCLUDE END */
|
||||||
|
|
||||||
|
/* Private typedef ---------------------------------------------------------- */
|
||||||
|
/* Private define ----------------------------------------------------------- */
|
||||||
|
/* Private macro ------------------------------------------------------------ */
|
||||||
|
/* Private variables -------------------------------------------------------- */
|
||||||
|
/* USER STRUCT BEGIN */
|
||||||
|
BUZZER_t buzzer;
|
||||||
|
static uint16_t count;
|
||||||
|
/* USER STRUCT END */
|
||||||
|
|
||||||
|
/* Private function --------------------------------------------------------- */
|
||||||
|
/* Exported functions ------------------------------------------------------- */
|
||||||
|
void Task_blink(void *argument) {
|
||||||
|
(void)argument; /* 未使用argument,消除警告 */
|
||||||
|
|
||||||
|
|
||||||
|
/* 计算任务运行到指定频率需要等待的tick数 */
|
||||||
|
const uint32_t delay_tick = osKernelGetTickFreq() / BLINK_FREQ;
|
||||||
|
|
||||||
|
osDelay(BLINK_INIT_DELAY); /* 延时一段时间再开启任务 */
|
||||||
|
|
||||||
|
uint32_t tick = osKernelGetTickCount(); /* 控制任务运行频率的计时 */
|
||||||
|
/* USER CODE INIT BEGIN */
|
||||||
|
/* 播放启动音乐 */
|
||||||
|
BUZZER_Init(&buzzer, BSP_PWM_BUZZER);
|
||||||
|
BUZZER_PlayMusic(&buzzer, MUSIC_RM);
|
||||||
|
/* USER CODE INIT END */
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
tick += delay_tick; /* 计算下一个唤醒时刻 */
|
||||||
|
/* USER CODE BEGIN */
|
||||||
|
count++;
|
||||||
|
uint16_t phase = count % 1000;
|
||||||
|
if (phase == 0) {
|
||||||
|
/* 每秒开始播放C4音符 */
|
||||||
|
BUZZER_Set(&buzzer, 261.63f, 0.5f); // C4音符频率约261.63Hz
|
||||||
|
BUZZER_Start(&buzzer);
|
||||||
|
} else if (phase == 50) {
|
||||||
|
/* 播放100ms后停止 (50/500Hz = 0.1s) */
|
||||||
|
BUZZER_Stop(&buzzer);
|
||||||
|
}
|
||||||
|
/* USER CODE END */
|
||||||
|
osDelayUntil(tick); /* 运行结束,等待下一次唤醒 */
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -11,3 +11,31 @@
|
|||||||
function: Task_atti_esit
|
function: Task_atti_esit
|
||||||
name: atti_esit
|
name: atti_esit
|
||||||
stack: 256
|
stack: 256
|
||||||
|
- delay: 0
|
||||||
|
description: ''
|
||||||
|
freq_control: true
|
||||||
|
frequency: 500.0
|
||||||
|
function: Task_ctrl_chassis
|
||||||
|
name: ctrl_chassis
|
||||||
|
stack: 256
|
||||||
|
- delay: 0
|
||||||
|
description: ''
|
||||||
|
freq_control: true
|
||||||
|
frequency: 500.0
|
||||||
|
function: Task_ctrl_gimbal
|
||||||
|
name: ctrl_gimbal
|
||||||
|
stack: 256
|
||||||
|
- delay: 0
|
||||||
|
description: ''
|
||||||
|
freq_control: true
|
||||||
|
frequency: 500.0
|
||||||
|
function: Task_monitor
|
||||||
|
name: monitor
|
||||||
|
stack: 256
|
||||||
|
- delay: 0
|
||||||
|
description: ''
|
||||||
|
freq_control: true
|
||||||
|
frequency: 500.0
|
||||||
|
function: Task_blink
|
||||||
|
name: blink
|
||||||
|
stack: 256
|
||||||
|
|||||||
53
User/task/ctrl_chassis.c
Normal file
53
User/task/ctrl_chassis.c
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
ctrl_chassis Task
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Includes ----------------------------------------------------------------- */
|
||||||
|
#include "task/user_task.h"
|
||||||
|
/* USER INCLUDE BEGIN */
|
||||||
|
#include "bsp/can.h"
|
||||||
|
#include "device/motor.h"
|
||||||
|
#include "device/motor_lk.h"
|
||||||
|
#include "device/motor_lz.h"
|
||||||
|
/* USER INCLUDE END */
|
||||||
|
|
||||||
|
/* Private typedef ---------------------------------------------------------- */
|
||||||
|
/* Private define ----------------------------------------------------------- */
|
||||||
|
/* Private macro ------------------------------------------------------------ */
|
||||||
|
/* Private variables -------------------------------------------------------- */
|
||||||
|
/* USER STRUCT BEGIN */
|
||||||
|
MOTOR_LK_Param_t chassis_motor_params[4] = {
|
||||||
|
{BSP_CAN_1, 0x201, MOTOR_LK_MF9025, false},
|
||||||
|
{BSP_CAN_1, 0x202, MOTOR_LK_MF9025, false},
|
||||||
|
{BSP_CAN_1, 0x203, MOTOR_LK_MF9025, false},
|
||||||
|
{BSP_CAN_1, 0x204, MOTOR_LK_MF9025, false}
|
||||||
|
};
|
||||||
|
/* USER STRUCT END */
|
||||||
|
|
||||||
|
/* Private function --------------------------------------------------------- */
|
||||||
|
/* Exported functions ------------------------------------------------------- */
|
||||||
|
void Task_ctrl_chassis(void *argument) {
|
||||||
|
(void)argument; /* 未使用argument,消除警告 */
|
||||||
|
|
||||||
|
|
||||||
|
/* 计算任务运行到指定频率需要等待的tick数 */
|
||||||
|
const uint32_t delay_tick = osKernelGetTickFreq() / CTRL_CHASSIS_FREQ;
|
||||||
|
|
||||||
|
osDelay(CTRL_CHASSIS_INIT_DELAY); /* 延时一段时间再开启任务 */
|
||||||
|
|
||||||
|
uint32_t tick = osKernelGetTickCount(); /* 控制任务运行频率的计时 */
|
||||||
|
/* USER CODE INIT BEGIN */
|
||||||
|
BSP_CAN_Init();
|
||||||
|
/* USER CODE INIT END */
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
tick += delay_tick; /* 计算下一个唤醒时刻 */
|
||||||
|
/* USER CODE BEGIN */
|
||||||
|
MOTOR_LK_SetOutput(&chassis_motor_params[0], 0.5f);
|
||||||
|
MOTOR_LK_Ctrl(&chassis_motor_params[0]);
|
||||||
|
|
||||||
|
/* USER CODE END */
|
||||||
|
osDelayUntil(tick); /* 运行结束,等待下一次唤醒 */
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
44
User/task/ctrl_gimbal.c
Normal file
44
User/task/ctrl_gimbal.c
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
ctrl_gimbal Task
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Includes ----------------------------------------------------------------- */
|
||||||
|
#include "task/user_task.h"
|
||||||
|
/* USER INCLUDE BEGIN */
|
||||||
|
|
||||||
|
/* USER INCLUDE END */
|
||||||
|
|
||||||
|
/* Private typedef ---------------------------------------------------------- */
|
||||||
|
/* Private define ----------------------------------------------------------- */
|
||||||
|
/* Private macro ------------------------------------------------------------ */
|
||||||
|
/* Private variables -------------------------------------------------------- */
|
||||||
|
/* USER STRUCT BEGIN */
|
||||||
|
|
||||||
|
/* USER STRUCT END */
|
||||||
|
|
||||||
|
/* Private function --------------------------------------------------------- */
|
||||||
|
/* Exported functions ------------------------------------------------------- */
|
||||||
|
void Task_ctrl_gimbal(void *argument) {
|
||||||
|
(void)argument; /* 未使用argument,消除警告 */
|
||||||
|
|
||||||
|
|
||||||
|
/* 计算任务运行到指定频率需要等待的tick数 */
|
||||||
|
const uint32_t delay_tick = osKernelGetTickFreq() / CTRL_GIMBAL_FREQ;
|
||||||
|
|
||||||
|
osDelay(CTRL_GIMBAL_INIT_DELAY); /* 延时一段时间再开启任务 */
|
||||||
|
|
||||||
|
uint32_t tick = osKernelGetTickCount(); /* 控制任务运行频率的计时 */
|
||||||
|
/* USER CODE INIT BEGIN */
|
||||||
|
|
||||||
|
/* USER CODE INIT END */
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
tick += delay_tick; /* 计算下一个唤醒时刻 */
|
||||||
|
/* USER CODE BEGIN */
|
||||||
|
|
||||||
|
/* USER CODE END */
|
||||||
|
osDelayUntil(tick); /* 运行结束,等待下一次唤醒 */
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -32,6 +32,10 @@ void Task_Init(void *argument) {
|
|||||||
/* 创建任务线程 */
|
/* 创建任务线程 */
|
||||||
task_runtime.thread.rc = osThreadNew(Task_rc, NULL, &attr_rc);
|
task_runtime.thread.rc = osThreadNew(Task_rc, NULL, &attr_rc);
|
||||||
task_runtime.thread.atti_esit = osThreadNew(Task_atti_esit, NULL, &attr_atti_esit);
|
task_runtime.thread.atti_esit = osThreadNew(Task_atti_esit, NULL, &attr_atti_esit);
|
||||||
|
task_runtime.thread.ctrl_chassis = osThreadNew(Task_ctrl_chassis, NULL, &attr_ctrl_chassis);
|
||||||
|
task_runtime.thread.ctrl_gimbal = osThreadNew(Task_ctrl_gimbal, NULL, &attr_ctrl_gimbal);
|
||||||
|
task_runtime.thread.monitor = osThreadNew(Task_monitor, NULL, &attr_monitor);
|
||||||
|
task_runtime.thread.blink = osThreadNew(Task_blink, NULL, &attr_blink);
|
||||||
|
|
||||||
// 创建消息队列
|
// 创建消息队列
|
||||||
/* USER MESSAGE BEGIN */
|
/* USER MESSAGE BEGIN */
|
||||||
|
|||||||
44
User/task/monitor.c
Normal file
44
User/task/monitor.c
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
monitor Task
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Includes ----------------------------------------------------------------- */
|
||||||
|
#include "task/user_task.h"
|
||||||
|
/* USER INCLUDE BEGIN */
|
||||||
|
|
||||||
|
/* USER INCLUDE END */
|
||||||
|
|
||||||
|
/* Private typedef ---------------------------------------------------------- */
|
||||||
|
/* Private define ----------------------------------------------------------- */
|
||||||
|
/* Private macro ------------------------------------------------------------ */
|
||||||
|
/* Private variables -------------------------------------------------------- */
|
||||||
|
/* USER STRUCT BEGIN */
|
||||||
|
|
||||||
|
/* USER STRUCT END */
|
||||||
|
|
||||||
|
/* Private function --------------------------------------------------------- */
|
||||||
|
/* Exported functions ------------------------------------------------------- */
|
||||||
|
void Task_monitor(void *argument) {
|
||||||
|
(void)argument; /* 未使用argument,消除警告 */
|
||||||
|
|
||||||
|
|
||||||
|
/* 计算任务运行到指定频率需要等待的tick数 */
|
||||||
|
const uint32_t delay_tick = osKernelGetTickFreq() / MONITOR_FREQ;
|
||||||
|
|
||||||
|
osDelay(MONITOR_INIT_DELAY); /* 延时一段时间再开启任务 */
|
||||||
|
|
||||||
|
uint32_t tick = osKernelGetTickCount(); /* 控制任务运行频率的计时 */
|
||||||
|
/* USER CODE INIT BEGIN */
|
||||||
|
|
||||||
|
/* USER CODE INIT END */
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
tick += delay_tick; /* 计算下一个唤醒时刻 */
|
||||||
|
/* USER CODE BEGIN */
|
||||||
|
|
||||||
|
/* USER CODE END */
|
||||||
|
osDelayUntil(tick); /* 运行结束,等待下一次唤醒 */
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -4,7 +4,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/* Includes ----------------------------------------------------------------- */
|
/* Includes ----------------------------------------------------------------- */
|
||||||
#include "device/dr16.h"
|
|
||||||
#include "task/user_task.h"
|
#include "task/user_task.h"
|
||||||
/* USER INCLUDE BEGIN */
|
/* USER INCLUDE BEGIN */
|
||||||
#include "device/dr16.h"
|
#include "device/dr16.h"
|
||||||
|
|||||||
@ -18,4 +18,24 @@ const osThreadAttr_t attr_atti_esit = {
|
|||||||
.name = "atti_esit",
|
.name = "atti_esit",
|
||||||
.priority = osPriorityNormal,
|
.priority = osPriorityNormal,
|
||||||
.stack_size = 256 * 4,
|
.stack_size = 256 * 4,
|
||||||
|
};
|
||||||
|
const osThreadAttr_t attr_ctrl_chassis = {
|
||||||
|
.name = "ctrl_chassis",
|
||||||
|
.priority = osPriorityNormal,
|
||||||
|
.stack_size = 256 * 4,
|
||||||
|
};
|
||||||
|
const osThreadAttr_t attr_ctrl_gimbal = {
|
||||||
|
.name = "ctrl_gimbal",
|
||||||
|
.priority = osPriorityNormal,
|
||||||
|
.stack_size = 256 * 4,
|
||||||
|
};
|
||||||
|
const osThreadAttr_t attr_monitor = {
|
||||||
|
.name = "monitor",
|
||||||
|
.priority = osPriorityNormal,
|
||||||
|
.stack_size = 256 * 4,
|
||||||
|
};
|
||||||
|
const osThreadAttr_t attr_blink = {
|
||||||
|
.name = "blink",
|
||||||
|
.priority = osPriorityNormal,
|
||||||
|
.stack_size = 256 * 4,
|
||||||
};
|
};
|
||||||
@ -14,11 +14,19 @@ extern "C" {
|
|||||||
/* Exported constants ------------------------------------------------------- */
|
/* Exported constants ------------------------------------------------------- */
|
||||||
/* 任务运行频率 */
|
/* 任务运行频率 */
|
||||||
#define RC_FREQ (500.0)
|
#define RC_FREQ (500.0)
|
||||||
|
#define CTRL_CHASSIS_FREQ (500.0)
|
||||||
|
#define CTRL_GIMBAL_FREQ (500.0)
|
||||||
|
#define MONITOR_FREQ (500.0)
|
||||||
|
#define BLINK_FREQ (500.0)
|
||||||
|
|
||||||
/* 任务初始化延时ms */
|
/* 任务初始化延时ms */
|
||||||
#define TASK_INIT_DELAY (100u)
|
#define TASK_INIT_DELAY (100u)
|
||||||
#define RC_INIT_DELAY (0)
|
#define RC_INIT_DELAY (0)
|
||||||
#define ATTI_ESIT_INIT_DELAY (0)
|
#define ATTI_ESIT_INIT_DELAY (0)
|
||||||
|
#define CTRL_CHASSIS_INIT_DELAY (0)
|
||||||
|
#define CTRL_GIMBAL_INIT_DELAY (0)
|
||||||
|
#define MONITOR_INIT_DELAY (0)
|
||||||
|
#define BLINK_INIT_DELAY (0)
|
||||||
|
|
||||||
/* Exported defines --------------------------------------------------------- */
|
/* Exported defines --------------------------------------------------------- */
|
||||||
/* Exported macro ----------------------------------------------------------- */
|
/* Exported macro ----------------------------------------------------------- */
|
||||||
@ -30,6 +38,10 @@ typedef struct {
|
|||||||
struct {
|
struct {
|
||||||
osThreadId_t rc;
|
osThreadId_t rc;
|
||||||
osThreadId_t atti_esit;
|
osThreadId_t atti_esit;
|
||||||
|
osThreadId_t ctrl_chassis;
|
||||||
|
osThreadId_t ctrl_gimbal;
|
||||||
|
osThreadId_t monitor;
|
||||||
|
osThreadId_t blink;
|
||||||
} thread;
|
} thread;
|
||||||
|
|
||||||
/* USER MESSAGE BEGIN */
|
/* USER MESSAGE BEGIN */
|
||||||
@ -53,16 +65,28 @@ typedef struct {
|
|||||||
struct {
|
struct {
|
||||||
UBaseType_t rc;
|
UBaseType_t rc;
|
||||||
UBaseType_t atti_esit;
|
UBaseType_t atti_esit;
|
||||||
|
UBaseType_t ctrl_chassis;
|
||||||
|
UBaseType_t ctrl_gimbal;
|
||||||
|
UBaseType_t monitor;
|
||||||
|
UBaseType_t blink;
|
||||||
} stack_water_mark;
|
} stack_water_mark;
|
||||||
|
|
||||||
/* 各任务运行频率 */
|
/* 各任务运行频率 */
|
||||||
struct {
|
struct {
|
||||||
float rc;
|
float rc;
|
||||||
|
float ctrl_chassis;
|
||||||
|
float ctrl_gimbal;
|
||||||
|
float monitor;
|
||||||
|
float blink;
|
||||||
} freq;
|
} freq;
|
||||||
|
|
||||||
/* 任务最近运行时间 */
|
/* 任务最近运行时间 */
|
||||||
struct {
|
struct {
|
||||||
float rc;
|
float rc;
|
||||||
|
float ctrl_chassis;
|
||||||
|
float ctrl_gimbal;
|
||||||
|
float monitor;
|
||||||
|
float blink;
|
||||||
} last_up_time;
|
} last_up_time;
|
||||||
|
|
||||||
} Task_Runtime_t;
|
} Task_Runtime_t;
|
||||||
@ -74,11 +98,19 @@ extern Task_Runtime_t task_runtime;
|
|||||||
extern const osThreadAttr_t attr_init;
|
extern const osThreadAttr_t attr_init;
|
||||||
extern const osThreadAttr_t attr_rc;
|
extern const osThreadAttr_t attr_rc;
|
||||||
extern const osThreadAttr_t attr_atti_esit;
|
extern const osThreadAttr_t attr_atti_esit;
|
||||||
|
extern const osThreadAttr_t attr_ctrl_chassis;
|
||||||
|
extern const osThreadAttr_t attr_ctrl_gimbal;
|
||||||
|
extern const osThreadAttr_t attr_monitor;
|
||||||
|
extern const osThreadAttr_t attr_blink;
|
||||||
|
|
||||||
/* 任务函数声明 */
|
/* 任务函数声明 */
|
||||||
void Task_Init(void *argument);
|
void Task_Init(void *argument);
|
||||||
void Task_rc(void *argument);
|
void Task_rc(void *argument);
|
||||||
void Task_atti_esit(void *argument);
|
void Task_atti_esit(void *argument);
|
||||||
|
void Task_ctrl_chassis(void *argument);
|
||||||
|
void Task_ctrl_gimbal(void *argument);
|
||||||
|
void Task_monitor(void *argument);
|
||||||
|
void Task_blink(void *argument);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user