This commit is contained in:
2025-07-08 23:30:16 +08:00
parent a635b6d5eb
commit a9884051f8
21 changed files with 7673 additions and 7958 deletions

View File

@@ -36,7 +36,7 @@
// BLE define
#define BLE_RX_THREAD_STACK_SIZE 2048
#define BLE_RX_THREAD_PRIORITY 10
#define BLE_RX_THREAD_PRIORITY 9
#define BLE_TX_THREAD_STACK_SIZE 2048
#define BLE_TX_THREAD_PRIORITY 10
// IMU thread config
@@ -212,19 +212,25 @@ UINT App_ThreadX_Init(VOID *memory_ptr)
7, 7, // 这里的优先级
TX_NO_TIME_SLICE,
TX_AUTO_START);
if(status != TX_SUCCESS)
{
return status;
}
//
// HCBle_SendData("✅ BLE RX/TX 线程和队列初始化完成\r\n");
status = ControlThreadCreate();
if(status != TX_SUCCESS)
{
return status;
}
status = Encoder_ThreadCreate();
if(status != TX_SUCCESS)
{
return status;
}
// status = ControlThreadCreate();
// if(status != TX_SUCCESS)
// {
// return status;
// }
// status = Encoder_ThreadCreate();
// if(status != TX_SUCCESS)
// {
// return status;
// }
return TX_SUCCESS;
}

View File

@@ -106,6 +106,9 @@ int main(void)
imu600_init();
GPS_Init();
DWT_Init();
PWM_GPIO_TIM_Init();
HAL_TIM_IC_Start_IT(&htim5,TIM_CHANNEL_1);
// Buzzer_Open();
// HCBle_InitDMAReception();
// HAL_Delay(200);
// GPS_Init();

File diff suppressed because one or more lines are too long

View File

@@ -152,18 +152,18 @@
<Bp>
<Number>0</Number>
<Type>0</Type>
<LineNumber>124</LineNumber>
<LineNumber>110</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>134223930</Address>
<Address>134265834</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>1</BreakIfRCount>
<Filename>../Core/Src/app_threadx.c</Filename>
<Filename>..\fun\Ultrasound.c</Filename>
<ExecCommand></ExecCommand>
<Expression>\\AutoGuideStick\../Core/Src/app_threadx.c\124</Expression>
<Expression>\\AutoGuideStick\../fun/Ultrasound.c\110</Expression>
</Bp>
</Breakpoint>
<WatchWindow1>
@@ -289,6 +289,11 @@
<WinNumber>2</WinNumber>
<ItemText>status</ItemText>
</Ww>
<Ww>
<count>8</count>
<WinNumber>2</WinNumber>
<ItemText>distance_cm</ItemText>
</Ww>
</WatchWindow2>
<Tracepoint>
<THDelay>0</THDelay>

View File

