From 4d94d15052b046d79ea76ed14bcbaa132198265b Mon Sep 17 00:00:00 2001 From: ws <1621320660@qq.com> Date: Thu, 13 Mar 2025 19:23:24 +0800 Subject: [PATCH] =?UTF-8?q?=E8=9C=82=E9=B8=A3=E5=99=A8=E9=9F=B3=E6=95=88?= =?UTF-8?q?=EF=BC=8C=E5=8A=A0=E4=BA=86=E4=B8=80=E5=9D=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Core/Inc/main.h | 8 ++ Core/Inc/tim.h | 3 + Core/Src/gpio.c | 10 +++ Core/Src/main.c | 3 + Core/Src/tim.c | 109 +++++++++++++++++++++++++- MDK-ARM/.vscode/c_cpp_properties.json | 36 ++++----- MDK-ARM/.vscode/keil-assistant.log | 32 ++++++++ MDK-ARM/.vscode/settings.json | 8 +- MDK-ARM/.vscode/uv4.log | 16 +--- MDK-ARM/.vscode/uv4.log.lock | 2 +- MDK-ARM/mycode1.uvoptx | 93 ++++++++++++++++------ MDK-ARM/mycode1.uvprojx | 20 +++++ README.md | 9 ++- User/device/odrive_can.h | 2 - User/module/ball.c | 88 +++++++++++++++++++++ User/module/ball.h | 19 +++++ User/module/buzzer.c | 79 +++++++++++++++++++ User/module/buzzer.h | 53 +++++++++++++ User/module/dji.c | 41 +++++++++- User/module/dji.h | 23 +----- User/module/go.c | 9 +-- User/module/shoot.c | 77 ++++++++++++++++++ User/module/shoot.h | 26 ++++++ User/task/attrTask.c | 7 +- User/task/attrTask.h | 8 +- User/task/ball_task.c | 29 +++++++ User/task/ball_task.h | 5 ++ User/task/can_task.c | 6 +- User/task/dji_task.c | 13 +-- User/task/initTask.c | 5 +- User/task/led_task.c | 6 +- User/task/nuc_task.c | 8 +- User/task/shoot_task.c | 36 +++++---- mycode1.ioc | 53 ++++++++++--- 34 files changed, 803 insertions(+), 139 deletions(-) create mode 100644 User/module/ball.c create mode 100644 User/module/ball.h create mode 100644 User/module/buzzer.c create mode 100644 User/module/buzzer.h create mode 100644 User/module/shoot.c create mode 100644 User/module/shoot.h create mode 100644 User/task/ball_task.c create mode 100644 User/task/ball_task.h diff --git a/Core/Inc/main.h b/Core/Inc/main.h index af97aee..4d96a1f 100644 --- a/Core/Inc/main.h +++ b/Core/Inc/main.h @@ -69,6 +69,14 @@ void Error_Handler(void); #define LED_G_GPIO_Port GPIOH #define LED_B_Pin GPIO_PIN_10 #define LED_B_GPIO_Port GPIOH +#define buzzer_Pin GPIO_PIN_14 +#define buzzer_GPIO_Port GPIOD +#define down_Pin GPIO_PIN_13 +#define down_GPIO_Port GPIOE +#define key_Pin GPIO_PIN_11 +#define key_GPIO_Port GPIOE +#define paw_Pin GPIO_PIN_14 +#define paw_GPIO_Port GPIOE #define SPI_CS_Pin GPIO_PIN_12 #define SPI_CS_GPIO_Port GPIOB diff --git a/Core/Inc/tim.h b/Core/Inc/tim.h index 504bb7d..a500c01 100644 --- a/Core/Inc/tim.h +++ b/Core/Inc/tim.h @@ -34,11 +34,14 @@ extern "C" { extern TIM_HandleTypeDef htim1; +extern TIM_HandleTypeDef htim4; + /* USER CODE BEGIN Private defines */ /* USER CODE END Private defines */ void MX_TIM1_Init(void); +void MX_TIM4_Init(void); void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim); diff --git a/Core/Src/gpio.c b/Core/Src/gpio.c index 6f6d0f0..9ec8b3b 100644 --- a/Core/Src/gpio.c +++ b/Core/Src/gpio.c @@ -57,6 +57,9 @@ void MX_GPIO_Init(void) /*Configure GPIO pin Output Level */ HAL_GPIO_WritePin(GPIOH, LED_R_Pin|LED_G_Pin|LED_B_Pin, GPIO_PIN_RESET); + /*Configure GPIO pin Output Level */ + HAL_GPIO_WritePin(GPIOE, down_Pin|key_Pin|paw_Pin, GPIO_PIN_RESET); + /*Configure GPIO pin Output Level */ HAL_GPIO_WritePin(SPI_CS_GPIO_Port, SPI_CS_Pin, GPIO_PIN_RESET); @@ -79,6 +82,13 @@ void MX_GPIO_Init(void) GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOH, &GPIO_InitStruct); + /*Configure GPIO pins : PEPin PEPin PEPin */ + GPIO_InitStruct.Pin = down_Pin|key_Pin|paw_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + HAL_GPIO_Init(GPIOE, &GPIO_InitStruct); + /*Configure GPIO pin : PtPin */ GPIO_InitStruct.Pin = SPI_CS_Pin; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; diff --git a/Core/Src/main.c b/Core/Src/main.c index 3b8f610..fc3f03b 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -101,9 +101,12 @@ int main(void) MX_USART6_UART_Init(); MX_TIM1_Init(); MX_SPI2_Init(); + MX_TIM4_Init(); /* USER CODE BEGIN 2 */ //HAL_TIM_Base_Start(&htim1); //HAL_TIM_PWM_Start(&htim1,TIM_CHANNEL_1 ); + HAL_TIM_Base_Start(&htim4); + HAL_TIM_PWM_Start(&htim4, TIM_CHANNEL_3); /* USER CODE END 2 */ /* Init scheduler */ diff --git a/Core/Src/tim.c b/Core/Src/tim.c index 54d7046..03e5679 100644 --- a/Core/Src/tim.c +++ b/Core/Src/tim.c @@ -25,6 +25,7 @@ /* USER CODE END 0 */ TIM_HandleTypeDef htim1; +TIM_HandleTypeDef htim4; /* TIM1 init function */ void MX_TIM1_Init(void) @@ -85,6 +86,60 @@ void MX_TIM1_Init(void) /* USER CODE END TIM1_Init 2 */ HAL_TIM_MspPostInit(&htim1); +} +/* TIM4 init function */ +void MX_TIM4_Init(void) +{ + + /* USER CODE BEGIN TIM4_Init 0 */ + + /* USER CODE END TIM4_Init 0 */ + + TIM_ClockConfigTypeDef sClockSourceConfig = {0}; + TIM_MasterConfigTypeDef sMasterConfig = {0}; + TIM_OC_InitTypeDef sConfigOC = {0}; + + /* USER CODE BEGIN TIM4_Init 1 */ + + /* USER CODE END TIM4_Init 1 */ + htim4.Instance = TIM4; + htim4.Init.Prescaler = 0; + htim4.Init.CounterMode = TIM_COUNTERMODE_UP; + htim4.Init.Period = 20999; + htim4.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; + htim4.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; + if (HAL_TIM_Base_Init(&htim4) != HAL_OK) + { + Error_Handler(); + } + sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; + if (HAL_TIM_ConfigClockSource(&htim4, &sClockSourceConfig) != HAL_OK) + { + Error_Handler(); + } + if (HAL_TIM_PWM_Init(&htim4) != HAL_OK) + { + Error_Handler(); + } + sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; + sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; + if (HAL_TIMEx_MasterConfigSynchronization(&htim4, &sMasterConfig) != HAL_OK) + { + Error_Handler(); + } + sConfigOC.OCMode = TIM_OCMODE_PWM1; + sConfigOC.Pulse = 0; + sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH; + sConfigOC.OCFastMode = TIM_OCFAST_DISABLE; + if (HAL_TIM_PWM_ConfigChannel(&htim4, &sConfigOC, TIM_CHANNEL_3) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN TIM4_Init 2 */ + + /* USER CODE END TIM4_Init 2 */ + HAL_TIM_MspPostInit(&htim4); + } void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef* tim_pwmHandle) @@ -102,6 +157,22 @@ void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef* tim_pwmHandle) /* USER CODE END TIM1_MspInit 1 */ } } + +void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle) +{ + + if(tim_baseHandle->Instance==TIM4) + { + /* USER CODE BEGIN TIM4_MspInit 0 */ + + /* USER CODE END TIM4_MspInit 0 */ + /* TIM4 clock enable */ + __HAL_RCC_TIM4_CLK_ENABLE(); + /* USER CODE BEGIN TIM4_MspInit 1 */ + + /* USER CODE END TIM4_MspInit 1 */ + } +} void HAL_TIM_MspPostInit(TIM_HandleTypeDef* timHandle) { @@ -111,7 +182,6 @@ void HAL_TIM_MspPostInit(TIM_HandleTypeDef* timHandle) /* USER CODE BEGIN TIM1_MspPostInit 0 */ /* USER CODE END TIM1_MspPostInit 0 */ - __HAL_RCC_GPIOE_CLK_ENABLE(); /**TIM1 GPIO Configuration PE9 ------> TIM1_CH1 @@ -127,6 +197,27 @@ void HAL_TIM_MspPostInit(TIM_HandleTypeDef* timHandle) /* USER CODE END TIM1_MspPostInit 1 */ } + else if(timHandle->Instance==TIM4) + { + /* USER CODE BEGIN TIM4_MspPostInit 0 */ + + /* USER CODE END TIM4_MspPostInit 0 */ + + __HAL_RCC_GPIOD_CLK_ENABLE(); + /**TIM4 GPIO Configuration + PD14 ------> TIM4_CH3 + */ + GPIO_InitStruct.Pin = buzzer_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_TIM4; + HAL_GPIO_Init(buzzer_GPIO_Port, &GPIO_InitStruct); + + /* USER CODE BEGIN TIM4_MspPostInit 1 */ + + /* USER CODE END TIM4_MspPostInit 1 */ + } } @@ -146,6 +237,22 @@ void HAL_TIM_PWM_MspDeInit(TIM_HandleTypeDef* tim_pwmHandle) } } +void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* tim_baseHandle) +{ + + if(tim_baseHandle->Instance==TIM4) + { + /* USER CODE BEGIN TIM4_MspDeInit 0 */ + + /* USER CODE END TIM4_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_TIM4_CLK_DISABLE(); + /* USER CODE BEGIN TIM4_MspDeInit 1 */ + + /* USER CODE END TIM4_MspDeInit 1 */ + } +} + /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ diff --git a/MDK-ARM/.vscode/c_cpp_properties.json b/MDK-ARM/.vscode/c_cpp_properties.json index 013ae45..c93e7bd 100644 --- a/MDK-ARM/.vscode/c_cpp_properties.json +++ b/MDK-ARM/.vscode/c_cpp_properties.json @@ -3,26 +3,26 @@ { "name": "mycode1", "includePath": [ - "d:\\Desktop\\mycode -vision\\Core\\Inc", - "d:\\Desktop\\mycode -vision\\Drivers\\STM32F4xx_HAL_Driver\\Inc", - "d:\\Desktop\\mycode -vision\\Drivers\\STM32F4xx_HAL_Driver\\Inc\\Legacy", - "d:\\Desktop\\mycode -vision\\Middlewares\\Third_Party\\FreeRTOS\\Source\\include", - "d:\\Desktop\\mycode -vision\\Middlewares\\Third_Party\\FreeRTOS\\Source\\CMSIS_RTOS_V2", - "d:\\Desktop\\mycode -vision\\Middlewares\\Third_Party\\FreeRTOS\\Source\\portable\\RVDS\\ARM_CM4F", - "d:\\Desktop\\mycode -vision\\Drivers\\CMSIS\\Device\\ST\\STM32F4xx\\Include", - "d:\\Desktop\\mycode -vision\\Drivers\\CMSIS\\Include", - "d:\\Desktop\\mycode -vision\\User\\bsp", - "d:\\Desktop\\mycode -vision\\User\\device", - "d:\\Desktop\\mycode -vision\\User\\lib", - "d:\\Desktop\\mycode -vision\\User\\module", - "d:\\Desktop\\mycode -vision\\User\\task", + "d:\\Desktop\\mycode-shoot\\shoot\\Core\\Inc", + "d:\\Desktop\\mycode-shoot\\shoot\\Drivers\\STM32F4xx_HAL_Driver\\Inc", + "d:\\Desktop\\mycode-shoot\\shoot\\Drivers\\STM32F4xx_HAL_Driver\\Inc\\Legacy", + "d:\\Desktop\\mycode-shoot\\shoot\\Middlewares\\Third_Party\\FreeRTOS\\Source\\include", + "d:\\Desktop\\mycode-shoot\\shoot\\Middlewares\\Third_Party\\FreeRTOS\\Source\\CMSIS_RTOS_V2", + "d:\\Desktop\\mycode-shoot\\shoot\\Middlewares\\Third_Party\\FreeRTOS\\Source\\portable\\RVDS\\ARM_CM4F", + "d:\\Desktop\\mycode-shoot\\shoot\\Drivers\\CMSIS\\Device\\ST\\STM32F4xx\\Include", + "d:\\Desktop\\mycode-shoot\\shoot\\Drivers\\CMSIS\\Include", + "d:\\Desktop\\mycode-shoot\\shoot\\User\\bsp", + "d:\\Desktop\\mycode-shoot\\shoot\\User\\device", + "d:\\Desktop\\mycode-shoot\\shoot\\User\\lib", + "d:\\Desktop\\mycode-shoot\\shoot\\User\\module", + "d:\\Desktop\\mycode-shoot\\shoot\\User\\task", "D:\\keil\\ARM\\ARMCC\\include", "D:\\keil\\ARM\\ARMCC\\include\\rw", - "d:\\Desktop\\mycode -vision\\MDK-ARM", - "d:\\Desktop\\mycode -vision\\Core\\Src", - "d:\\Desktop\\mycode -vision\\Drivers\\STM32F4xx_HAL_Driver\\Src", - "d:\\Desktop\\mycode -vision\\Middlewares\\Third_Party\\FreeRTOS\\Source", - "d:\\Desktop\\mycode -vision\\Middlewares\\Third_Party\\FreeRTOS\\Source\\portable\\MemMang" + "d:\\Desktop\\mycode-shoot\\shoot\\MDK-ARM", + "d:\\Desktop\\mycode-shoot\\shoot\\Core\\Src", + "d:\\Desktop\\mycode-shoot\\shoot\\Drivers\\STM32F4xx_HAL_Driver\\Src", + "d:\\Desktop\\mycode-shoot\\shoot\\Middlewares\\Third_Party\\FreeRTOS\\Source", + "d:\\Desktop\\mycode-shoot\\shoot\\Middlewares\\Third_Party\\FreeRTOS\\Source\\portable\\MemMang" ], "defines": [ "USE_HAL_DRIVER", diff --git a/MDK-ARM/.vscode/keil-assistant.log b/MDK-ARM/.vscode/keil-assistant.log index 185a137..f82290b 100644 --- a/MDK-ARM/.vscode/keil-assistant.log +++ b/MDK-ARM/.vscode/keil-assistant.log @@ -16,3 +16,35 @@ [info] Log at : 2025/3/12|23:02:19|GMT+0800 +[info] Log at : 2025/3/12|23:23:36|GMT+0800 + +[info] Log at : 2025/3/13|10:52:41|GMT+0800 + +[info] Log at : 2025/3/13|11:23:36|GMT+0800 + +[info] Log at : 2025/3/13|11:29:50|GMT+0800 + +[info] Log at : 2025/3/13|11:32:26|GMT+0800 + +[info] Log at : 2025/3/13|11:48:43|GMT+0800 + +[info] Log at : 2025/3/13|11:49:08|GMT+0800 + +[info] Log at : 2025/3/13|11:52:00|GMT+0800 + +[info] Log at : 2025/3/13|11:52:12|GMT+0800 + +[info] Log at : 2025/3/13|11:52:29|GMT+0800 + +[info] Log at : 2025/3/13|11:52:40|GMT+0800 + +[info] Log at : 2025/3/13|13:05:40|GMT+0800 + +[info] Log at : 2025/3/13|13:05:50|GMT+0800 + +[info] Log at : 2025/3/13|13:09:23|GMT+0800 + +[info] Log at : 2025/3/13|13:09:39|GMT+0800 + +[info] Log at : 2025/3/13|14:46:01|GMT+0800 + diff --git a/MDK-ARM/.vscode/settings.json b/MDK-ARM/.vscode/settings.json index ce95e9a..3e1fb17 100644 --- a/MDK-ARM/.vscode/settings.json +++ b/MDK-ARM/.vscode/settings.json @@ -10,6 +10,12 @@ "can_task.h": "c", "go_m8010_6_driver.h": "c", "read_spi.h": "c", - "djimotor.h": "c" + "djimotor.h": "c", + "buzzer.h": "c", + "main.h": "c", + "ball.h": "c", + "shoot.h": "c", + "dji.h": "c", + "calc_lib.h": "c" } } \ No newline at end of file diff --git a/MDK-ARM/.vscode/uv4.log b/MDK-ARM/.vscode/uv4.log index 04c4d17..2a2628d 100644 --- a/MDK-ARM/.vscode/uv4.log +++ b/MDK-ARM/.vscode/uv4.log @@ -1,13 +1,3 @@ -*** Using Compiler 'V5.06 update 7 (build 960)', folder: 'D:\keil\ARM\ARMCC\Bin' -Build target 'mycode1' -compiling dji_task.c... -compiling dji.c... -compiling djiMotor.c... -compiling shoot_task.c... -compiling can_task.c... -compiling odrive_shoot.c... -linking... -Program Size: Code=26064 RO-data=1860 RW-data=284 ZI-data=22276 -FromELF: creating hex file... -"mycode1\mycode1.axf" - 0 Error(s), 0 Warning(s). -Build Time Elapsed: 00:00:04 +Load "mycode1\\mycode1.axf" +Erase Done.Programming Done.Verify OK.Application running ... +Flash Load finished at 19:18:06 diff --git a/MDK-ARM/.vscode/uv4.log.lock b/MDK-ARM/.vscode/uv4.log.lock index 77846cf..13666e4 100644 --- a/MDK-ARM/.vscode/uv4.log.lock +++ b/MDK-ARM/.vscode/uv4.log.lock @@ -1 +1 @@ -2025/3/12 20:09:49 \ No newline at end of file +2025/3/13 19:18:07 \ No newline at end of file diff --git a/MDK-ARM/mycode1.uvoptx b/MDK-ARM/mycode1.uvoptx index bf8fa64..b4bc059 100644 --- a/MDK-ARM/mycode1.uvoptx +++ b/MDK-ARM/mycode1.uvoptx @@ -153,62 +153,57 @@ 0 1 - go + cmd_fromnuc 1 1 - Temp_buffer + nucbuf 2 1 - cmd_fromnuc + motor_3508_data,0x0A 3 1 - nucbuf + speed,0x0A 4 1 - motor_3508_data,0x0A + RC_mess,0x0A 5 1 - speed,0x0A + M3508_speed_PID 6 1 - RC_mess + M3508_angle_PID 7 1 - M3508_speed_PID + angle,0x0A 8 1 - M3508_angle_PID + m,0x0A 9 1 - angle,0x0A + go 10 1 - m,0x0A - - - 11 - 1 - go + basketball,0x0A @@ -1048,6 +1043,42 @@ 0 0 + + 9 + 60 + 1 + 0 + 0 + 0 + ..\User\module\buzzer.c + buzzer.c + 0 + 0 + + + 9 + 61 + 1 + 0 + 0 + 0 + ..\User\module\ball.c + ball.c + 0 + 0 + + + 9 + 62 + 1 + 0 + 0 + 0 + ..\User\module\shoot.c + shoot.c + 0 + 0 + @@ -1058,7 +1089,7 @@ 0 10 - 60 + 63 1 0 0 @@ -1070,7 +1101,7 @@ 10 - 61 + 64 1 0 0 @@ -1082,7 +1113,7 @@ 10 - 62 + 65 1 0 0 @@ -1094,7 +1125,7 @@ 10 - 63 + 66 1 0 0 @@ -1106,7 +1137,7 @@ 10 - 64 + 67 1 0 0 @@ -1118,7 +1149,7 @@ 10 - 65 + 68 1 0 0 @@ -1130,7 +1161,7 @@ 10 - 66 + 69 1 0 0 @@ -1142,7 +1173,7 @@ 10 - 67 + 70 1 0 0 @@ -1154,7 +1185,7 @@ 10 - 68 + 71 1 0 0 @@ -1164,6 +1195,18 @@ 0 0 + + 10 + 72 + 1 + 0 + 0 + 0 + ..\User\task\ball_task.c + ball_task.c + 0 + 0 + diff --git a/MDK-ARM/mycode1.uvprojx b/MDK-ARM/mycode1.uvprojx index 4e3e11a..6a9cf52 100644 --- a/MDK-ARM/mycode1.uvprojx +++ b/MDK-ARM/mycode1.uvprojx @@ -820,6 +820,21 @@ 1 ..\User\module\odrive_shoot.c + + buzzer.c + 1 + ..\User\module\buzzer.c + + + ball.c + 1 + ..\User\module\ball.c + + + shoot.c + 1 + ..\User\module\shoot.c + @@ -870,6 +885,11 @@ 1 ..\User\task\rc_task.c + + ball_task.c + 1 + ..\User\task\ball_task.c + diff --git a/README.md b/README.md index 12f22ce..2c04db8 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,8 @@ -# shoot +# myshoot -r1上层 \ No newline at end of file +## r1上层 + +1. **odrive**推射 **can1** **id 010** **spi2**读取as5047p +2. go1 RS485模块 01翻转 02云台 +3. 爪子 左三PC6 +4. 接球 左一左2 PI7 PI6 \ No newline at end of file diff --git a/User/device/odrive_can.h b/User/device/odrive_can.h index ece8251..4769619 100644 --- a/User/device/odrive_can.h +++ b/User/device/odrive_can.h @@ -136,8 +136,6 @@ device_status_e odrive_pos_cmd(node_id_e node_id, fp32 pos); */ odrive_msg_t* Get_Odrive_Point(void); -void odrive_CB(void); - void User_Odrive_Can1_CB(void); void User_Odrive_Can2_CB(void); diff --git a/User/module/ball.c b/User/module/ball.c new file mode 100644 index 0000000..11f6cf1 --- /dev/null +++ b/User/module/ball.c @@ -0,0 +1,88 @@ +#include "ball.h" +#include "main.h" +#include "cmsis_os.h" +#include "FreeRTOS.h" +#include "bsp_delay.h" + +#define ballcome 1 +#define balldown 0 + +//光电识别 +int ball_in(void) +{ + if (HAL_GPIO_ReadPin(ball_up_GPIO_Port, ball_up_Pin) == GPIO_PIN_SET) + { + return ballcome; + } + else + { + return balldown; + } + + +} +int pass_ball(void) +{ + + if (HAL_GPIO_ReadPin(ball_in1_GPIO_Port, ball_in1_Pin) == GPIO_PIN_SET) + { + return ballcome; + } + else + { + return balldown; + } + +} + + + + +//运球 +void handling_ball(int hand, int paw) +{ + paw =ball_in(); + if (hand == 1 && paw == 1) + { + //爪子 + delay_us(100); + HAL_GPIO_WritePin(paw_GPIO_Port, paw_Pin, GPIO_PIN_RESET); + osDelay(2); + delay_us(100); + //上推 + HAL_GPIO_WritePin(down_GPIO_Port, down_Pin, GPIO_PIN_RESET); + hand=0; + } + else + { + + //爪子 + HAL_GPIO_WritePin(paw_GPIO_Port, paw_Pin, GPIO_PIN_SET); + osDelay(2); + delay_us(100); + //下推 + HAL_GPIO_WritePin(down_GPIO_Port, down_Pin, GPIO_PIN_SET); + } + + + + +} + + + +//接球 +int catch_ball(int inball) +{ + inball =pass_ball(); + if(inball==1) + { + return ballcome; + } + else + { + return balldown; + } + + +} diff --git a/User/module/ball.h b/User/module/ball.h new file mode 100644 index 0000000..cc2eacf --- /dev/null +++ b/User/module/ball.h @@ -0,0 +1,19 @@ +#ifndef _BALL_H_ +#define _BALL_H_ + +typedef struct ball +{ + int hand;//运球 + int paw;//爪 + int inball;//光电门 + int to_shoot;//给发射 +}BASKETBALL; + + +int ball_in(void); +int pass_ball(void); +void handling_ball(int hand, int paw); +int catch_ball(int inball); + + +#endif diff --git a/User/module/buzzer.c b/User/module/buzzer.c new file mode 100644 index 0000000..2b1e7fd --- /dev/null +++ b/User/module/buzzer.c @@ -0,0 +1,79 @@ +#include "buzzer.h" + +uint32_t Frequency = 0; +uint32_t CLOCK = 10500000; +int i; + +int pwm = MIN_BUZZER_PWM; +int psc = 0; + +unsigned int notes[] = { + G3,C4,D4s,D4,C4,D4s,C4,D4,C4,G3s,A3s,G3, + G3,C4,D4s,D4,C4,D4s,C4,D4,C4,G3,F3s,F3, + F3,G3s,B3,D4, F3,G3s,B3,C4, + C4,D4s,A4s,G4s,G4,A4s,G4s,G4s,G4,G4,B3,C4, + C5,C5,B4,A4s, A4s,D5,C5,G4s,G4, + G4,A4s,G4,F4, F4,G4s,G4,F4,G4 + }; + unsigned int duration[] = { + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5, + 1, 1, 1, 5, 1, 1, 1, 4, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5, + 1, 1, 1, 3, 1, 2, 1, 1, 4, + 1, 1, 1, 3, 1, 2, 1, 1, 4 + }; + +void buzzer_on(uint16_t note) { + Frequency = CLOCK / note; // 计算定时器的重载值 + + htim4.Init.Prescaler = 0; // 预分频器设置为0 + htim4.Init.Period = Frequency; // 设置定时器的重载值 + + // 设置PWM的占空比为50% + __HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_3, Frequency / 2); + + // 启动PWM + HAL_TIM_PWM_Start(&htim4, TIM_CHANNEL_3); +} + +void noTone(void){ + __HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_3, 0); + HAL_Delay(30); +} + + +void playSong(void){ + for (i = 0; i < sizeof(notes)/sizeof(notes[0]); i++) { + Frequency = CLOCK / notes[i]; // 计算定时器的重载值 + htim4.Instance->ARR = Frequency; // 设置定时器的重载值 + __HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_3, Frequency / 2);// 设置PWM的占空比为50% + HAL_Delay(400*duration[i]); + noTone(); + } +} + + +void set_buzzer_frequency(uint32_t freq){ + __HAL_TIM_SetAutoreload(&htim4, freq); + __HAL_TIM_SetCompare(&htim4, TIM_CHANNEL_3, freq/2); + } + uint32_t music[3][205]={{9, 10, 9, 6, 9, 0, 6, 10, 9, 10, 12, 10, 9, 10, 9, 6, 8, 0, 10, 9, 12, 10}, {5, 9, 8, 3, 0, 8, 9, 10, 9, 8, 9, 5, 9, 8, 3, 0, 8, 9, 10, 9, 8, 9, 5, 9, 8, 3, 0, 8, 9, 10, 9, 8, 9, 5, 9, 8, 3, 0, 8, 10, 12, 13, 12, 0, 8, 9, 9, 8, 9, 10, 0, 10, 12, 13, 14, 13, 12, 10, 9, 9, 8, 9, 9, 9, 8, 0, 8, 10, 12, 13, 12, 0, 8, 9, 9, 8, 10, 0, 9, 10, 12, 13, 15, 16, 17, 16, 15, 12, 13, 15, 17, 17, 17, 16, 0, 12, 13, 15, 17, 17, 17, 16, 0}}; + uint32_t lst[3][205]={{ 1, 1, 1, 1, 4, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 2, 2, 1, 1, 2}, {2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 6, 6, 3, 1, 2, 2, 2, 2, 4, 2, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 5, 1, 1, 1, 6, 6, 3, 1, 2, 2, 2, 2, 4, 1, 1, 2, 2, 2, 2, 2, 2, 2, 1, 1, 2, 2, 2, 2, 2, 4, 1, 1, 2, 2, 2, 2, 2, 8}}; + uint32_t tones[]={21000000, 262, 294, 330, 349, 392, 440, 494, 523, 587, 659, 698, 784, 880, 988, 1046, 1174, 1318, 1396, 1568, 1760, 1976}; + uint32_t lenth[]={22, 103}; + + uint32_t frequency = 21000000; + uint32_t nw = 0, time_base = 125; + uint32_t song = 1; + + void see_you_again(void) + { + set_buzzer_frequency(frequency/tones[music[song][nw]]); + /* USER CODE BEGIN 3 */ + HAL_Delay(time_base*lst[song][nw]-time_base*1/4); + set_buzzer_frequency(frequency/tones[0]); + HAL_Delay(time_base*1/64); + nw = (nw + 1) % lenth[song]; + +} diff --git a/User/module/buzzer.h b/User/module/buzzer.h new file mode 100644 index 0000000..5d4c62c --- /dev/null +++ b/User/module/buzzer.h @@ -0,0 +1,53 @@ +#ifndef _BUZZER_H_ +#define _BUZZER_H_ + +#include "tim.h" + +#define MIN_BUZZER_PWM ((uint32_t)10000) +#define MAX_BUZZER_PWM ((uint32_t)20000) +#define MAX_PSC ((uint32_t)1000) +#define C3 131 +#define C3s 139 +#define D3 147 +#define D3s 156 +#define E3 165 +#define F3 175 +#define F3s 185 +#define G3 196 +#define G3s 208 +#define A3 220 +#define A3s 233 +#define B3 247 +#define C4 262 +#define C4s 277 +#define D4 294 +#define D4s 311 +#define E4 330 +#define F4 349 +#define F4s 370 +#define G4 392 +#define G4s 415 +#define A4 440 +#define A4s 466 +#define B4 494 +#define C5 523 +#define C5s 554 +#define D5 587 +#define D5s 622 +#define E5 659 +#define F5 698 +#define F5s 740 +#define G5 784 +#define G5s 831 +#define A5 880 +#define A5s 932 +#define B5 988 +#define C6 1047 + + + void buzzer_on(uint16_t note); + void noTone(void); + void playSong(void); + void see_you_again(void); + +#endif diff --git a/User/module/dji.c b/User/module/dji.c index e27a6e7..4160532 100644 --- a/User/module/dji.c +++ b/User/module/dji.c @@ -26,17 +26,49 @@ fp32 M3508_PID[3]={4.9,0.01,0.0}; int16_t result; //速度环 float angleSet[MOTOR_NUM]; //位置环 +//trigger +//编码器数据 +const motor_measure_t *trigger_motor_data;//3508电机数据 + +pid_type_def t_speed_pid;//2006速度环pid结构体 +pid_type_def t_angle_pid;//2006位置环pid结构体 + +fp32 M2006_speed_PID[3]={5.0,0.3,0.0}; //P,I,D(速度环) +fp32 M2006_angle_PID[3]={25.0,0.0,1.5}; //P,I,D(角度环) +//速度环pid参数 +fp32 M2006_PID[3]={4.9,0.01,0.0}; + +int16_t t_result; //速度环 //can最后发送的数据 +float t_angleSet[1]; //位置环 + + + void motor_init(void) { - motor_3508_data=get_motor_point(0); - +// motor_3508_data=get_motor_point(0); + trigger_motor_data=get_motor_point(0); // PID_init(&speed_pid,PID_POSITION,M3508_speed_PID,3000,1000); // PID_init(&angle_pid,PID_POSITION,M3508_angle_PID,7000,2000); - PID_init(&speed_pid,PID_POSITION,M3508_speed_PID,500000,500000); - PID_init(&angle_pid,PID_POSITION,M3508_angle_PID,500000,100000); + // PID_init(&speed_pid,PID_POSITION,M3508_speed_PID,500000,500000); + // PID_init(&angle_pid,PID_POSITION,M3508_angle_PID,500000,100000); + + PID_init(&t_speed_pid,PID_POSITION,M2006_speed_PID,500000,500000); + PID_init(&t_angle_pid,PID_POSITION,M2006_angle_PID,500000,100000); } + +float trigger_angle = 0; +void trigger_pos(fp32 angle) +{ + + int16_t delta[1]; + + delta[0]=PID_calc(&t_angle_pid,trigger_motor_data->total_angle,angle); + t_result=PID_calc(&t_speed_pid,trigger_motor_data->speed_rpm,delta[0]); + +} + void motor_speed(fp32 speed) { @@ -53,3 +85,4 @@ void motor_pos(fp32 angle) result=PID_calc(&speed_pid,motor_3508_data->speed_rpm,delta[0]); } + diff --git a/User/module/dji.h b/User/module/dji.h index c722a0a..49d4b5a 100644 --- a/User/module/dji.h +++ b/User/module/dji.h @@ -14,30 +14,11 @@ typedef enum MOTOR_NUM }motorput_e; - // //电机输出 - // int16_t result[MOTOR_NUM]; //速度环 - // float angleSet[MOTOR_NUM]; //位置环 - // //电机状态 - - // motor_measure_t* putMotor[MOTOR_NUM]; - - // //翻转3508pid - // static const float M3508_speed_PID[3]; - // static const float M3508_angle_PID[3]; - - // //前后与夹球2006pid - // static const float M2006_speed_PID[3]; - // static const float M2006_angle_PID[3]; - // //电机速度pid结构体 - // pid_type_def speed_pid[MOTOR_NUM]; - // //位置环pid - // pid_type_def angle_pid[MOTOR_NUM]; - // //暂存目标位置 - // //0上下,1翻转,2前后,3夹球 - // float angleSet[MOTOR_NUM]; void motor_init(void); void motor_speed(fp32 speed); void motor_pos(fp32 angle); + void trigger_pos(fp32 angle); + #endif diff --git a/User/module/go.c b/User/module/go.c index 3bc2720..19d4a80 100644 --- a/User/module/go.c +++ b/User/module/go.c @@ -20,20 +20,17 @@ void gimbalInit(void) for(i = 0;i < GO_NUM;i ++) { go.goData[i] = getGoPoint(i);//获取电机数据指针 - // PID_init(&angle_pid[i],PID_POSITION,PID_angle,15,0.5);//pid初始化 - // PID_init(&speed_pid[i],PID_POSITION,PID_speed,60,0.2);//pid初始化 - -// result[i] = 0; + go.angleSetgo[i] = 0; go.offestAngle[i] = 0; // GO_M8010_send_data(&huart1, i,0,0,0,0,0,0); GO_M8010_send_data(&huart6, i,0,0,0,0,0,0); go.offestAngle[i] = go.goData[i]->Pos; - HAL_Delay(2000); + HAL_Delay(100); // GO_M8010_send_data(&huart1, i,0,0,0,0,0,0); GO_M8010_send_data(&huart6, i,0,0,0,0,0,0); go.offestAngle[i] = go.goData[i]->Pos; - HAL_Delay(2000); + HAL_Delay(100); } } diff --git a/User/module/shoot.c b/User/module/shoot.c new file mode 100644 index 0000000..02dc1ca --- /dev/null +++ b/User/module/shoot.c @@ -0,0 +1,77 @@ +#include "shoot.h" +#include "remote_control.h" + +extern RC_mess_t RC_mess; +extern motor_measure_t *trigger_motor_data;//3508电机数据 + + +#define GO1_SHOOT 1 +#define ODRIVE_SHOOT 0 + +#define KP 0.12 +#define KD 0.008 + + +#if GO1_SHOOT == 1 + GO_SHOOT goshoot; + +void shooterInit(void) +{ + int i; + GO_M8010_init(); + for(i = 0;i < GO_NUM;i ++) + { + goshoot.goData[i] = getGoPoint(i);//获取电机数据指针 + + goshoot.angleSetgo[i] = 0; + goshoot.offestAngle[i] = 0; + // GO_M8010_send_data(&huart1, i,0,0,0,0,0,0); + GO_M8010_send_data(&huart6, i,0,0,0,0,0,0); + goshoot.offestAngle[i] = goshoot.goData[i]->Pos; + HAL_Delay(100); + // GO_M8010_send_data(&huart1, i,0,0,0,0,0,0); + GO_M8010_send_data(&huart6, i,0,0,0,0,0,0); + goshoot.offestAngle[i] = goshoot.goData[i]->Pos; + HAL_Delay(100); + } + +} + + +void shoot_ball(int key) +{ + + + //蓄力 + if(trigger_motor_data->real_angle ==60)//扳机已闭合 + { + goshoot.angleSetgo[0] = 10; + GO_M8010_send_data(&huart6, 0,0,0,goshoot.angleSetgo[0],1,KP,KD); + } + if (key ==2)//上升准备蓄力 + { + goshoot.angleSetgo[0] = 0; + GO_M8010_send_data(&huart6, 0,0,0,goshoot.angleSetgo[0],1,KP,KD); + } + + +} + + +#elif ODRIVE_SHOOT == 1 + +void shoot_odrive(void) +{ + //扳机 + if(trigger_motor_data->real_angle == 60) + { + trigger_pos(0); + } + else + { + trigger_pos(60); + } +} + +#endif + diff --git a/User/module/shoot.h b/User/module/shoot.h new file mode 100644 index 0000000..497a4ca --- /dev/null +++ b/User/module/shoot.h @@ -0,0 +1,26 @@ +#ifndef _SHOOT_H_ +#define _SHOOT_H_ + +#include "GO_M8010_6_Driver.h" +#include "odrive_can.h" +#include "djiMotor.h" +#include "calc_lib.h" +#include "pid.h" + +typedef struct +{ + /* data */ + GO_Motorfield* goData[GO_NUM]; + //暂存目标位置 + //0 left,1 right + float angleSetgo[GO_NUM]; + float offestAngle[GO_NUM];//go数据 + float Kp; + float Kd; + float allowRange; +}GO_SHOOT; + +void shooterInit(void); +void shoot_ball(int key); + +#endif diff --git a/User/task/attrTask.c b/User/task/attrTask.c index 12b690f..01fbfe0 100644 --- a/User/task/attrTask.c +++ b/User/task/attrTask.c @@ -63,5 +63,10 @@ const osThreadAttr_t attr_rc = { .stack_size = 256 * 4, }; - +//ball +const osThreadAttr_t attr_ball = { + .name = "ball", + .priority = osPriorityRealtime, + .stack_size = 256 * 4, +}; diff --git a/User/task/attrTask.h b/User/task/attrTask.h index 3506765..e591ed1 100644 --- a/User/task/attrTask.h +++ b/User/task/attrTask.h @@ -20,7 +20,7 @@ #define TASK_FREQ_MONITOR (2u) #define TASK_FREQ_CAN (500u) #define TASK_FREQ_AI (250u) -#define TASK_FREQ_REFEREE (1000u) +#define TASK_FREQ_BALL (500u) #define TASK_INIT_DELAY_INFO (500u) #define TASK_INIT_DELAY_MONITOR (10) @@ -43,7 +43,8 @@ typedef struct { osThreadId_t dji_motor; osThreadId_t shoot; osThreadId_t go; - osThreadId_t nuc; + osThreadId_t nuc; + osThreadId_t ball; } thread; /* 电机的反馈和输出 */ @@ -159,6 +160,7 @@ extern const osThreadAttr_t attr_shoot; extern const osThreadAttr_t attr_go; extern const osThreadAttr_t attr_nuc; extern const osThreadAttr_t attr_rc; +extern const osThreadAttr_t attr_ball; /* Exported functions prototypes -------------------------------------------- */ //声明一下任务 @@ -178,4 +180,6 @@ void Task_nuc(void *argument); void Task_Rc(void *argument); +void Task_Ball(void *argument); + #endif diff --git a/User/task/ball_task.c b/User/task/ball_task.c new file mode 100644 index 0000000..e02ee5e --- /dev/null +++ b/User/task/ball_task.c @@ -0,0 +1,29 @@ +#include "ball_task.h" +#include "TopDefine.h" +#include "FreeRTOS.h" +#include "attrTask.h" +#include +#include "remote_control.h" +#include "ball.h" + +extern RC_mess_t RC_mess; + +BASKETBALL basketball; +void Task_Ball(void *argument) +{ + (void)argument; /* 未使用argument,消除警告 */ + const uint32_t delay_tick = osKernelGetTickFreq() / TASK_FREQ_CAN; + + uint32_t tick = osKernelGetTickCount(); /* 控制任务运行频率的计算 */ + basketball.hand=0; + basketball.paw=0; + while(1) + { + + handling_ball(basketball.hand, basketball.paw); + + tick += delay_tick; /* 计算下一个唤醒时刻 */ + osDelayUntil(tick); /* 运行结束,等待下一个周期唤醒 */ + } + +} diff --git a/User/task/ball_task.h b/User/task/ball_task.h new file mode 100644 index 0000000..a98c707 --- /dev/null +++ b/User/task/ball_task.h @@ -0,0 +1,5 @@ +#ifndef _BALL_TASK_H_ +#define _BALL_TASK_H_ + + +#endif diff --git a/User/task/can_task.c b/User/task/can_task.c index 17a14c5..9ea03e6 100644 --- a/User/task/can_task.c +++ b/User/task/can_task.c @@ -14,7 +14,7 @@ extern motor_measure_t *motor_3508_data; void Task_Can(void *argument) { (void)argument; /* 未使用argument,消除警告 */ - // const uint32_t delay_tick = osKernelGetTickFreq() / TASK_FREQ_CAN; + const uint32_t delay_tick = osKernelGetTickFreq() / TASK_FREQ_CAN; djiInit();//FIFO滤波器初始化 Odrive_Can_Init(); @@ -29,8 +29,8 @@ void Task_Can(void *argument) //将can数据添加到消息队列 - // tick += delay_tick; /* 计算下一个唤醒时刻 */ - // osDelayUntil(tick); /* 运行结束,等待下一个周期唤醒 */ + tick += delay_tick; /* 计算下一个唤醒时刻 */ + osDelayUntil(tick); /* 运行结束,等待下一个周期唤醒 */ } } diff --git a/User/task/dji_task.c b/User/task/dji_task.c index abe51f9..7540029 100644 --- a/User/task/dji_task.c +++ b/User/task/dji_task.c @@ -9,6 +9,7 @@ extern RC_mess_t RC_mess; extern int16_t result; +extern int16_t t_result; extern motor_measure_t *motor_3508_data; float vofa[8]; /** @@ -24,7 +25,7 @@ void Task_Motor(void *argument) { (void)argument; /* 未使用argument,消除警告 */ - // const uint32_t delay_tick = osKernelGetTickFreq() / TASK_FREQ_CTRL_CHASSIS; + const uint32_t delay_tick = osKernelGetTickFreq() / TASK_FREQ_CTRL_CHASSIS; motor_init(); @@ -37,18 +38,18 @@ void Task_Motor(void *argument) //电机控制 //motor_speed(speed); m=angle*(8191/360); - motor_pos(m); + // motor_pos(m); + trigger_pos(m); //CAN_cmd_200(result[MOTOR_UP],result[MOTOR_UP],result[MOTOR_UP],result[MOTOR_UP],&hcan1); - CAN_cmd_200(result,0,0,0,&hcan1); + CAN_cmd_200(t_result,0,0,0,&hcan1); osDelay(2); // vofa[0]=motor_3508_data->speed_rpm; // vofa[1]=speed; // vofa_tx_main(vofa); - // tick += delay_tick; - // osDelayUntil(tick); - + tick += delay_tick; + osDelayUntil(tick); } diff --git a/User/task/initTask.c b/User/task/initTask.c index 17c5958..a2ae415 100644 --- a/User/task/initTask.c +++ b/User/task/initTask.c @@ -48,7 +48,10 @@ task_runtime.thread.nuc = osThreadNew(Task_nuc, NULL, &attr_nuc); // rc task_runtime.thread.rc = - osThreadNew(Task_Rc, NULL, &attr_rc); + osThreadNew(Task_Rc, NULL, &attr_rc); +// ball +task_runtime.thread.ball = + osThreadNew(Task_Ball, NULL, &attr_ball); /* 消息队列 */ //can diff --git a/User/task/led_task.c b/User/task/led_task.c index 138b3b8..4cf90ba 100644 --- a/User/task/led_task.c +++ b/User/task/led_task.c @@ -3,6 +3,7 @@ #include "FreeRTOS.h" #include "main.h" #include "led.h" +#include "buzzer.h" void Task_Led(void *argument) { (void)argument; /* 未使用argument,消除警告 */ @@ -10,9 +11,10 @@ void Task_Led(void *argument) { for (;;) { // LED_red(); - LED_bule(); + // LED_bule(); + see_you_again(); // LED_green(); - osDelay(500); + // osDelay(500); } } diff --git a/User/task/nuc_task.c b/User/task/nuc_task.c index 0dcdf8f..aec9eff 100644 --- a/User/task/nuc_task.c +++ b/User/task/nuc_task.c @@ -15,11 +15,11 @@ void Task_nuc(void *argument) { (void)argument; /* 未使用argument,消除警告 */ - // const uint32_t delay_tick = osKernelGetTickFreq() / TASK_FREQ_AI; + const uint32_t delay_tick = osKernelGetTickFreq() / TASK_FREQ_AI; NUC_Init(&cmd_fromnuc); - uint32_t tick = osKernelGetTickCount(); + uint32_t tick = osKernelGetTickCount(); while(1) { @@ -42,8 +42,8 @@ void Task_nuc(void *argument) // osMessageQueuePut(task_runtime.msgq.cmd.raw.nuc,&(cmd_fromnuc),0,0); osDelay(2); - // tick += delay_tick; /* 计算下一个唤醒时刄1ķ*/ - // osDelayUntil(tick); + tick += delay_tick; /* 计算下一个唤醒时刄1ķ*/ + osDelayUntil(tick); } } diff --git a/User/task/shoot_task.c b/User/task/shoot_task.c index 9710ac1..4ad88fa 100644 --- a/User/task/shoot_task.c +++ b/User/task/shoot_task.c @@ -3,29 +3,37 @@ #include "FreeRTOS.h" #include "attrTask.h" #include -#include "shoot_task.h" -#include "odrive_shoot.h" #include "remote_control.h" +#include "shoot.h" extern RC_mess_t RC_mess; -const odrive_msg_t *odrive_msg1; + +#define GO1_SHOOT 1 +#define ODRIVE_SHOOT 0 + void Task_Shoot(void *argument) { (void)argument; /* 未使用argument,消除警告 */ - // const uint32_t delay_tick = osKernelGetTickFreq() / TASK_FREQ_CAN; - // odrive_CB(); - // uint32_t tick = osKernelGetTickCount(); /* 控制任务运行频率的计算 */ + const uint32_t delay_tick = osKernelGetTickFreq() / TASK_FREQ_CAN; + #if GO1_SHOOT == 1 + shooterInit(); + #endif + + uint32_t tick = osKernelGetTickCount(); /* 控制任务运行频率的计算 */ + while(1) { - shootStep(); + #if GO1_SHOOT == 1 + + shoot_ball(0); - odrive_get_encode(AXIS0_NODE); - - odrive_msg1 = Get_Odrive_Point(); - osDelay(2); + #elif ODRIVE_SHOOT == 1 + shootStep(); + #endif - - // tick += delay_tick; /* 计算下一个唤醒时刻 */ - // osDelayUntil(tick); /* 运行结束,等待下一个周期唤醒 */ + + tick += delay_tick; /* 计算下一个唤醒时刻 */ + osDelayUntil(tick); /* 运行结束,等待下一个周期唤醒 */ } + } diff --git a/mycode1.ioc b/mycode1.ioc index 8e02ea7..5a37442 100644 --- a/mycode1.ioc +++ b/mycode1.ioc @@ -67,8 +67,9 @@ Mcu.CPN=STM32F407IGH6 Mcu.Family=STM32F4 Mcu.IP0=CAN1 Mcu.IP1=CAN2 -Mcu.IP10=USART3 -Mcu.IP11=USART6 +Mcu.IP10=USART1 +Mcu.IP11=USART3 +Mcu.IP12=USART6 Mcu.IP2=DMA Mcu.IP3=FREERTOS Mcu.IP4=NVIC @@ -76,8 +77,8 @@ Mcu.IP5=RCC Mcu.IP6=SPI2 Mcu.IP7=SYS Mcu.IP8=TIM1 -Mcu.IP9=USART1 -Mcu.IPNb=12 +Mcu.IP9=TIM4 +Mcu.IPNb=13 Mcu.Name=STM32F407I(E-G)Hx Mcu.Package=UFBGA176 Mcu.Pin0=PB5 @@ -93,21 +94,26 @@ Mcu.Pin17=PH12 Mcu.Pin18=PH11 Mcu.Pin19=PH10 Mcu.Pin2=PA14 -Mcu.Pin20=PE9 -Mcu.Pin21=PB12 -Mcu.Pin22=PB13 -Mcu.Pin23=PB14 -Mcu.Pin24=PB15 -Mcu.Pin25=VP_FREERTOS_VS_CMSIS_V2 -Mcu.Pin26=VP_SYS_VS_Systick +Mcu.Pin20=PD14 +Mcu.Pin21=PE13 +Mcu.Pin22=PE9 +Mcu.Pin23=PE11 +Mcu.Pin24=PE14 +Mcu.Pin25=PB12 +Mcu.Pin26=PB13 +Mcu.Pin27=PB14 +Mcu.Pin28=PB15 +Mcu.Pin29=VP_FREERTOS_VS_CMSIS_V2 Mcu.Pin3=PA13 +Mcu.Pin30=VP_SYS_VS_Systick +Mcu.Pin31=VP_TIM4_VS_ClockSourceINT Mcu.Pin4=PB7 Mcu.Pin5=PB6 Mcu.Pin6=PD0 Mcu.Pin7=PC11 Mcu.Pin8=PC10 Mcu.Pin9=PI7 -Mcu.PinsNb=27 +Mcu.PinsNb=32 Mcu.ThirdPartyNb=0 Mcu.UserConstants= Mcu.UserName=STM32F407IGHx @@ -174,6 +180,22 @@ PD0.Signal=CAN1_RX PD1.Locked=true PD1.Mode=CAN_Activate PD1.Signal=CAN1_TX +PD14.GPIOParameters=GPIO_Label +PD14.GPIO_Label=buzzer +PD14.Locked=true +PD14.Signal=S_TIM4_CH3 +PE11.GPIOParameters=GPIO_Label +PE11.GPIO_Label=key +PE11.Locked=true +PE11.Signal=GPIO_Output +PE13.GPIOParameters=GPIO_Label +PE13.GPIO_Label=down +PE13.Locked=true +PE13.Signal=GPIO_Output +PE14.GPIOParameters=GPIO_Label +PE14.GPIO_Label=paw +PE14.Locked=true +PE14.Signal=GPIO_Output PE9.Locked=true PE9.Signal=S_TIM1_CH1 PG14.Mode=Asynchronous @@ -272,6 +294,8 @@ RCC.VCOOutputFreq_Value=336000000 RCC.VcooutputI2S=192000000 SH.S_TIM1_CH1.0=TIM1_CH1,PWM Generation1 CH1 SH.S_TIM1_CH1.ConfNb=1 +SH.S_TIM4_CH3.0=TIM4_CH3,PWM Generation3 CH3 +SH.S_TIM4_CH3.ConfNb=1 SPI2.BaudRatePrescaler=SPI_BAUDRATEPRESCALER_32 SPI2.CLKPhase=SPI_PHASE_2EDGE SPI2.CalculateBaudRate=1.3125 MBits/s @@ -285,6 +309,9 @@ TIM1.IPParameters=Channel-PWM Generation1 CH1,Prescaler,Period,Pulse-PWM Generat TIM1.Period=20000-1 TIM1.Prescaler=168-1 TIM1.Pulse-PWM\ Generation1\ CH1=2000 +TIM4.Channel-PWM\ Generation3\ CH3=TIM_CHANNEL_3 +TIM4.IPParameters=Channel-PWM Generation3 CH3,Period +TIM4.Period=20999 USART1.BaudRate=115200 USART1.IPParameters=VirtualMode,BaudRate USART1.VirtualMode=VM_ASYNC @@ -299,5 +326,7 @@ VP_FREERTOS_VS_CMSIS_V2.Mode=CMSIS_V2 VP_FREERTOS_VS_CMSIS_V2.Signal=FREERTOS_VS_CMSIS_V2 VP_SYS_VS_Systick.Mode=SysTick VP_SYS_VS_Systick.Signal=SYS_VS_Systick +VP_TIM4_VS_ClockSourceINT.Mode=Internal +VP_TIM4_VS_ClockSourceINT.Signal=TIM4_VS_ClockSourceINT board=custom rtos.0.ip=FREERTOS