完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
主函数
#include "gui.h" #include "stm32f4xx.h" #include "delay.h" #include "led.h" #include "usart.h" #include "ucos_ii.h" #include "pwm.h" #include "control.h" #include "app_cfg.h" #include "bsp.h" #include "24l01.h" #include "spi.h" //Task Stack Setting #define APP_TASK_START_STK_SIZE 512 #define APP_LED1_STK_SIZE 1024 #define APP_NRF24L01_STK_SIZE 1024 #define APP_LED3_STK_SIZE 1024 //Task Priority #define APP_TASK_START_PRIO 3 #define APP_LED1_PRIO 5 #define APP_NRF24L01_PRIO 4 #define APP_LED3_PRIO 7 //Stack Size setting static OS_STK App_TaskStartStk[APP_TASK_START_STK_SIZE]; static OS_STK App_LED1Stk[APP_LED1_STK_SIZE]; static OS_STK App_NRF24L01Stk[APP_NRF24L01_STK_SIZE]; static OS_STK App_LED3Stk[APP_LED3_STK_SIZE]; //Function Statement static void App_TaskStart(void *p_arg); static void App_Task_LED1(void *p_arg); static void App_Task_NRF24L01(void *p_arg); static void App_Task_ACTION(void *p_arg); u8 tmp_buf[33];//data received buffer u8 cmd_last = 0xff; static u8 cmd = 0; //command of action int main(void) { OSInit(); //uC/OS-II init TIM_Init(); NRF24L01_Init(); // Stand_Up(); LED_Init(); //LED Init while(NRF24L01_Check()) { LED1(On); OSTimeDlyHMSM(0,0,0,50); LED1(Off); OSTimeDlyHMSM(0,0,0,50); } RX_Mode(); OSTaskCreate(App_TaskStart,(void*)0,(OS_STK*)&App_TaskStartStk[APP_TASK_START_STK_SIZE-1],APP_TASK_START_PRIO); OSStart(); return (0); } static void App_TaskStart (void *p_arg)//construct new task in this function { OS_CPU_SysTickInit(); //Init System Clock BSP_Init(); OSTaskCreate(App_Task_LED1,(void*)0,(OS_STK*)&App_LED1Stk[APP_LED1_STK_SIZE-1],APP_LED1_PRIO); OSTaskCreate(App_Task_NRF24L01,(void*)0,(OS_STK*)&App_NRF24L01Stk[APP_NRF24L01_STK_SIZE-1],APP_NRF24L01_PRIO); OSTaskCreate(App_Task_ACTION,(void*)0,(OS_STK*)&App_LED3Stk[APP_LED3_STK_SIZE-1],APP_LED3_PRIO); OSTaskSuspend(APP_TASK_START_PRIO); //suspend but not delete } static void App_Task_LED1 (void *p_arg)//construct new task in this function { while (1) { LED1(On); LED0(Off); OSTimeDlyHMSM(0,0,0,50); LED1(Off); LED0(On); OSTimeDlyHMSM(0,0,0,50); } } static void App_Task_NRF24L01 (void *p_arg)//construct new task in this function { while (1) { if(NRF24L01_RxPacket(tmp_buf)==0) { LED2(On); OSTimeDlyHMSM(0,0,0,30); LED2(Off); OSTimeDlyHMSM(0,0,0,30); }else OSTimeDlyHMSM(0,0,0,1); if((tmp_buf[0] == tmp_buf[1])&&(tmp_buf[0] == tmp_buf[2])) { cmd = tmp_buf[0]; } } } static void App_Task_ACTION (void *p_arg)//construct new task in this function { while (1) { if(cmd != cmd_last) { cmd_last = cmd; switch ( cmd ) { case '1':Stand_Up(ACTION_DELAY);break; case '2':Stamp('2',&cmd);break; case '3':Sit_Down(ACTION_DELAY);break; case '4':Go_straight('4',&cmd);break; case '5':LED3(On); break; case '6':Turn('6',&cmd); break; default :break; } } } } 个人动作 void Stand_Up(int delay_time) { int pwm_tmp = 0; int pwm_tmp2 = 0; Open_All_TIM(); //Open all timer TIM_SetCompare4(TIM1,pwm_init[2]); //2-3-2 TIM_SetCompare4(TIM2,pwm_init[18]); //4-3-18 TIM_SetCompare1(TIM4,pwm_init[23]); //6-3-23 TIM_SetCompare4(TIM4,pwm_init[19]); //1-3-19 TIM_SetCompare2(TIM5,pwm_init[16]); //3-3-16 TIM_SetCompare3(TIM5,pwm_init[22]); //5-3-22 for (;pwm_tmp<=STAND_HIGHT;) //150 efect the height of stand { // delay_ms(ACTION_DELAY); OSTimeDlyHMSM(0,0,0,delay_time);//ÑÓʱ£¬²ÎÊý£ºÊ±£¬·Ö£¬Ã룬΢Ãë TIM_SetCompare3(TIM2,pwm_init[15] - STAND_HIGHT + pwm_tmp); //3-2-15 TIM_SetCompare3(TIM4,pwm_init[20] - STAND_HIGHT + pwm_tmp); //1-2-20 TIM_SetCompare1(TIM5,pwm_init[6] - STAND_HIGHT + pwm_tmp); //2-2-6 TIM_SetCompare4(TIM3,pwm_init[7] + STAND_HIGHT - pwm_tmp); //4-2-7 TIM_SetCompare2(TIM4,pwm_init[24] + STAND_HIGHT - pwm_tmp); //6-2-24 TIM_SetCompare4(TIM5,pwm_init[21] + STAND_HIGHT - pwm_tmp); //5-2-21 TIM_SetCompare1(TIM1,pwm_init[1] - SHRINK_DEGREE + pwm_tmp2); //1-1-1 TIM_SetCompare2(TIM1,pwm_init[5] - SHRINK_DEGREE + pwm_tmp2); //2-1-5 TIM_SetCompare3(TIM1,pwm_init[9] - SHRINK_DEGREE + pwm_tmp2); //3-1-9 TIM_SetCompare1(TIM3,pwm_init[12] + SHRINK_DEGREE - pwm_tmp2); //4-1-12 TIM_SetCompare2(TIM3,pwm_init[8] + SHRINK_DEGREE - pwm_tmp2); //5-1-8 TIM_SetCompare3(TIM3,pwm_init[4] + SHRINK_DEGREE - pwm_tmp2); //6-1-4 pwm_tmp += ACTION_SPEED; pwm_tmp2 += SHRINK_SPEED; } } void Stamp(u8 Com_Num,u8 * Input_num) { Pace_135_Motor2(0,150,STAMP_DELAY); //UP while(Com_Num == *Input_num) { Pace_135_Motor2(150,-150,STAMP_DELAY); //DOWM Pace_246_Motor2(0,150,STAMP_DELAY); //UP Pace_246_Motor2(150,-150,STAMP_DELAY); //DOWM Pace_135_Motor2(0,150,STAMP_DELAY); //UP } Pace_135_Motor2(150,-150,STAMP_DELAY); //DOWM } void Sit_Down(int delay_time) { int pwm_tmp = 0; //motor 2 int pwm_tmp2 = 0; //motor 1 for (;pwm_tmp<=STAND_HIGHT;) //150 efect the height of stand { // delay_ms(ACTION_DELAY); OSTimeDlyHMSM(0,0,0,delay_time);//ÑÓʱ£¬²ÎÊý£ºÊ±£¬·Ö£¬Ã룬΢Ãë TIM_SetCompare3(TIM2,pwm_init[15] - pwm_tmp); //3-2-15 TIM_SetCompare3(TIM4,pwm_init[20] - pwm_tmp); //1-2-20 TIM_SetCompare1(TIM5,pwm_init[6] - pwm_tmp); //2-2-6 TIM_SetCompare4(TIM3,pwm_init[7] + pwm_tmp); //4-2-7 TIM_SetCompare2(TIM4,pwm_init[24] + pwm_tmp); //6-2-24 TIM_SetCompare4(TIM5,pwm_init[21] + pwm_tmp); //5-2-21 TIM_SetCompare1(TIM1,pwm_init[1] - pwm_tmp2); //1-1-1 TIM_SetCompare2(TIM1,pwm_init[5] - pwm_tmp2); //2-1-5 TIM_SetCompare3(TIM1,pwm_init[9] - pwm_tmp2); //3-1-9 TIM_SetCompare1(TIM3,pwm_init[12] + pwm_tmp2); //4-1-12 TIM_SetCompare2(TIM3,pwm_init[8] + pwm_tmp2); //5-1-8 TIM_SetCompare3(TIM3,pwm_init[4] + pwm_tmp2); //6-1-4 pwm_tmp += ACTION_SPEED; pwm_tmp2 += SHRINK_SPEED; } OSTimeDlyHMSM(0,0,0,100);//ÑÓʱ£¬²ÎÊý£ºÊ±£¬·Ö£¬Ã룬΢Ãë Close_All_TIM(); //close all timer } void Go_straight(u8 Com_Num,u8 * Input_num) { Pace_135_Motor2(0,100,STRAIGHT_DELAY); //UP while(Com_Num == *Input_num) { Pace_246_Motor3(0,80,STRAIGHT_DELAY); //FRONT Pace_135_Motor2(100,-100,STRAIGHT_DELAY); //DOWM Pace_246_Motor2(0,100,STRAIGHT_DELAY); //UP Pace_246_Motor3(80,-80,STRAIGHT_DELAY); //RETURN Pace_135_Motor3(0,80,STRAIGHT_DELAY); //FRONT Pace_246_Motor2(100,-100,STRAIGHT_DELAY); //DOWM Pace_135_Motor2(0,100,STRAIGHT_DELAY); //UP Pace_135_Motor3(80,-80,STRAIGHT_DELAY); //RETURN } Pace_135_Motor2(100,-100,STRAIGHT_DELAY); //DOWM } void Turn(u8 Com_Num,u8 * Input_num) { while(Com_Num == *Input_num) { Pace_135_246_Motor3(0,0,70,TURN_DELAY); //turn body left Pace_246_Motor2(0,100,TURN_DELAY); //UP Pace_246_Motor3_Different(70,-70,TURN_DELAY); //2,4,6 leg return Pace_246_Motor2(100,-100,TURN_DELAY); //DOWM Pace_135_Motor2(0,100,TURN_DELAY); //UP Pace_135_Motor3_Different(70,-70,TURN_DELAY); //1,3,5 leg return Pace_135_Motor2(100,-100,TURN_DELAY); //DOWM } } 驱动 void TIM_Init(void) { TIM1_Init(); TIM2_Init(); TIM3_Init(); TIM4_Init(); TIM5_Init(); } |
|
|
|
只有小组成员才能发言,加入小组>>
调试STM32H750的FMC总线读写PSRAM遇到的问题求解?
1559 浏览 1 评论
X-NUCLEO-IHM08M1板文档中输出电流为15Arms,15Arms是怎么得出来的呢?
1500 浏览 1 评论
930 浏览 2 评论
STM32F030F4 HSI时钟温度测试过不去是怎么回事?
662 浏览 2 评论
ST25R3916能否对ISO15693的标签芯片进行分区域写密码?
1551 浏览 2 评论
1847浏览 9评论
STM32仿真器是选择ST-LINK还是选择J-LINK?各有什么优势啊?
607浏览 4评论
STM32F0_TIM2输出pwm2后OLED变暗或者系统重启是怎么回事?
503浏览 3评论
507浏览 3评论
stm32cubemx生成mdk-arm v4项目文件无法打开是什么原因导致的?
487浏览 3评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-9 12:30 , Processed in 0.736492 second(s), Total 78, Slave 62 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号