@@ -26,232 +26,8 @@ Project File Date: 07/02/2025
<h2>Output:</h2>
*** Using Compiler 'V6.21', folder: 'D:\keil5\ARM\ARMCLANG\Bin'
Rebuild target 'AutoGuideStick'
compiling main.c...
compiling stm32h5xx_hal_msp.c...
compiling stm32h5xx_hal_timebase_tim.c...
compiling tim.c...
compiling gpdma.c...
compiling stm32h5xx_it.c...
compiling stm32h5xx_hal_tim.c...
assembling startup_stm32h563xx.s...
compiling app_azure_rtos.c...
compiling memorymap.c...
compiling app_threadx.c...
compiling gpio.c...
compiling usart.c...
compiling stm32h5xx_hal_cortex.c...
compiling stm32h5xx_hal_tim_ex.c...
assembling tx_initialize_low_level.S...
compiling stm32h5xx_hal_rcc.c...
compiling stm32h5xx_hal_flash.c...
compiling stm32h5xx_hal_flash_ex.c...
compiling stm32h5xx_hal_rcc_ex.c...
compiling stm32h5xx_hal_gpio.c...
compiling stm32h5xx_hal_dma.c...
compiling stm32h5xx_hal_pwr.c...
compiling stm32h5xx_hal_dma_ex.c...
compiling stm32h5xx_hal_pwr_ex.c...
compiling stm32h5xx_hal.c...
compiling stm32h5xx_hal_exti.c...
compiling stm32h5xx_hal_uart_ex.c...
compiling stm32h5xx_hal_uart.c...
compiling system_stm32h5xx.c...
compiling tx_initialize_high_level.c...
compiling tx_initialize_kernel_enter.c...
compiling tx_initialize_kernel_setup.c...
compiling tx_thread_stack_error_handler.c...
compiling tx_thread_stack_error_notify.c...
compiling tx_thread_system_resume.c...
compiling tx_block_allocate.c...
assembling tx_thread_context_restore.S...
compiling tx_block_pool_cleanup.c...
assembling tx_thread_context_save.S...
assembling tx_thread_interrupt_control.S...
assembling tx_thread_interrupt_disable.S...
assembling tx_thread_interrupt_restore.S...
assembling tx_thread_schedule.S...
assembling tx_thread_stack_build.S...
assembling tx_thread_system_return.S...
assembling tx_timer_interrupt.S...
compiling tx_block_pool_create.c...
compiling tx_block_pool_delete.c...
compiling tx_block_pool_info_get.c...
compiling tx_block_pool_initialize.c...
compiling tx_block_pool_prioritize.c...
compiling tx_block_release.c...
compiling tx_byte_allocate.c...
compiling tx_byte_pool_cleanup.c...
compiling tx_byte_pool_create.c...
compiling tx_byte_pool_delete.c...
compiling tx_byte_pool_info_get.c...
compiling tx_byte_pool_initialize.c...
compiling tx_byte_pool_prioritize.c...
compiling tx_byte_pool_search.c...
compiling tx_byte_release.c...
compiling tx_event_flags_cleanup.c...
compiling tx_event_flags_create.c...
compiling tx_event_flags_delete.c...
compiling tx_event_flags_get.c...
compiling tx_event_flags_info_get.c...
compiling tx_event_flags_initialize.c...
compiling tx_event_flags_set.c...
compiling tx_event_flags_set_notify.c...
compiling tx_mutex_cleanup.c...
compiling tx_mutex_create.c...
compiling tx_mutex_delete.c...
compiling tx_mutex_get.c...
compiling tx_mutex_info_get.c...
compiling tx_mutex_initialize.c...
compiling tx_mutex_prioritize.c...
compiling tx_mutex_priority_change.c...
compiling tx_mutex_put.c...
compiling tx_queue_cleanup.c...
compiling tx_queue_create.c...
compiling tx_queue_delete.c...
compiling tx_queue_flush.c...
compiling tx_queue_front_send.c...
compiling tx_queue_info_get.c...
compiling tx_queue_initialize.c...
compiling tx_queue_prioritize.c...
compiling tx_queue_receive.c...
compiling tx_queue_send.c...
compiling tx_queue_send_notify.c...
compiling tx_semaphore_ceiling_put.c...
compiling tx_semaphore_cleanup.c...
compiling tx_semaphore_create.c...
compiling tx_semaphore_delete.c...
compiling tx_semaphore_get.c...
compiling tx_semaphore_info_get.c...
compiling tx_semaphore_initialize.c...
compiling tx_semaphore_prioritize.c...
compiling tx_semaphore_put.c...
compiling tx_semaphore_put_notify.c...
compiling tx_thread_create.c...
compiling tx_thread_delete.c...
compiling tx_thread_entry_exit_notify.c...
compiling tx_thread_identify.c...
compiling tx_thread_info_get.c...
compiling tx_thread_initialize.c...
compiling tx_thread_preemption_change.c...
compiling tx_thread_priority_change.c...
compiling tx_thread_relinquish.c...
compiling tx_thread_reset.c...
compiling tx_thread_resume.c...
compiling tx_thread_shell_entry.c...
compiling tx_thread_sleep.c...
compiling tx_thread_stack_analyze.c...
compiling tx_thread_suspend.c...
compiling tx_thread_system_preempt_check.c...
compiling tx_thread_system_suspend.c...
compiling tx_thread_terminate.c...
compiling tx_thread_time_slice.c...
compiling tx_thread_time_slice_change.c...
compiling tx_thread_timeout.c...
compiling tx_thread_wait_abort.c...
compiling tx_time_get.c...
compiling tx_time_set.c...
compiling txe_block_allocate.c...
compiling txe_block_pool_create.c...
compiling txe_block_pool_delete.c...
compiling txe_block_pool_info_get.c...
compiling txe_block_pool_prioritize.c...
compiling txe_block_release.c...
compiling txe_byte_allocate.c...
compiling txe_byte_pool_create.c...
compiling txe_byte_pool_delete.c...
compiling txe_byte_pool_info_get.c...
compiling txe_byte_pool_prioritize.c...
compiling txe_byte_release.c...
compiling txe_event_flags_create.c...
compiling txe_event_flags_delete.c...
compiling txe_event_flags_get.c...
compiling txe_event_flags_info_get.c...
compiling txe_event_flags_set.c...
compiling txe_event_flags_set_notify.c...
compiling txe_mutex_create.c...
compiling txe_mutex_delete.c...
compiling txe_mutex_get.c...
compiling txe_mutex_info_get.c...
compiling txe_mutex_prioritize.c...
compiling txe_mutex_put.c...
compiling txe_queue_create.c...
compiling txe_queue_delete.c...
compiling txe_queue_flush.c...
compiling txe_queue_front_send.c...
compiling txe_queue_info_get.c...
compiling txe_queue_prioritize.c...
compiling txe_queue_receive.c...
compiling txe_queue_send.c...
compiling txe_queue_send_notify.c...
compiling txe_semaphore_ceiling_put.c...
compiling txe_semaphore_create.c...
compiling txe_semaphore_delete.c...
compiling txe_semaphore_get.c...
compiling txe_semaphore_info_get.c...
compiling txe_semaphore_prioritize.c...
compiling txe_semaphore_put.c...
compiling txe_semaphore_put_notify.c...
compiling txe_thread_create.c...
compiling txe_thread_delete.c...
compiling txe_thread_entry_exit_notify.c...
compiling txe_thread_info_get.c...
compiling txe_thread_preemption_change.c...
compiling txe_thread_priority_change.c...
compiling txe_thread_relinquish.c...
compiling txe_thread_reset.c...
compiling txe_thread_resume.c...
compiling txe_thread_suspend.c...
compiling txe_thread_terminate.c...
compiling txe_thread_time_slice_change.c...
compiling txe_thread_wait_abort.c...
compiling tx_timer_activate.c...
compiling tx_timer_change.c...
compiling tx_timer_create.c...
compiling tx_timer_deactivate.c...
compiling tx_timer_delete.c...
compiling tx_timer_expiration_process.c...
compiling tx_timer_info_get.c...
compiling tx_timer_initialize.c...
compiling tx_timer_system_activate.c...
compiling tx_timer_system_deactivate.c...
compiling tx_timer_thread_entry.c...
compiling txe_timer_activate.c...
compiling txe_timer_change.c...
compiling txe_timer_create.c...
compiling txe_timer_deactivate.c...
compiling txe_timer_delete.c...
compiling txe_timer_info_get.c...
../fun/HCBle.c(144): warning: illegal character encoding in string literal [-Winvalid-source-encoding]
144 | HCBle_SendData("? <BD><E2><CE><F6>ʧ<B0><DC>: %s\r\n", frame);
| ^~~~~~~~~~~~~~~~ ~~~~~~~~
1 warning generated.
compiling HCBle.c...
compiling gps.c...
compiling Buzzer.c...
compiling Shake_Motor.c...
compiling Ultrasound.c...
compiling Motor.c...
compiling encoder.c...
compiling imu948.c...
../fun/IMU.c(1236): warning: passing 'char[6]' to parameter of type 'U8 *' (aka 'unsigned char *') converts between pointers to integer types where one is of the unique plain 'char' type and the other is not [-Wpointer-sign]
1236 | Cmd_22("im948");
| ^~~~~~~
../fun/IMU.c(386): note: passing argument to parameter 'bleName' here
386 | void Cmd_22(U8 *bleName)
| ^
../fun/IMU.c(1239): warning: passing 'char[9]' to parameter of type 'U8 *' (aka 'unsigned char *') converts between pointers to integer types where one is of the unique plain 'char' type and the other is not [-Wpointer-sign]
1239 | Cmd_22("helloBle");
| ^~~~~~~~~~
../fun/IMU.c(386): note: passing argument to parameter 'bleName' here
386 | void Cmd_22(U8 *bleName)
| ^
2 warnings generated.
compiling IMU.c...
linking...
Program Size: Code=87692 RO-data=1352 RW-data=20 ZI-data=18156
FromELF: creating hex file...
"AutoGuideStick\AutoGuideStick.axf" - 0 Error(s), 3 Warning(s).
Build target 'AutoGuideStick'
"AutoGuideStick\AutoGuideStick.axf" - 0 Error(s), 0 Warning(s).
<h2>Software Packages used:</h2>
@@ -275,7 +51,7 @@ Package Vendor: Keil
* Component: ARM::CMSIS:CORE@5.6.0
Include file: CMSIS/Core/Include/tz_context.h
Build Time Elapsed: 00:00:25
Build Time Elapsed: 00:00:02
</pre>
</body>
</html>

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,7 +1,7 @@
Dependencies for Project 'AutoGuideStick', Target 'AutoGuideStick': (DO NOT MODIFY !)
CompilerVersion: 6210000::V6.21::ARMCLANG
F (startup_stm32h563xx.s)(0x68654635)(--target=arm-arm-none-eabi -mcpu=cortex-m33 -mfpu=fpv5-sp-d16 -mfloat-abi=hard -masm=auto -Wa,armasm,--diag_suppress=A1950W -c
-gdwarf-4 -Wa,armasm,--pd,"__MICROLIB SETA 1" -I ../Core/Inc -I ../AZURE_RTOS/App -I ../Drivers/STM32H5xx_HAL_Driver/Inc -I ../Drivers/STM32H5xx_HAL_Driver/Inc/Legacy -I ../Middlewares/ST/threadx/common/inc -I ../Drivers/CMSIS/Device/ST/STM32H5xx/Include -I ../Middlewares/ST/threadx/ports/cortex_m33/ac6/inc -I ../Drivers/CMSIS/Include
-I./RTE/_AutoGuideStick
@@ -142,7 +142,7 @@ I (..\Drivers\STM32H5xx_HAL_Driver\Inc\stm32h5xx_hal_tim_ex.h)(0x683FA4DD)
-ID:/keil5/ARM/PACK/Keil/STM32H5xx_DFP/1.3.0/Drivers/CMSIS/Device/ST/STM32H5xx/Include
-D__UVISION_VERSION="539" -D_RTE_ -DSTM32H563xx -D_RTE_ -DTX_INCLUDE_USER_DEFINE_FILE -DTX_SINGLE_MODE_NON_SECURE="1" -DUSE_HAL_DRIVER -DSTM32H563xx
-o autoguidestick/gpdma.o -MD)
I (..\Core\Inc\main.hc.\Drivers\STM32H5xx_HAL_Driver\Inc\stm32h5xx_hal.h)(0x00000000)
I (..\Core\Inc\stm32h5xx_hal_conf.h)(0x685C2A98)
@@ -2077,7 +2077,7 @@ I (..\Middlewares\ST\threadx\ports\cortex_m33\ac6\inc\tx_port.h)(0x683FA4D9)
-o autoguidestick/tx_event_flags_info_get.o -MD)
I (..\Middlewares\ST\threadx\common\inc\tx_api.h)(0x683FA4DA)
I (..\Middlewares\ST\threadx\ports\cortex_m33\ac6\inc\tx_port.h)(0x683FA4D9)
I (..\Middlewares\ST\threadx\ports\cortex_m33\ac6\inc\tx_port.h)(0x683FA4D9)
I (..\Core\Inc\tx_user.he:\keil5\ARM\ARMCLANG\include\stdlib.h)(0x00000000)
I (D:\keil5\ARM\ARMCLANG\include\string.h)(0x6569B012)
I (..\Middlewares\ST\threadx\common\inc\tx_trace.h)(0x683FA4DA)
@@ -2254,7 +2254,7 @@ I (D:\keil5\ARM\ARMCLANG\include\stdarg.h)(0x6569B012)
I (..\Middlewares\ST\threadx\common\inc\tx_trace.h)(0x683FA4DA)
I (..\Middlewares\ST\threadx\common\inc\tx_mutex.h)(0x683FA4DA)
F (../Middlewares/ST/threadx/common/src/tx_mutex_initialize.c)(0x683FA4DA)(-xc -std=c11 --target=arm-arm-none-eabi -mcpu=cortex-m33 -mfpu=fpv5-sp-d16 -mfloat-abi=hard -c
-fno-rtti -funsigned-char -fshort-enums -fshort-wchar
-D__MICROLIB -gdwarf-4 -O0 -ffunction-sections -Wno-packed -Wno-missing-variable-declarations -Wno-missing-prototypes -Wno-missing-noreturn -Wno-sign-conversion -Wno-nonportable-include-path -Wno-reserved-id-macro -Wno-unused-macros -Wno-documentation-unknown-command -Wno-documentation -Wno-license-management -Wno-parentheses-equality -Wno-reserved-identifier -I ../Core/Inc -I ../AZURE_RTOS/App -I ../Drivers/STM32H5xx_HAL_Driver/Inc -I ../Drivers/STM32H5xx_HAL_Driver/Inc/Legacy -I ../Middlewares/ST/threadx/common/inc -I ../Drivers/CMSIS/Device/ST/STM32H5xx/Include -I ../Middlewares/ST/threadx/ports/cortex_m33/ac6/inc -I ../Drivers/CMSIS/Include -I ../fun
@@ -2297,7 +2297,7 @@ I (D:\keil5\ARM\ARMCLANG\include\stdio.h)(0x6569B012)
I (..\Middlewares\ST\threadx\common\inc\tx_mutex.h)(0x683FA4DA)
F (../Middlewares/ST/threadx/common/src/tx_mutex_priority_change.c)(0x683FA4DA)(-xc -std=c11 --target=arm-arm-none-eabi -mcpu=cortex-m33 -mfpu=fpv5-sp-d16 -mfloat-abi=hard -c
-fno-rtti -funsigned-char -fshort-enums -fshort-wchar
-fno-rtti -funsigned-char -fshort-enums -fshort-wchar
-D__MICROLIB -gdwarf-4 -O0 -ffunction-sections -Wno-packed -Wno-missing-variable-declarations -Wno-missing-prototypes -Wno-missing-noreturn -Wno-sign-conversion -Wno-nonportable-include-path -Wno-reserved-id-macro -Wno-unused-macros -Wno-documentation-unknown-command -Wno-documentation -Wno-license-management -Wno-parentheses-equality -Wno-reserved-identifier -I ../Core/Inc -I ../AZURE_RTOS/App -I ../Drivers/STM32H5xx_HAL_Driver/Inc -I ../Drivers/STM32H5xx_HAL_Driver/Inc/Legacy -I ../Middlewares/ST/threadx/common/inc -I ../Drivers/CMSIS/Device/ST/STM32H5xx/Include -I ../Middlewares/ST/threadx/ports/cortex_m33/ac6/inc -I ../Drivers/CMSIS/Include -I ../fun
@@ -2341,7 +2341,7 @@ I (D:\keil5\ARM\ARMCLANG\include\stdarg.h)(0x6569B012)
F (../Middlewares/ST/threadx/common/src/tx_queue_cleanup.c)(0x683FA4DA)(-xc -std=c11 --target=arm-arm-none-eabi -mcpu=cortex-m33 -mfpu=fpv5-sp-d16 -mfloat-abi=hard -c
-fno-rtti -funsigned-char -fshort-enums -fshort-wchar
-D__MICROLIB -gdwarf-4 -O0 -ffunction-sections -Wno-packed -Wno-missing-variable-declarations -Wno-missing-prototypes -Wno-missing-noreturn -Wno-sign-conversion -Wno-nonportable-include-path -Wno-reserved-id-macro -Wno-unused-macros -Wno-documentation-unknown-command -Wno-documentation -Wno-license-management -Wno-parentheses-equality -Wno-reserved-identifier -I ../Core/Inc -I ../AZURE_RTOS/App -I ../Drivers/STM32H5xx_HAL_Driver/Inc -I ../Drivers/STM32H5xx_HAL_Driver/Inc/Legacy -I ../Middlewares/ST/threadx/common/inc -I ../Drivers/CMSIS/Device/ST/STM32H5xx/Include -I ../Middlewares/ST/threadx/ports/cortex_m33/ac6/inc -I ../Drivers/CMSIS/Include -I ../fun
-I./RTE/_AutoGuideStick
@@ -2429,7 +2429,7 @@ I (..\fun\Shake_Motor.hG.\fun\Ultrasound.h..\fun\Buzzer.h)(0x00000000)
-fno-rtti -funsigned-char -fshort-enums -fshort-wchar
-D__MICROLIB -gdwarf-4 -O0 -ffunction-sections -Wno-packed -Wno-missing-variable-declarations -Wno-missing-prototypes -Wno-missing-noreturn -Wno-sign-conversion -Wno-nonportable-include-path -Wno-reserved-id-macro -Wno-unused-macros -Wno-documentation-unknown-command -Wno-documentation -Wno-license-management -Wno-parentheses-equality -Wno-reserved-identifier -I ../Core/Inc -I ../AZURE_RTOS/App -I ../Drivers/STM32H5xx_HAL_Driver/Inc -I ../Drivers/STM32H5xx_HAL_Driver/Inc/Legacy -I ../Middlewares/ST/threadx/common/inc -I ../Drivers/CMSIS/Device/ST/STM32H5xx/Include -I ../Middlewares/ST/threadx/ports/cortex_m33/ac6/inc -I ../Drivers/CMSIS/Include -I ../fun
-I./RTE/_AutoGuideStick
-ID:/keil5/ARM/PACK/ARM/CMSIS/5.9.0/CMSIS/Core/Include

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -136,6 +136,7 @@ void HCBle_ParseAndHandleFrame(const char *frame)
HCBle_SendData("left=%d, right=%d\r\n", cmd.LeftSpeed, cmd.RightSpeed);
// HCBle_SendData("left=%d, right=%d\r\n", left, right);
DriveBOTH(cmd.LeftSpeed,cmd.RightSpeed); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// DriveBOTH(cmd.LeftSpeed,cmd.RightSpeed);
return;
}

View File

@@ -64,23 +64,68 @@ void MotorB_Speed(uint8_t speed)
// ʾ<><CABE> ͬʱ<CDAC><CAB1><EFBFBD>Ƶ<EFBFBD><C6B5><EFBFBD>A/B
// <20><>ʾ <20><><EFBFBD><EFBFBD> Dir 0 ---- ǰ<><C7B0> go forward
// <20><><EFBFBD><EFBFBD> Dir 1 ---- <20><><EFBFBD><EFBFBD> go forward
void DriveBOTH(int16_t speedA,int16_t speedB)
//void DriveBOTH(int16_t speedA,int16_t speedB)
//{
// // <20><><EFBFBD><EFBFBD> A
// if (speedA >= 0) MotorA_Dir(0);
// else
// {
// MotorA_Dir(1);
// speedA = -speedA;
// }
// MotorA_Speed(speedA);
//
// // <20><><EFBFBD><EFBFBD> B
// if (speedB >= 0) MotorB_Dir(0);
// else
// {
// MotorB_Dir(1);
// speedB = -speedB;
// }
// MotorB_Speed(speedB);
//}
// Motor.c <20><><EFBFBD>Ͻ<EFBFBD><CFBD>д<EFBFBD><D0B4><EFBFBD>
void DriveBOTH(int16_t speedA, int16_t speedB)
{
// <20><><EFBFBD><EFBFBD> A
if (speedA >= 0) MotorA_Dir(0);
else
{
MotorA_Dir(1);
speedA = -speedA;
}
MotorA_Speed(speedA);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>A
if(speedA == 0) {
// <20>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD>͵<EFBFBD>ƽ
HAL_GPIO_WritePin(AIN1_GPIO_Port, AIN1_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(AIN2_GPIO_Port, AIN2_Pin, GPIO_PIN_RESET);
}
else if(speedA > 0) {
HAL_GPIO_WritePin(AIN1_GPIO_Port, AIN1_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(AIN2_GPIO_Port, AIN2_Pin, GPIO_PIN_RESET);
speedA = abs(speedA); // ȡ<><C8A1><EFBFBD><EFBFBD>ֵ
}
else {
HAL_GPIO_WritePin(AIN1_GPIO_Port, AIN1_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(AIN2_GPIO_Port, AIN2_Pin, GPIO_PIN_SET);
speedA = abs(speedA); // ȡ<><C8A1><EFBFBD><EFBFBD>ֵ
}
// <20><><EFBFBD><EFBFBD> B
if (speedB >= 0) MotorA_Dir(0);
else
{
MotorB_Dir(1);
speedB = -speedB;
}
MotorB_Speed(speedB);
}
if(speedB == 0) {
// <20>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD>͵<EFBFBD>ƽ
HAL_GPIO_WritePin(BIN1_GPIO_Port, BIN1_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(BIN2_GPIO_Port, BIN2_Pin, GPIO_PIN_RESET);
}
else if(speedB > 0) {
HAL_GPIO_WritePin(BIN1_GPIO_Port, BIN1_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(BIN2_GPIO_Port, BIN2_Pin, GPIO_PIN_RESET);
speedB = abs(speedB); // ȡ<><C8A1><EFBFBD><EFBFBD>ֵ
}
else {
HAL_GPIO_WritePin(BIN1_GPIO_Port, BIN1_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(BIN2_GPIO_Port, BIN2_Pin, GPIO_PIN_SET);
speedB = abs(speedB); // ȡ<><C8A1><EFBFBD><EFBFBD>ֵ
}
// ͬ<><CDAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>B...
// <20><><EFBFBD><EFBFBD>PWM
__HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_4, speedA);
__HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_4, speedB);
}

View File

@@ -123,6 +123,7 @@ void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim) {
// ֪ͨ<CDA8><D6AA><EFBFBD><EFBFBD> ȡ<><C8A1>ע<EFBFBD><D7A2><EFBFBD>Ի<EFBFBD><D4BB>Ѳ<EFBFBD><D1B2><EFBFBD><EFBFBD>߳<EFBFBD>
tx_event_flags_set(&ultrasonic_event, EVENT_ECHO_DONE, TX_OR);
}
HAL_TIM_IC_Start_IT(&htim5,TIM_CHANNEL_1);
}
}

View File

@@ -7,6 +7,7 @@
#define EVENT_ECHO_DONE 0x01
extern volatile uint8_t obstacle_level;
extern volatile uint32_t distance_cm;
void DWT_Init(void);
/********
delay_us() <20><><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5> (ʹ<><CAB9>DWT) <20><>ȷ<EFBFBD><C8B7>

View File

@@ -85,8 +85,8 @@ UINT ControlThreadCreate(void)
static void control_thread_entry(ULONG arg)
{
int16_t pwmL = 0, pwmR = 0;
float integralL = 0, integralR = 0;
static int16_t pwmL = 0, pwmR = 0;
static float integralL = 0, integralR = 0;
float Kp = 1.0f, Ki = 0.1f;
while (1)
@@ -96,7 +96,19 @@ static void control_thread_entry(ULONG arg)
integralL += errorL;
integralR += errorR;
// <20>ڻ<EFBFBD><DABB><EFBFBD><EFBFBD>ۼӺ<DBBC><D3BA><EFBFBD><EFBFBD>ӿ<EFBFBD><D3BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߼<EFBFBD>
if (errorL == 0) integralL = 0;
if (errorR == 0) integralR = 0;
const float max_integral = 1000.0f;
if(integralL > max_integral) integralL = max_integral;
if(integralL < -max_integral) integralL = -max_integral;
if(integralR > max_integral) integralR = max_integral;
if(integralR < -max_integral) integralR = -max_integral;
// ͬ<><CDAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>integralR...
pwmL += (int16_t)(Kp * errorL + Ki * integralL);
pwmR += (int16_t)(Kp * errorR + Ki * integralR);
@@ -111,9 +123,13 @@ static void control_thread_entry(ULONG arg)
}
}
int16_t map_speed_to_rpm(int speed)
{
if (speed < 60) return 0;
if (abs(speed) < 30) return 0;
return (speed - 60) * 1.5; // <20><><EFBFBD><EFBFBD>
}