Compare commits

..

1 Commits

Author SHA1 Message Date
ws
8ea27c8620 一次运球完自动放球 2025-07-04 16:04:06 +08:00
22 changed files with 452 additions and 495 deletions

View File

@ -3,26 +3,26 @@
{ {
"name": "R1", "name": "R1",
"includePath": [ "includePath": [
"d:\\Desktop\\R1_up\\Core\\Inc", "d:\\Desktop\\r1\\R1_up\\Core\\Inc",
"d:\\Desktop\\R1_up\\Drivers\\STM32F4xx_HAL_Driver\\Inc", "d:\\Desktop\\r1\\R1_up\\Drivers\\STM32F4xx_HAL_Driver\\Inc",
"d:\\Desktop\\R1_up\\Drivers\\STM32F4xx_HAL_Driver\\Inc\\Legacy", "d:\\Desktop\\r1\\R1_up\\Drivers\\STM32F4xx_HAL_Driver\\Inc\\Legacy",
"d:\\Desktop\\R1_up\\Middlewares\\Third_Party\\FreeRTOS\\Source\\include", "d:\\Desktop\\r1\\R1_up\\Middlewares\\Third_Party\\FreeRTOS\\Source\\include",
"d:\\Desktop\\R1_up\\Middlewares\\Third_Party\\FreeRTOS\\Source\\CMSIS_RTOS_V2", "d:\\Desktop\\r1\\R1_up\\Middlewares\\Third_Party\\FreeRTOS\\Source\\CMSIS_RTOS_V2",
"d:\\Desktop\\R1_up\\Middlewares\\Third_Party\\FreeRTOS\\Source\\portable\\RVDS\\ARM_CM4F", "d:\\Desktop\\r1\\R1_up\\Middlewares\\Third_Party\\FreeRTOS\\Source\\portable\\RVDS\\ARM_CM4F",
"d:\\Desktop\\R1_up\\Drivers\\CMSIS\\Device\\ST\\STM32F4xx\\Include", "d:\\Desktop\\r1\\R1_up\\Drivers\\CMSIS\\Device\\ST\\STM32F4xx\\Include",
"d:\\Desktop\\R1_up\\Drivers\\CMSIS\\Include", "d:\\Desktop\\r1\\R1_up\\Drivers\\CMSIS\\Include",
"d:\\Desktop\\R1_up\\User\\bsp", "d:\\Desktop\\r1\\R1_up\\User\\bsp",
"d:\\Desktop\\R1_up\\User\\module", "d:\\Desktop\\r1\\R1_up\\User\\module",
"d:\\Desktop\\R1_up\\User\\task", "d:\\Desktop\\r1\\R1_up\\User\\task",
"d:\\Desktop\\R1_up\\User\\lib", "d:\\Desktop\\r1\\R1_up\\User\\lib",
"d:\\Desktop\\R1_up\\User\\device", "d:\\Desktop\\r1\\R1_up\\User\\device",
"D:\\Develop\\keil\\ARM\\ARMCC\\include", "D:\\keil\\ARM\\ARMCC\\include",
"D:\\Develop\\keil\\ARM\\ARMCC\\include\\rw", "D:\\keil\\ARM\\ARMCC\\include\\rw",
"d:\\Desktop\\R1_up\\MDK-ARM", "d:\\Desktop\\r1\\R1_up\\MDK-ARM",
"d:\\Desktop\\R1_up\\Core\\Src", "d:\\Desktop\\r1\\R1_up\\Core\\Src",
"d:\\Desktop\\R1_up\\Drivers\\STM32F4xx_HAL_Driver\\Src", "d:\\Desktop\\r1\\R1_up\\Drivers\\STM32F4xx_HAL_Driver\\Src",
"d:\\Desktop\\R1_up\\Middlewares\\Third_Party\\FreeRTOS\\Source", "d:\\Desktop\\r1\\R1_up\\Middlewares\\Third_Party\\FreeRTOS\\Source",
"d:\\Desktop\\R1_up\\Middlewares\\Third_Party\\FreeRTOS\\Source\\portable\\MemMang" "d:\\Desktop\\r1\\R1_up\\Middlewares\\Third_Party\\FreeRTOS\\Source\\portable\\MemMang"
], ],
"defines": [ "defines": [
"USE_HAL_DRIVER", "USE_HAL_DRIVER",

View File

@ -102,73 +102,3 @@
[info] Log at : 2025/7/4|09:10:46|GMT+0800 [info] Log at : 2025/7/4|09:10:46|GMT+0800
[info] Log at : 2025/7/6|22:01:26|GMT+0800
[info] Log at : 2025/7/6|22:02:13|GMT+0800
[info] Log at : 2025/7/6|23:12:04|GMT+0800
[info] Log at : 2025/7/7|04:53:38|GMT+0800
[info] Log at : 2025/7/7|08:44:07|GMT+0800
[info] Log at : 2025/7/7|14:20:11|GMT+0800
[info] Log at : 2025/7/8|02:49:12|GMT+0800
[info] Log at : 2025/7/8|13:15:42|GMT+0800
[info] Log at : 2025/7/8|18:00:22|GMT+0800
[info] Log at : 2025/7/8|20:39:07|GMT+0800
[info] Log at : 2025/7/9|08:39:28|GMT+0800
[info] Log at : 2025/7/9|11:36:02|GMT+0800
[info] Log at : 2025/7/9|16:01:34|GMT+0800
[info] Log at : 2025/7/9|23:48:02|GMT+0800
[info] Log at : 2025/7/10|01:59:23|GMT+0800
[info] Log at : 2025/7/10|15:33:45|GMT+0800
[info] Log at : 2025/7/10|17:26:59|GMT+0800
[info] Log at : 2025/7/10|22:12:10|GMT+0800
[info] Log at : 2025/7/11|10:11:25|GMT+0800
[info] Log at : 2025/7/11|17:39:11|GMT+0800
[info] Log at : 2025/7/12|23:45:28|GMT+0800
[info] Log at : 2025/7/13|11:08:55|GMT+0800
[info] Log at : 2025/7/13|12:29:41|GMT+0800
[info] Log at : 2025/7/13|16:33:17|GMT+0800
[info] Log at : 2025/7/13|16:42:25|GMT+0800
[info] Log at : 2025/7/13|22:38:15|GMT+0800
[info] Log at : 2025/7/14|07:52:29|GMT+0800
[info] Log at : 2025/7/14|12:31:22|GMT+0800
[info] Log at : 2025/7/14|13:56:03|GMT+0800
[info] Log at : 2025/7/16|22:15:00|GMT+0800
[info] Log at : 2025/7/16|22:26:06|GMT+0800
[info] Log at : 2025/8/26|11:04:50|GMT+0800
[info] Log at : 2025/8/27|09:22:50|GMT+0800
[info] Log at : 2025/8/27|21:26:07|GMT+0800
[info] Log at : 2025/8/28|09:52:37|GMT+0800

View File

@ -1,76 +1,13 @@
*** Using Compiler 'V5.06 update 7 (build 960)', folder: 'D:\Develop\keil\ARM\ARMCC\Bin' *** Using Compiler 'V5.06 update 7 (build 960)', folder: 'D:\keil\ARM\ARMCC\Bin'
Rebuild target 'R1' Build target 'R1'
assembling startup_stm32f407xx.s...
compiling crc.c...
compiling dma.c...
compiling gpio.c...
compiling tim.c...
compiling stm32f4xx_hal_rcc_ex.c...
compiling spi.c...
compiling stm32f4xx_hal_can.c...
compiling main.c...
compiling usart.c...
compiling freertos.c...
compiling stm32f4xx_it.c...
compiling can.c...
compiling stm32f4xx_hal_msp.c...
compiling stm32f4xx_hal_rcc.c...
compiling stm32f4xx_hal_cortex.c...
compiling stm32f4xx_hal_pwr.c...
compiling stm32f4xx_hal_crc.c...
compiling stm32f4xx_hal_dma.c...
compiling stm32f4xx_hal_pwr_ex.c...
compiling stm32f4xx_hal_flash_ex.c...
compiling stm32f4xx_hal_flash_ramfunc.c...
compiling stm32f4xx_hal_flash.c...
compiling stm32f4xx_hal.c...
compiling stm32f4xx_hal_gpio.c...
compiling stm32f4xx_hal_exti.c...
compiling croutine.c...
compiling stm32f4xx_hal_dma_ex.c...
compiling stm32f4xx_hal_spi.c...
compiling event_groups.c...
compiling list.c...
compiling stream_buffer.c...
compiling queue.c...
compiling heap_4.c...
compiling timers.c...
compiling stm32f4xx_hal_tim.c...
compiling port.c...
compiling tasks.c...
compiling calc_lib.c...
compiling crc_ccitt.c...
compiling kalman.c...
compiling gpio_it.c...
compiling system_stm32f4xx.c...
compiling can_it.c...
compiling bsp_delay.c...
compiling can_init.c...
compiling bsp_buzzer.c...
compiling uart_it.c...
compiling stm32f4xx_hal_tim_ex.c...
compiling stm32f4xx_hal_uart.c...
compiling user_math.c...
compiling filter.c...
compiling pid.c...
compiling buzzer.c...
compiling userTask.c...
compiling cmsis_os2.c...
compiling detect.c...
compiling vofa.c...
compiling GO_M8010_6_Driver.c...
compiling remote_control.c...
compiling initTask.c...
compiling nuc.c...
compiling nucTask.cpp...
compiling encodeCan.cpp...
compiling djiMotor.c...
compiling ballTask.cpp...
compiling shootTask.cpp... compiling shootTask.cpp...
compiling shoot.cpp... compiling nuc.c...
compiling initTask.c...
compiling ball.cpp... compiling ball.cpp...
compiling nucTask.cpp...
compiling shoot.cpp...
linking... linking...
Program Size: Code=31312 RO-data=1832 RW-data=280 ZI-data=32264 Program Size: Code=32960 RO-data=1832 RW-data=268 ZI-data=32220
FromELF: creating hex file... FromELF: creating hex file...
"R1\R1.axf" - 0 Error(s), 0 Warning(s). "R1\R1.axf" - 0 Error(s), 0 Warning(s).
Build Time Elapsed: 00:00:25 Build Time Elapsed: 00:02:09

View File

@ -1 +1 @@
2025/8/27 9:23:25 2025/7/4 9:21:52

View File

@ -12,7 +12,7 @@
<lExt>*.lib</lExt> <lExt>*.lib</lExt>
<tExt>*.txt; *.h; *.inc; *.md</tExt> <tExt>*.txt; *.h; *.inc; *.md</tExt>
<pExt>*.plm</pExt> <pExt>*.plm</pExt>
<CppX>*.cpp; *.cc; *.cxx</CppX> <CppX>*.cpp</CppX>
<nMigrate>0</nMigrate> <nMigrate>0</nMigrate>
</Extensions> </Extensions>
@ -26,7 +26,7 @@
<ToolsetNumber>0x4</ToolsetNumber> <ToolsetNumber>0x4</ToolsetNumber>
<ToolsetName>ARM-ADS</ToolsetName> <ToolsetName>ARM-ADS</ToolsetName>
<TargetOption> <TargetOption>
<CLKADS>25000000</CLKADS> <CLKADS>12000000</CLKADS>
<OPTTT> <OPTTT>
<gFlags>1</gFlags> <gFlags>1</gFlags>
<BeepAtEnd>1</BeepAtEnd> <BeepAtEnd>1</BeepAtEnd>
@ -93,7 +93,7 @@
<tRbreak>1</tRbreak> <tRbreak>1</tRbreak>
<tRwatch>1</tRwatch> <tRwatch>1</tRwatch>
<tRmem>1</tRmem> <tRmem>1</tRmem>
<tRfunc>0</tRfunc> <tRfunc>1</tRfunc>
<tRbox>1</tRbox> <tRbox>1</tRbox>
<tRtrace>1</tRtrace> <tRtrace>1</tRtrace>
<sRSysVw>1</sRSysVw> <sRSysVw>1</sRSysVw>
@ -117,6 +117,11 @@
<pMon>BIN\CMSIS_AGDI.dll</pMon> <pMon>BIN\CMSIS_AGDI.dll</pMon>
</DebugOpt> </DebugOpt>
<TargetDriverDllRegistry> <TargetDriverDllRegistry>
<SetRegEntry>
<Number>0</Number>
<Key>CMSIS_AGDI</Key>
<Name>-X"Any" -UAny -O206 -S8 -C0 -P00000000 -N00("ARM CoreSight SW-DP") -D00(2BA01477) -L00(0) -TO65554 -TC10000000 -TT10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0STM32F4xx_1024.FLM -FS08000000 -FL0100000 -FP0($$Device:STM32F407IGHx$CMSIS\Flash\STM32F4xx_1024.FLM)</Name>
</SetRegEntry>
<SetRegEntry> <SetRegEntry>
<Number>0</Number> <Number>0</Number>
<Key>ARMRTXEVENTFLAGS</Key> <Key>ARMRTXEVENTFLAGS</Key>
@ -139,13 +144,13 @@
</SetRegEntry> </SetRegEntry>
<SetRegEntry> <SetRegEntry>
<Number>0</Number> <Number>0</Number>
<Key>CMSIS_AGDI</Key> <Key>UL2CM3</Key>
<Name>-X"Any" -UAny -O206 -S8 -C0 -P00000000 -N00("ARM CoreSight SW-DP") -D00(2BA01477) -L00(0) -TO65554 -TC10000000 -TT10000000 -TP20 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC1000 -FN1 -FF0STM32F4xx_1024.FLM -FS08000000 -FL0100000 -FP0($$Device:STM32F407IGHx$CMSIS\Flash\STM32F4xx_1024.FLM)</Name> <Name>UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0STM32F4xx_1024 -FS08000000 -FL0100000 -FP0($$Device:STM32F407IGHx$CMSIS\Flash\STM32F4xx_1024.FLM))</Name>
</SetRegEntry> </SetRegEntry>
<SetRegEntry> <SetRegEntry>
<Number>0</Number> <Number>0</Number>
<Key>UL2CM3</Key> <Key>ST-LINKIII-KEIL_SWO</Key>
<Name>UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0STM32F4xx_1024 -FS08000000 -FL0100000 -FP0($$Device:STM32F407IGHx$CMSIS\Flash\STM32F4xx_1024.FLM))</Name> <Name>-U00160029510000164E574E32 -O2254 -SF10000 -C0 -A0 -I0 -HNlocalhost -HP7184 -P1 -N00("ARM CoreSight SW-DP (ARM Core") -D00(2BA01477) -L00(0) -TO131090 -TC10000000 -TT10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO15 -FD20000000 -FC800 -FN1 -FF0STM32F4xx_1024.FLM -FS08000000 -FL0100000 -FP0($$Device:STM32F407IGHx$CMSIS\Flash\STM32F4xx_1024.FLM)</Name>
</SetRegEntry> </SetRegEntry>
</TargetDriverDllRegistry> </TargetDriverDllRegistry>
<Breakpoint/> <Breakpoint/>
@ -153,20 +158,58 @@
<Ww> <Ww>
<count>0</count> <count>0</count>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>and1</ItemText> <ItemText>rc_ctrl,0x0A</ItemText>
</Ww> </Ww>
<Ww> <Ww>
<count>1</count> <count>1</count>
<WinNumber>1</WinNumber> <WinNumber>1</WinNumber>
<ItemText>ws</ItemText> <ItemText>shoot,0x0A</ItemText>
</Ww>
<Ww>
<count>2</count>
<WinNumber>1</WinNumber>
<ItemText>ball,0x0A</ItemText>
</Ww>
<Ww>
<count>3</count>
<WinNumber>1</WinNumber>
<ItemText>nucbuf</ItemText>
</Ww>
<Ww>
<count>4</count>
<WinNumber>1</WinNumber>
<ItemText>nuc_v</ItemText>
</Ww>
<Ww>
<count>5</count>
<WinNumber>1</WinNumber>
<ItemText>abc,0x0A</ItemText>
</Ww>
<Ww>
<count>6</count>
<WinNumber>1</WinNumber>
<ItemText>shoot_wait,0x0A</ItemText>
</Ww>
<Ww>
<count>7</count>
<WinNumber>1</WinNumber>
<ItemText>error_code</ItemText>
</Ww> </Ww>
</WatchWindow1> </WatchWindow1>
<MemoryWindow4>
<Mm>
<WinNumber>4</WinNumber>
<SubType>0</SubType>
<ItemText>nucbuf</ItemText>
<AccSizeX>0</AccSizeX>
</Mm>
</MemoryWindow4>
<Tracepoint> <Tracepoint>
<THDelay>0</THDelay> <THDelay>0</THDelay>
</Tracepoint> </Tracepoint>
<DebugFlag> <DebugFlag>
<trace>0</trace> <trace>0</trace>
<periodic>0</periodic> <periodic>1</periodic>
<aLwin>1</aLwin> <aLwin>1</aLwin>
<aCover>0</aCover> <aCover>0</aCover>
<aSer1>0</aSer1> <aSer1>0</aSer1>
@ -185,7 +228,7 @@
<aPa1>0</aPa1> <aPa1>0</aPa1>
<AscS4>0</AscS4> <AscS4>0</AscS4>
<aSer4>0</aSer4> <aSer4>0</aSer4>
<StkLoc>0</StkLoc> <StkLoc>1</StkLoc>
<TrcWin>0</TrcWin> <TrcWin>0</TrcWin>
<newCpu>0</newCpu> <newCpu>0</newCpu>
<uProt>0</uProt> <uProt>0</uProt>
@ -205,7 +248,7 @@
<pMultCmdsp></pMultCmdsp> <pMultCmdsp></pMultCmdsp>
<DebugDescription> <DebugDescription>
<Enable>1</Enable> <Enable>1</Enable>
<EnableFlashSeq>1</EnableFlashSeq> <EnableFlashSeq>0</EnableFlashSeq>
<EnableLog>0</EnableLog> <EnableLog>0</EnableLog>
<Protocol>2</Protocol> <Protocol>2</Protocol>
<DbgClock>10000000</DbgClock> <DbgClock>10000000</DbgClock>
@ -1043,7 +1086,7 @@
<Group> <Group>
<GroupName>User/task</GroupName> <GroupName>User/task</GroupName>
<tvExp>0</tvExp> <tvExp>1</tvExp>
<tvExpOptDlg>0</tvExpOptDlg> <tvExpOptDlg>0</tvExpOptDlg>
<cbSel>0</cbSel> <cbSel>0</cbSel>
<RteFlg>0</RteFlg> <RteFlg>0</RteFlg>

View File

@ -137,7 +137,7 @@
<DriverSelection>4101</DriverSelection> <DriverSelection>4101</DriverSelection>
</Flash1> </Flash1>
<bUseTDR>1</bUseTDR> <bUseTDR>1</bUseTDR>
<Flash2>BIN\UL2CM3.DLL</Flash2> <Flash2>BIN\UL2V8M.DLL</Flash2>
<Flash3></Flash3> <Flash3></Flash3>
<Flash4></Flash4> <Flash4></Flash4>
<pFcarmOut></pFcarmOut> <pFcarmOut></pFcarmOut>

View File

@ -5,60 +5,19 @@ r1上层
## 外设 ## 外设
+ CAN1 + CAN1
+ 扳机2006 id:0x201 - 扳机2006 id:0x205
+ CAN2 - 三摩擦 id:123
+ 小米电机 id:1
+ UART + UART
+ uart1 波特率4000000 id2 - uart1 波特率4000000 id2
+ uart6 nuc - uart6 nuc
+ uart3 遥控器接收 - uart3 遥控器接收
+ GPIO + GPIO
+ PI6运球光电 - PI6运球光电
+ PE13 爪气缸 - PE11 运球气缸
+ PE14 砸气缸
## 遥控器 ## 遥控器
## 待解决
+ 用了将运球和伸缩绑定到一起 √
+ 串口收数加个滤波 √
## 思路
+ 👆 传球档 👆 配合档
+ 中 初始档 中 初始档
+ 👇 发射档 👇 运球档
+ 起步遥控档我直接蓄力准备接球 + 可多次的运球
+ 缩回转移球
+ 蓄力到位,收到掉落信号和已伸出信号
+ 根据视觉拟合信息的动态调整
+ 拨置👇发射清空掉落信号
+ 用一个攻守方档
+ 初始移动到最上面 更待蓄力(不管攻方守方都在最上面等待)
+ 攻方时拨下立马蓄力并伸出(可小角度)
+ 守方时不动并保持缩回
+ 👇 运球档正常运球
+ 中 初始档直接缩回
+ 👆 配合档 完成配合并伸出才能发射
+ 传球模式
+ 自动
+ 底盘的传球对准档拨下
+ 我的蓄力进入传球拟合
+ 继续拨下发射
+ 手动
+ 目前只能打固定距离
+ 切相同传球档 自动蓄力到传球力度
+ 发射档发射
+ 图传多距离
+ 传球档
+ 旋钮+看图传点位调整
+ 修复
+ 6.29 发射误操作导致没有拟合作用就射了(已修复)
+ 6.29 串口不稳定 重新拔插一下
+ 6.29 nuc位置更新慢
+ 6.29 添加光电上电保护防止跳尺(已添加)

View File

@ -16,7 +16,7 @@
#endif #endif
#define ONE_CONTROL 0 #define ONE_CONTROL 1
//是否使用大疆DT7遥控器 //是否使用大疆DT7遥控器
#ifndef DT7 #ifndef DT7
@ -28,8 +28,7 @@
//================任务通知,时间组================// //================任务通知,时间组================//
//事件组 //事件组
#define EVENT_RC (1<<1) #define EVENT_RC (1<<1)
#define EVENT_CAN1 (1<<2) #define EVENT_CAN (1<<2)
#define EVENT_CAN2 (1<<3)
//================任务通知================// //================任务通知================//
//运球 //运球
@ -43,8 +42,6 @@
#define EXTEND_OK (1<<3) #define EXTEND_OK (1<<3)
//等待ok //等待ok
#define WAIT_OK (1<<4) #define WAIT_OK (1<<4)
//可以防守收回
#define DEF_READY (1<<5)
//要发送ok了 //要发送ok了
#define BALL_SEND (1<<6) #define BALL_SEND (1<<6)

View File

@ -215,13 +215,15 @@ static osThreadId_t thread_alert;
void Dji_Motor_CB() void Dji_Motor_CB()
{ {
HAL_CAN_GetRxMessage(&hcan1, CAN_RX_FIFO0, &dji_rx_header, dji_rx_data); HAL_CAN_GetRxMessage(&hcan1, CAN_RX_FIFO0, &dji_rx_header, dji_rx_data);
osThreadFlagsSet(thread_alert, EVENT_CAN1);
osThreadFlagsSet(thread_alert, EVENT_CAN);
// osEventFlagsSet(eventReceive, EVENT_CAN);
} }
void can2_Motor_CB(void) void can2_Motor_CB(void)
{ {
HAL_CAN_GetRxMessage(&hcan2, CAN_RX_FIFO1, &rx_header, rx_data); HAL_CAN_GetRxMessage(&hcan2, CAN_RX_FIFO1, &rx_header, rx_data);
osThreadFlagsSet(thread_alert, EVENT_CAN2);
//osThreadFlagsSet(thread_alert, EVENT_CAN);
} }
/** /**
@ -232,6 +234,9 @@ void can2_Motor_CB(void)
void djiInit(void) void djiInit(void)
{ {
thread_alert = osThreadGetId(); thread_alert = osThreadGetId();
BSP_CAN_RegisterCallback(BSP_CAN_1, HAL_CAN_RX_FIFO0_MSG_PENDING_CB, BSP_CAN_RegisterCallback(BSP_CAN_1, HAL_CAN_RX_FIFO0_MSG_PENDING_CB,
Dji_Motor_CB); Dji_Motor_CB);
BSP_CAN_RegisterCallback(BSP_CAN_2, HAL_CAN_RX_FIFO1_MSG_PENDING_CB, BSP_CAN_RegisterCallback(BSP_CAN_2, HAL_CAN_RX_FIFO1_MSG_PENDING_CB,
@ -245,9 +250,11 @@ void djiInit(void)
*/ */
uint32_t waitNewDji() uint32_t waitNewDji()
{ {
// 等待CAN1或CAN2任意一个事件 // return osEventFlagsWait(
// eventReceive, EVENT_CAN,osFlagsWaitAny, osWaitForever);
return osThreadFlagsWait( return osThreadFlagsWait(
EVENT_CAN1 | EVENT_CAN2, osFlagsWaitAny, osWaitForever); EVENT_CAN, osFlagsWaitAll, osWaitForever);
} }
#endif #endif

View File

@ -6,7 +6,7 @@ static osThreadId_t thread_alert;
volatile uint32_t drop_message = 0; volatile uint32_t drop_message = 0;
uint8_t nucbuf[18]; uint8_t nucbuf[16];
uint8_t packet[32]; // 假设最大数据包长度为 32 字节 uint8_t packet[32]; // 假设最大数据包长度为 32 字节
static void NUC_CBLTCallback(void) static void NUC_CBLTCallback(void)
@ -82,62 +82,6 @@ int8_t NUC_SendPacket(void *data, uint16_t length) {
return DEVICE_OK; // 发送成功 return DEVICE_OK; // 发送成功
} }
// int8_t NUC_RawParse(NUC_t *n) {
// if (n == NULL) return DEVICE_ERR_NULL;
// union {
// float x[3];
// char data[12];
// } instance; // 方便在浮点数和字符数组之间进行数据转换
// // 校验数据包头
// if(nucbuf[0]!=HEAD) goto error; //发送ID不是底盘
// else
// {
// n->status_fromnuc = nucbuf[1];
// n->ctrl_status = nucbuf[2];
// switch (n->status_fromnuc) {
// case VISION:
// /* 协议格式
// 0xFF HEAD
// 0x07
// 控制帧
// 0x01 相机帧
// x fp32
// 0xFE TAIL
// */
// if (nucbuf[7] != TAIL) goto error;
// instance.data[3] = nucbuf[6];
// instance.data[2] = nucbuf[5];
// instance.data[1] = nucbuf[4];
// instance.data[0] = nucbuf[3];
// n->vision.x = instance.x[0];
// instance.data[7] = nucbuf[10];
// instance.data[6] = nucbuf[9];
// instance.data[5] = nucbuf[8];
// instance.data[4] = nucbuf[7];
// n->vision.y = instance.x[1];
// break;
// }
// return DEVICE_OK;
// }
// error:
// drop_message++;
// return DEVICE_ERR;
// }
/* 协议格式
0xFF HEAD
x fp32
y fp32
0xFE TAIL
*/
int8_t NUC_RawParse(NUC_t *n) { int8_t NUC_RawParse(NUC_t *n) {
if (n == NULL) return DEVICE_ERR_NULL; if (n == NULL) return DEVICE_ERR_NULL;
union { union {
@ -149,24 +93,43 @@ int8_t NUC_RawParse(NUC_t *n) {
if(nucbuf[0]!=HEAD) goto error; //发送ID不是底盘 if(nucbuf[0]!=HEAD) goto error; //发送ID不是底盘
else else
{ {
n->status_fromnuc = nucbuf[1];
n->ctrl_status = nucbuf[2];
switch (n->status_fromnuc) {
case VISION:
/* 协议格式
0xFF HEAD
0x07
0x01
x fp32
0xFE TAIL
*/
if (nucbuf[7] != TAIL) goto error;
if (nucbuf[17] != TAIL) goto error; instance.data[3] = nucbuf[6];
instance.data[2] = nucbuf[5];
instance.data[3] = nucbuf[8]; instance.data[1] = nucbuf[4];
instance.data[2] = nucbuf[7]; instance.data[0] = nucbuf[3];
instance.data[1] = nucbuf[6];
instance.data[0] = nucbuf[5];
n->vision.x = instance.x[0]; n->vision.x = instance.x[0];
instance.data[7] = nucbuf[16]; instance.data[7] = nucbuf[10];
instance.data[6] = nucbuf[15]; instance.data[6] = nucbuf[9];
instance.data[5] = nucbuf[14]; instance.data[5] = nucbuf[8];
instance.data[4] = nucbuf[13]; instance.data[4] = nucbuf[7];
n->vision.y = instance.x[1]; n->vision.y = instance.x[1];
instance.data[11] = nucbuf[11];
instance.data[10] = nucbuf[12];
instance.data[9] = nucbuf[13];
instance.data[8] = nucbuf[14];
n->vision.z = instance.x[2];
break;
} }
return DEVICE_OK; return DEVICE_OK;
}
error: error:
drop_message++; drop_message++;
return DEVICE_ERR; return DEVICE_ERR;

View File

@ -11,14 +11,14 @@ extern int ball_exit;
// 外死点168 外163 中150 内127 限位124.8 // 外死点168 外163 中150 内127 限位124.8
// 伸缩 // 伸缩
//外死点89 外85 中75 内49 限位46 //外死点168 外163 中150 内127 限位124.8
#define I_ANGLE 127
#define O_ANGLE 163
#define WAIT_POS 150
#define IN 124.8
#define OUT 168
#define I_ANGLE 49 // PE11 气缸
#define O_ANGLE 85
#define WAIT_POS 75
#define HANGDING_POS 89
// PE11 气缸git stash apply
Ball ::Ball() Ball ::Ball()
{ {
@ -107,7 +107,7 @@ void Ball::Move_Extend()
} }
if (extern_key == OUT) if (extern_key == OUT)
{ {
xiaomi.position = HANGDING_POS; xiaomi.position = O_ANGLE;
} }
} }
@ -218,13 +218,12 @@ void Ball::ballHadling(void)
void Ball::ball_control() void Ball::ball_control()
{ {
hand_thread = osThreadFlagsGet(); // 获取任务通知标志位 hand_thread = osThreadFlagsGet(); // 获取任务通知标志位
ball_state = HAL_GPIO_ReadPin(up_ball_GPIO_Port, up_ball_Pin); // 读取光电状态(有球 0无球 1) ball_state = HAL_GPIO_ReadPin(up_ball_GPIO_Port, up_ball_Pin); // 读取光电状态(有球 1无球 0)
// 进攻 // 进攻
if (ready_key == SIDE) if (ready_key == SIDE)
{ {
osThreadFlagsClear(DEF_READY);
switch (rc_key) switch (rc_key)
{ {
case MIDDLE2: case MIDDLE2:
@ -237,6 +236,10 @@ void Ball::ball_control()
case DOWN2: case DOWN2:
ballHadling(); ballHadling();
if(hand_thread & HANDING_FINISH)
{
ballDown();
}
break; break;
} }
@ -245,23 +248,10 @@ void Ball::ball_control()
// 防守 // 防守
else if(ready_key == DEF) else if(ready_key == DEF)
{ {
if(hand_thread & DEF_READY) xiaomi.position = I_ANGLE; // 保持收回
{
xiaomi.position = I_ANGLE;
}
// 保持收回
HAL_GPIO_WritePin(CLOSE_GPIO_Port, CLOSE_Pin, GPIO_PIN_RESET); // 确保爪气缸关闭 HAL_GPIO_WritePin(CLOSE_GPIO_Port, CLOSE_Pin, GPIO_PIN_RESET); // 确保爪气缸关闭
HAL_GPIO_WritePin(DOWN_GPIO_Port, DOWN_Pin, GPIO_PIN_RESET); // 确保下气缸关闭 HAL_GPIO_WritePin(DOWN_GPIO_Port, DOWN_Pin, GPIO_PIN_RESET); // 确保下气缸关闭
osThreadFlagsClear(EXTEND_OK);
osThreadFlagsClear(READY_TELL); // 蓄力标志位
osThreadFlagsClear(HANDING_FINISH);
haveball=0;//变为空球状态
currentState1 = BALL_IDLE;
Send_control(); Send_control();
} }
@ -271,12 +261,11 @@ void Ball::ball_control()
void Ball::ballDown(void) void Ball::ballDown(void)
{ {
osThreadFlagsClear(HANDING_FINISH);
switch (currentState1) switch (currentState1)
{ {
case BALL_IDLE: case BALL_FINISH:
xiaomi.position = I_ANGLE; // 保持收回 xiaomi.position = I_ANGLE; // 保持收回
if (feedback->position_deg >= I_ANGLE - 1 && feedback->position_deg <= I_ANGLE + 1) if (feedback->position_deg >= I_ANGLE - 0.8 && feedback->position_deg <= I_ANGLE + 0.8)
{ {
currentState1 = EXTEND_DOWN; currentState1 = EXTEND_DOWN;
} }
@ -295,7 +284,7 @@ void Ball::ballDown(void)
case EXTEND_OUT: case EXTEND_OUT:
xiaomi.position = O_ANGLE; // 保持伸出 xiaomi.position = O_ANGLE; // 保持伸出
if (feedback->position_deg >= O_ANGLE - 1 && feedback->position_deg <= O_ANGLE + 1) if (feedback->position_deg >= O_ANGLE - 0.2 && feedback->position_deg <= O_ANGLE + 0.2)
{ {
osThreadFlagsSet(task_struct.thread.shoot, EXTEND_OK); osThreadFlagsSet(task_struct.thread.shoot, EXTEND_OK);
@ -315,48 +304,25 @@ void Ball::ballDown(void)
} }
} }
void Ball::Idle_control() void Ball::Idle_control()
{ {
if(ball_state==1 && haveball==0)// 读取光电状态(有球 0无球 1) HAL_GPIO_WritePin(CLOSE_GPIO_Port, CLOSE_Pin, GPIO_PIN_RESET); // 确保爪气缸关闭
{
HAL_GPIO_WritePin(CLOSE_GPIO_Port, CLOSE_Pin, GPIO_PIN_SET); // 确保爪气缸张开
}
if(ball_state==0)
{
haveball=1;//变为持球状态
osDelay(500);
HAL_GPIO_WritePin(CLOSE_GPIO_Port, CLOSE_Pin, GPIO_PIN_RESET); // 确保爪气缸闭合
}
// HAL_GPIO_WritePin(CLOSE_GPIO_Port, CLOSE_Pin, GPIO_PIN_RESET); // 确保爪气缸关闭
HAL_GPIO_WritePin(DOWN_GPIO_Port, DOWN_Pin, GPIO_PIN_RESET); // 确保下气缸关闭 HAL_GPIO_WritePin(DOWN_GPIO_Port, DOWN_Pin, GPIO_PIN_RESET); // 确保下气缸关闭
osThreadFlagsClear(EXTEND_OK); osThreadFlagsClear(EXTEND_OK);
osThreadFlagsClear(HANDING_FINISH);
if (ready_key == SIDE) // 检测是否准备好 if (ready_key == SIDE) // 检测是否准备好
{ {
if(hand_thread & HANDING_FINISH) xiaomi.position = WAIT_POS;
if (feedback->position_deg >= WAIT_POS - 3)
{ {
xiaomi.position=HANGDING_POS;//继续保持外伸
}
else
{
xiaomi.position = WAIT_POS;
if (feedback->position_deg >= WAIT_POS - 3)
{
// 只在READY_TELL未置位时发送防止重复 // 只在READY_TELL未置位时发送防止重复
if ((osThreadFlagsGet() & READY_TELL) == 0) if ((osThreadFlagsGet() & READY_TELL) == 0)
{ {
osThreadFlagsSet(task_struct.thread.shoot, READY_TELL); osThreadFlagsSet(task_struct.thread.shoot, READY_TELL);
} }
}
} }
} }
else else
{ {
@ -378,11 +344,9 @@ void Ball::Idle_control()
{ {
currentState1 = BALL_IDLE; currentState1 = BALL_IDLE;
} }
// xiaomi.position = I_ANGLE;
} }
int ball_state = 0; int ball_state = 0;
int last_ball_state = 0; // 上一次的光电状态 int last_ball_state = 0; // 上一次的光电状态
@ -394,8 +358,8 @@ void Ball::ballHadling(void)
case BALL_IDLE: case BALL_IDLE:
if (rc_key == DOWN2) if (rc_key == DOWN2)
{ {
xiaomi.position = HANGDING_POS; // 外伸 xiaomi.position = O_ANGLE; // 外伸
if (feedback->position_deg >= HANGDING_POS - 0.5f) // 确保伸缩电机到位 if (feedback->position_deg >= O_ANGLE - 1) // 确保伸缩电机到位
{ {
currentState1 = BALL_FORWARD; currentState1 = BALL_FORWARD;
} }
@ -440,11 +404,11 @@ void Ball::ballHadling(void)
case BALL_FINISH: case BALL_FINISH:
osDelay(50); // 延时 50ms osDelay(50); // 延时 50ms
osThreadFlagsSet(task_struct.thread.ball, HANDING_FINISH); osThreadFlagsSet(task_struct.thread.ball, HANDING_FINISH);
HAL_GPIO_WritePin(CLOSE_GPIO_Port, CLOSE_Pin, GPIO_PIN_RESET); // 确保气缸爪子闭合 HAL_GPIO_WritePin(CLOSE_GPIO_Port, CLOSE_Pin, GPIO_PIN_RESET); // 确保气缸爪子闭合
HAL_GPIO_WritePin(DOWN_GPIO_Port, DOWN_Pin, GPIO_PIN_RESET); // 确保下气缸关闭 HAL_GPIO_WritePin(DOWN_GPIO_Port, DOWN_Pin, GPIO_PIN_RESET); // 确保下气缸关闭
break;
break;
default: default:
currentState1 = BALL_IDLE; // 默认回到空闲状态 currentState1 = BALL_IDLE; // 默认回到空闲状态
break; break;

View File

@ -74,10 +74,11 @@ public:
int16_t extern_key; int16_t extern_key;
int16_t ready_key; //准备按键 int16_t ready_key; //准备按键
//用于传接球,运球后通知 //用于传接球,运球后通知
volatile BallState_t ballStatus;//是否有球
volatile uint32_t hand_thread;//接收传回的线程通知 volatile uint32_t hand_thread;//接收传回的线程通知
private: private:
bool haveball;
}; };

113
User/module/gimbal.cpp Normal file
View File

@ -0,0 +1,113 @@
#include "TopDefine.h"
#include "gimbal.hpp"
#include "remote_control.h"
#include "calc_lib.h"
#include "FreeRTOS.h"
#include <cmsis_os2.h>
#define KP 0.12
#define KD 0.008
//可活动角度
#define ANGLE_ALLOW 1.0f
extern RC_ctrl_t rc_ctrl;
NUC_t nuc;
const fp32 Gimbal:: Gimbal_speed_PID[3] = {50, 0.1, 0};
const fp32 Gimbal:: Gimbal_angle_PID[3]= { 5, 0.01, 0};
#if GM6020ING ==1
Gimbal::Gimbal()
{
// GM6020_Motor = get_motor_point(6);
// GM6020_Motor->type = GM6020;
// PID_init(&speed_pid,PID_POSITION,Gimbal_speed_PID,16000, 6000);
// PID_init(&angle_pid,PID_POSITION,Gimbal_angle_PID,5000, 2000);
// result = 0;
// angleSet = 0;
}
void Gimbal::gimbalFlow()
{
int16_t delta[1];
//angleSet = angle1;
delta[0] = PID_calc(&angle_pid,GM6020_Motor->total_angle,angleSet);
result = PID_calc(&speed_pid, GM6020_Motor->speed_rpm, delta[0]);
CAN_cmd_1FF(0,0,result,0,&hcan1);
osDelay(1);
}
void Gimbal::gimbalZero()
{
angleSet=0;
//gimbalFlow();
}
void Gimbal::gimbalVision(const NUC_t &nuc)
{
int16_t delta[1];
angleSet = nuc.vision.x;
delta[0] = PID_calc(&angle_pid,GM6020_Motor->total_angle,angleSet);
result = PID_calc(&speed_pid, GM6020_Motor->speed_rpm, delta[0]);
CAN_cmd_1FF(0,0,result,0,&hcan1);
osDelay(1);
}
#else
Gimbal::Gimbal()
{
Kp = KP;
Kd = KD;
allowRange = ANGLE_ALLOW;
}
void Gimbal::gimbalInit(void)
{
int i;
GO_M8010_init();
for(i = 0;i < GO_NUM;i ++)
{
goData[i] = getGoPoint(i);//获取电机数据指针
angleSet[i] = 0;
offestAngle[i] = 0;
GO_M8010_send_data(&huart6, i,0,0,0,0,0,0);
offestAngle[i] = goData[i]->Pos;
HAL_Delay(100);
}
}
void Gimbal::gimbalFlow(void)
{
//angleSet[0] = map_fp32((float)rc_ctrl.ch[3],-800.0f,800.0f,-allowRange,allowRange) + offestAngle[0];
GO_M8010_send_data(&huart6, 0,0,0,angleSet[0],1,KP,KD);
osDelay(1);
}
void Gimbal::gimbalZero(void)
{
GO_M8010_send_data(&huart6, 0,0,0,0,0,0,0);
}
void Gimbal::gimbalVision(const NUC_t &nuc)
{
angleSet[0] = nuc.vision.x;
GO_M8010_send_data(&huart6, 0,0,0,angleSet[0],1,KP,KD);
osDelay(1);
}
#endif

57
User/module/gimbal.hpp Normal file
View File

@ -0,0 +1,57 @@
#ifndef GIMBAL_HPP
#define GIMBAL_HPP
#include "GO_M8010_6_Driver.h"
#include "djiMotor.h"
#include "pid.h"
#include "nuc.h"
class Gimbal
{
public:
Gimbal();
void gimbalFlow(void);//云台随遥控器转动
void gimbalZero(void);//云台零阻尼模式
void gimbalInit(void);//go初始化
void gimbalVision(const NUC_t &nuc); // 接收 NUC_t 数据
int16_t result;
//暂存要发送的扭矩
//float result[GO_NUM];
// float Kp;
// float Kd;
private:
#if GM6020ING == 1
//GM6020电机数据
motor_measure_t *GM6020_Motor;
static const float Gimbal_speed_PID[3];
static const float Gimbal_angle_PID[3];
//电机速度pid结构体
pid_type_def speed_pid;
//位置环pid
pid_type_def angle_pid;
float angleSet;
#else
motor_measure_t *motorData[GO_NUM];
//视觉发送的要调的角度
float self_angleSet;
GO_Motorfield* goData[GO_NUM];
//暂存目标位置
float angleSet[GO_NUM];
float offestAngle[GO_NUM];//go数据
float Kp;
float Kd;
float allowRange;
#endif
};
#endif

View File

@ -15,7 +15,7 @@ extern RC_ctrl_t rc_ctrl;
NUC_t nuc_v; NUC_t nuc_v;
float vofa[8]; float vofa[8];
double test_distance=4.0; double test_distance;
// sw[7]👆 1694 中 1000 👇306 // sw[7]👆 1694 中 1000 👇306
// sw[2]👆 1694 👇306 // sw[2]👆 1694 👇306
@ -29,22 +29,19 @@ double test_distance=4.0;
const fp32 Shoot::M2006_speed_PID[3] = {5, 0, 0.01}; const fp32 Shoot::M2006_speed_PID[3] = {5, 0, 0.01};
const fp32 Shoot::M2006_angle_PID[3] = {15, 0.1, 0}; const fp32 Shoot::M2006_angle_PID[3] = {15, 0.1, 0};
#define TO_TOP 13.0f #define TO_TOP 10.0f
#define TO_BOTTOM 6.0f #define TO_BOTTOM 6.0f
#define INIT_POS -120 #define INIT_POS -130
#define TOP_POS -211 #define TOP_POS -211
#define BOTTOM_POS 0 #define BOTTOM_POS 0
#define WAIT_POS -170
#define CHANEGE_POS -205
#define GO_ERROR 1.0f #define GO_ERROR 1.0f
#define Tigger_DO -10 #define Tigger_DO 0
#define Tigger_ZERO 140 #define Tigger_ZERO 120
#define Tigger_ERROR 3 #define Tigger_ERROR 3
float knob_increment; float knob_increment;
double last_distance = 4.0f; // 4米做测试吧 double last_distance = 4.0f; // 4米做测试吧
double last_pass = 4.0f; // 4米做测试吧
Shoot::Shoot() Shoot::Shoot()
{ {
@ -74,7 +71,6 @@ Shoot::Shoot()
currentState = SHOOT_IDLE; currentState = SHOOT_IDLE;
LowPassFilter2p_Init(&distance_filter, 500.0f, 80.0f); // 给distance 做滤波 LowPassFilter2p_Init(&distance_filter, 500.0f, 80.0f); // 给distance 做滤波
LowPassFilter2p_Init(&pass_filter, 500.0f, 80.0f); // 给distance 做滤波
} }
void Shoot::trigger_control() void Shoot::trigger_control()
@ -86,27 +82,14 @@ void Shoot::trigger_control()
CAN_cmd_200(result, 0, 0, 0, &hcan1); CAN_cmd_200(result, 0, 0, 0, &hcan1);
} }
//好使老拟合
// float shoot_fitting(float x)
// {
// return 0.67076341f * x * x + 20.212423f * x + -154.53966f + 1.0f;
// }
// float shoot_fitting(float x)
// {
// return 1.4255807f * x * x + 12.138447f * x + -136.35306f;
// }
float shoot_fitting(float x) float shoot_fitting(float x)
{ {
return 1.2143736f * x * x + 14.733786f * x + -133.3627f; return 0.2006334f * x * x + 25.788123f * x + -169.32157 + 3.8f;
} }
float pass_fitting(float x) float pass_fitting(float x)
{ {
return 0.36807548f * x * x + 25.002169f * x + -199.2727f; return 1.1790172f * x * x + 15.983755f * x + -172.04664f + 1.6f;
} }
void Shoot::distanceGet(const NUC_t &nuc_v) void Shoot::distanceGet(const NUC_t &nuc_v)
@ -117,13 +100,8 @@ void Shoot::distanceGet(const NUC_t &nuc_v)
last_distance = LowPassFilter2p_Apply(&distance_filter, nuc_v.vision.x); last_distance = LowPassFilter2p_Apply(&distance_filter, nuc_v.vision.x);
} }
if(nuc_v.vision.y >= 0.0f && nuc_v.vision.y <= 7.5f)
{
last_pass = LowPassFilter2p_Apply(&pass_filter, nuc_v.vision.y);
}
// 否则不更新,保持上一次的值 // 否则不更新,保持上一次的值
distance = last_distance; distance = last_distance;
pass_distance =last_pass;
} }
int Shoot::GO_SendData(float pos, float limit) int Shoot::GO_SendData(float pos, float limit)
@ -171,10 +149,6 @@ int Shoot::GO_SendData(float pos, float limit)
// sw[5] 👆 200 👇1800 // sw[5] 👆 200 👇1800
// 左旋 sw[7] 200 --1800 // 左旋 sw[7] 200 --1800
float ws=-5.0f;
float and1=0.0f;
void Shoot::rc_mode() void Shoot::rc_mode()
{ {
// 底部光电检测假设0为到位1为未到位根据实际硬件调整 // 底部光电检测假设0为到位1为未到位根据实际硬件调整
@ -226,44 +200,22 @@ void Shoot::rc_mode()
{ {
ready_key = DEFENSE; ready_key = DEFENSE;
} }
//400--640为1 730--860为2 900到1200为3档中间 1300--1500为4
if(rc_ctrl.sw[7]<=300)
{
and1=0.0f;
}
if(rc_ctrl.sw[7]>=400&&rc_ctrl.sw[7]<=640)
{
and1=-2.0f;
}
if(rc_ctrl.sw[7]>=730&&rc_ctrl.sw[7]<=860)
{
and1=-1.0f;
}
if(rc_ctrl.sw[7]>=900&&rc_ctrl.sw[7]<=1200)
{
and1=0.0f;
}
if(rc_ctrl.sw[7]>=1300&&rc_ctrl.sw[7]<=1500)
{
and1=1.0f;
}
// // 旋钮映射部分不变 // 旋钮映射部分不变
// const int knob_min = 200; const int knob_min = 200;
// const int knob_max = 1800; const int knob_max = 1800;
// const float map_min = 130.0f; const float map_min = 130.0f;
// const float map_max = -60.0f; const float map_max = -60.0f;
// int current_knob_value = rc_ctrl.sw[7]; int current_knob_value = rc_ctrl.sw[7];
// if (current_knob_value < knob_min) if (current_knob_value < knob_min)
// current_knob_value = knob_min; current_knob_value = knob_min;
// if (current_knob_value > knob_max) if (current_knob_value > knob_max)
// current_knob_value = knob_max; current_knob_value = knob_max;
// knob_increment = map_min + (map_max - map_min) * (current_knob_value - knob_min) / (knob_max - knob_min); knob_increment = map_min + (map_max - map_min) * (current_knob_value - knob_min) / (knob_max - knob_min);
} }
#if ONE_CONTROL == 0 #if ONE_CONTROL == 0
void Shoot::shoot_control() void Shoot::shoot_control()
{ {
@ -273,14 +225,8 @@ void Shoot::shoot_control()
switch (mode_key) switch (mode_key)
{ {
case VSION: case VSION:
//fire_pos = distance; // 视觉拟合的力 fire_pos = distance; // 视觉拟合的力
if(distance<=3.1f) // fire_pos =shoot_fitting(test_distance);
{
ws=-8.0f;
}
fire_pos =shoot_fitting(distance)+and1+ws;
//fire_pos = INIT_POS + knob_increment; // 根据旋钮值调整发射位置
switch (rc_key) switch (rc_key)
{ {
case DOWN1: case DOWN1:
@ -320,8 +266,8 @@ void Shoot::shoot_control()
break; break;
case PASS: case PASS:
// 实时可调蓄力位置 // 实时可调蓄力位置
//fire_pos = INIT_POS + knob_increment; // 根据旋钮值调整发射位置 fire_pos = INIT_POS + knob_increment; // 根据旋钮值调整发射位置
fire_pos =pass_fitting(6.9f);
switch (rc_key) switch (rc_key)
{ {
case DOWN1: case DOWN1:
@ -365,7 +311,7 @@ void Shoot::shoot_control()
break; break;
} }
abs_limit_min_max_fp(&go1.Pos, -210.0f, 8.0f); abs_limit_min_max_fp(&go1.Pos, -210.0f, 2.0f);
// 发送数据到蓄力电机 // 发送数据到蓄力电机
GO_SendData(go1.Pos, limit_speed); GO_SendData(go1.Pos, limit_speed);
@ -444,8 +390,6 @@ void Shoot::RemoveError()
#if ONE_CONTROL #if ONE_CONTROL
float and2=0;
void Shoot::shoot_control() void Shoot::shoot_control()
{ {
@ -460,9 +404,7 @@ void Shoot::shoot_control()
switch (mode_key) switch (mode_key)
{ {
case VSION: case VSION:
fire_pos = shoot_fitting(distance)+and1; fire_pos = shoot_fitting(distance); // 视觉拟合的力
//fire_pos = INIT_POS + knob_increment; // 根据旋钮值调整发射位置
switch (rc_key) switch (rc_key)
{ {
case MIDDLE1: case MIDDLE1:
@ -478,8 +420,8 @@ void Shoot::shoot_control()
if (feedback.fd_gopos >= fire_pos - GO_ERROR && feedback.fd_gopos <= fire_pos + GO_ERROR) if (feedback.fd_gopos >= fire_pos - GO_ERROR && feedback.fd_gopos <= fire_pos + GO_ERROR)
{ {
shoot_wait = 1; shoot_wait = 1;
//BSP_Buzzer_Start(); BSP_Buzzer_Start();
//BSP_Buzzer_Set(1, 500); BSP_Buzzer_Set(1, 500);
} }
} }
@ -492,7 +434,7 @@ void Shoot::shoot_control()
if (feedback.fd_tpos >= Tigger_ZERO - 20) if (feedback.fd_tpos >= Tigger_ZERO - 20)
{ {
//BSP_Buzzer_Stop(); BSP_Buzzer_Stop();
currentState = SHOOT_IDLE; currentState = SHOOT_IDLE;
osThreadFlagsClear(EXTEND_OK); osThreadFlagsClear(EXTEND_OK);
osThreadFlagsClear(READY_TELL); // 蓄力标志位 osThreadFlagsClear(READY_TELL); // 蓄力标志位
@ -516,10 +458,11 @@ void Shoot::shoot_control()
switch (rc_key) switch (rc_key)
{ {
case MIDDLE1: case MIDDLE1:
fire_pos = shoot_fitting(distance)+and1; fire_pos = pass_fitting(distance);
if ((shoot_thread & READY_TELL) && !(shoot_thread & EXTEND_OK)) if ((shoot_thread & READY_TELL) && !(shoot_thread & EXTEND_OK))
{ {
ball_receive(); // 只收到READY_TELL且未收到EXTEND_OK时顶部蓄力流程
ball_receive(); // ball_receive内部写go1.Pos
} }
else if (shoot_thread & EXTEND_OK) else if (shoot_thread & EXTEND_OK)
{ {
@ -530,8 +473,8 @@ void Shoot::shoot_control()
if (feedback.fd_gopos >= fire_pos - GO_ERROR && feedback.fd_gopos <= fire_pos + GO_ERROR) if (feedback.fd_gopos >= fire_pos - GO_ERROR && feedback.fd_gopos <= fire_pos + GO_ERROR)
{ {
shoot_wait = 1; shoot_wait = 1;
// BSP_Buzzer_Start(); BSP_Buzzer_Start();
// BSP_Buzzer_Set(1, 500); BSP_Buzzer_Set(1, 500);
} }
} }
// 没收到READY_TELL不做任何蓄力 // 没收到READY_TELL不做任何蓄力
@ -546,7 +489,7 @@ void Shoot::shoot_control()
if (feedback.fd_tpos >= Tigger_ZERO - 20) if (feedback.fd_tpos >= Tigger_ZERO - 20)
{ {
//BSP_Buzzer_Stop(); BSP_Buzzer_Stop();
currentState = SHOOT_IDLE; currentState = SHOOT_IDLE;
osThreadFlagsClear(EXTEND_OK); osThreadFlagsClear(EXTEND_OK);
osThreadFlagsClear(READY_TELL); // 蓄力标志位 osThreadFlagsClear(READY_TELL); // 蓄力标志位
@ -572,28 +515,10 @@ void Shoot::shoot_control()
} }
else if (ready_key == DEFENSE) else if (ready_key == DEFENSE)
{ {
control_pos = TOP_POS - 2.0f; //-209
control_pos = WAIT_POS; //-209
go1.Pos = control_pos; go1.Pos = control_pos;
limit_speed = TO_TOP; // 快速上去 limit_speed = TO_TOP; // 快速上去
if(feedback.fd_gopos < WAIT_POS +2.0f) t_posSet = Tigger_ZERO; // 扳机松开
{
t_posSet = Tigger_ZERO; // 扳机松开
//osThreadFlagsSet(task_struct.thread.ball, DEF_READY);
// 只在READY_TELL未置位时发送防止重复
if ((osThreadFlagsGet() & DEF_READY) == 0)
{
osThreadFlagsSet(task_struct.thread.ball, DEF_READY);
}
}
osThreadFlagsClear(EXTEND_OK);
osThreadFlagsClear(READY_TELL); // 蓄力标志位
osThreadFlagsClear(HANDING_FINISH);
currentState = SHOOT_IDLE;
} }
else else
{ {
@ -608,7 +533,6 @@ void Shoot::shoot_control()
trigger_control(); trigger_control();
} }
// 配合运球到发射 // 配合运球到发射
void Shoot ::ball_receive() void Shoot ::ball_receive()
{ {
@ -618,17 +542,11 @@ void Shoot ::ball_receive()
// 初始状态:钩子移动到顶部,钩住拉簧 // 初始状态:钩子移动到顶部,钩住拉簧
if (shoot_thread & READY_TELL) // 如果收到等待通知 if (shoot_thread & READY_TELL) // 如果收到等待通知
{ {
control_pos = TOP_POS;
limit_speed = TO_TOP; // 快速上去
t_posSet = Tigger_ZERO; t_posSet = Tigger_ZERO;
if(trigger_Motor->total_angle > Tigger_ZERO-5 )
{
control_pos = TOP_POS;
limit_speed = TO_TOP; // 快速上去
}
if (feedback.fd_gopos < -209) if (feedback.fd_gopos < -209)
{ {
currentState = GO_TOP; // 切换到准备发射状态 currentState = GO_TOP; // 切换到准备发射状态
} }
} }
@ -644,7 +562,7 @@ void Shoot ::ball_receive()
break; break;
case BAKC: case BAKC:
control_pos = BOTTOM_POS; control_pos = BOTTOM_POS;
limit_speed = 8.0f; // 慢速下来 limit_speed = TO_BOTTOM; // 慢速下来
if (feedback.fd_gopos >= BOTTOM_POS - 1.0f && feedback.fd_gopos <= BOTTOM_POS + 1.0f) if (feedback.fd_gopos >= BOTTOM_POS - 1.0f && feedback.fd_gopos <= BOTTOM_POS + 1.0f)
{ {
@ -673,7 +591,7 @@ void Shoot::RemoveError()
control_pos = INIT_POS; control_pos = INIT_POS;
BSP_Buzzer_Stop(); BSP_Buzzer_Stop();
} }
limit_speed = 5.0f; // 慢慢送上去 limit_speed = 3.0f; // 慢慢送上去
go1.Pos = control_pos; go1.Pos = control_pos;
} }

View File

@ -87,7 +87,6 @@ public:
//滤波器 //滤波器
LowPassFilter2p_t distance_filter; // 用于滤波视觉距离 LowPassFilter2p_t distance_filter; // 用于滤波视觉距离
LowPassFilter2p_t pass_filter;
//==========================公共变量========================== //==========================公共变量==========================
int16_t rc_key; //遥控器按键 int16_t rc_key; //遥控器按键
@ -98,7 +97,6 @@ public:
volatile uint32_t shoot_thread;//接收传回的线程通知 volatile uint32_t shoot_thread;//接收传回的线程通知
fp32 distance; //视觉距离 fp32 distance; //视觉距离
fp32 pass_distance; //视觉距离
private: private:
//扳机2006 //扳机2006

View File

@ -8,7 +8,11 @@
#include "vofa.h" #include "vofa.h"
extern RC_ctrl_t rc_ctrl; extern RC_ctrl_t rc_ctrl;
Ball ball; Ball ball;
//float vofa[8];
//检查光电
int abc=0;
int aaaa=146;
extern int speedm; extern int speedm;
@ -18,7 +22,7 @@ void FunctionBall(void *argument)
const uint32_t delay_tick = osKernelGetTickFreq() / TASK_FREQ_BALL; const uint32_t delay_tick = osKernelGetTickFreq() / TASK_FREQ_BALL;
osDelay(6000);//等待极致控制板启动 osDelay(6000);//等待极致控制板启动
XiaomiWait_init(1,&hcan2); //小米电机初始化 XiaomiWait_init(1,&hcan2); //小米电机初始化
uint32_t tick = osKernelGetTickCount(); uint32_t tick = osKernelGetTickCount();
@ -28,9 +32,16 @@ void FunctionBall(void *argument)
#ifdef DEBUG #ifdef DEBUG
task_struct.stack_water_mark.ball = osThreadGetStackSpace(osThreadGetId()); task_struct.stack_water_mark.ball = osThreadGetStackSpace(osThreadGetId());
#endif #endif
ball.rc_mode(); // 遥控器模式
//abc=HAL_GPIO_ReadPin(up_ball_GPIO_Port, up_ball_Pin);
abc=HAL_GPIO_ReadPin(BALL_GPIO_Port, BALL_Pin); // 0为到位
ball.rc_mode(); // 遥控器模式
ball.ball_control(); // 控制球的动作 ball.ball_control(); // 控制球的动作
// ball.xiaomi.position = aaaa;
// CAN_XiaoMi(1,&ball.xiaomi,&hcan2);
tick += delay_tick; /* 计算下一个唤醒时刻 */ tick += delay_tick; /* 计算下一个唤醒时刻 */
osDelayUntil(tick); osDelayUntil(tick);

View File

@ -26,7 +26,7 @@ void FunctionCan(void *argument)
task_struct.stack_water_mark.can = osThreadGetStackSpace(osThreadGetId()); task_struct.stack_water_mark.can = osThreadGetStackSpace(osThreadGetId());
#endif #endif
//waitNewDji(); waitNewDji();
djiMotorEncode(); djiMotorEncode();
can2MotorEncode(); can2MotorEncode();

47
User/task/gimbalTask.cpp Normal file
View File

@ -0,0 +1,47 @@
#include "TopDefine.h"
#include "FreeRTOS.h"
#include "userTask.h"
#include <cmsis_os2.h>
#include "gimbalTask.hpp"
#include "gimbal.hpp"
#include "main.h"
#include "remote_control.h"
#include "nuc.h"
Gimbal gimbal;
// NUC_t nucData; // 用于存储从队列接收的数据
extern RC_ctrl_t rc_ctrl;
int cnt1=0;
void FunctionGimbal(void *argument)
{
(void)argument; /* 未使用argument消除警告 */
const uint32_t delay_tick = osKernelGetTickFreq() / TASK_FREQ_CTRL_GIMBAL;
HAL_GPIO_WritePin(LED_G_GPIO_Port,LED_G_Pin,GPIO_PIN_SET);
uint32_t tick = osKernelGetTickCount();
while(1)
{
#ifdef DEBUG
task_struct.stack_water_mark.gimbal = osThreadGetStackSpace(osThreadGetId());
#endif
//cnt1++;
// gimbal.gimbalFlow();
// 从消息队列接收视觉数据
// if (osMessageQueueGet(task_struct.msgq.nuc, &nucData, NULL, 0) == osOK)
// {
// // 使用接收到的视觉数据调整云台
// //gimbal.gimbalVision(nucData);
// }
osDelay(1);
tick += delay_tick; /* 计算下一个唤醒时刻 */
osDelayUntil(tick);
}
}

5
User/task/gimbalTask.hpp Normal file
View File

@ -0,0 +1,5 @@
#ifndef GIMBALTASK_HPP
#define GIMBALTASK_HPP
#endif

View File

@ -10,7 +10,7 @@ extern RC_ctrl_t rc_ctrl;
Shoot shoot; Shoot shoot;
NUC_t nucData; // 自瞄 NUC_t nucData; // 自瞄
int aaaxxx=0;
void FunctionShoot(void *argument) void FunctionShoot(void *argument)
{ {
@ -35,6 +35,13 @@ while(1)
shoot.shoot_control(); shoot.shoot_control();
// shoot.t_posSet=aaaxxx;
// shoot.trigger_control();
// shoot.GO_SendData(goangle,5);
// shoot.shoot_control();
// shoot.t_posSet=goangle;
// shoot.trigger_control();
tick += delay_tick; /* 计算下一个唤醒时刻 */ tick += delay_tick; /* 计算下一个唤醒时刻 */
osDelayUntil(tick); osDelayUntil(tick);

View File

@ -14,7 +14,7 @@ extern "C" {
/* 所有任务都要define一个“任务运行频率”和“初始化延时” */ /* 所有任务都要define一个“任务运行频率”和“初始化延时” */
#define TASK_FREQ_SHOOT (500u) #define TASK_FREQ_SHOOT (500u)
#define TASK_FREQ_CAN (500u) #define TASK_FREQ_CAN (1500u)
#define TASK_FREQ_AI (500u) #define TASK_FREQ_AI (500u)
#define TASK_FREQ_BALL (500u) #define TASK_FREQ_BALL (500u)