赞
踩
由于前边已经用MSP430做过一遍该赛题了,这里就不再重复叙述赛题内容。
也是应各网友需求,用该MSP432主控板再次完成该任务。
Tips: 本篇与上次用MSP430的做法大不一样,其中视觉上,上次采用的模板匹配,本次采用的神经网络数字训练,其各有优势,这里不便讨论,其次在巡线逻辑上,上次采用的是7路灰度,本次采用的12路灰度,逻辑性更强,且在转向时不再使用延迟转弯,因为延迟受电压影响较大,具体实现请见下方描述,然后在药物的装载上,上次采用红外对管检测物品的装卸,本次使用碰撞器模拟,更为方便。
打开OpenMV IDE,在菜单栏选择 “工具” —> “数据集编辑器” —> “新数据集”,创建好数据集后在左侧的菜单项中选择新建文件夹用于存储每个标签下的照片,即新建八个文件夹,依次在每个文件夹中采集照片。
依次在每个文件夹中采集对应图片
将拍出来的数据放置EDGE IMPULSE训练,这样训练出来的效果远比用手机拍出来的效果好很多哦。注意在拍照过程中尽量让背景更简单单纯一点,不然训练后的结果可能部分数字会受背景的影响。
Tips: 每张照片建议在100张左右,对易混淆的数字加量采集,如数字5和数字6可以加大到150张左右,且在采集过程中多选择不同方位进行拍照,在标签画框时只用框出中间数字即可,四周有加黑色框的尽量不要将框也标记进去,因为这样会影响训练效果。
视觉这块就比较简单易行了,将训练好的模型文件导入OpenMV中打开,即可准确识别数字及相应坐标,所以操作空间很小,只需要根据单片机发过来的指令完成指定动作再将数据返回到单片机即可,总共分为4次识别,第一次是在开始装药品时识别目的病房,第二次是在路口二处进行识别,第三次是在路口三,第四次是在路口四或路口五,所以最多也只需要进行四次识别操作,相对是非常简单的。
那怎么判断是否识别准确呢?可以通过OpenMV板载的LED灯进行闪烁提示,例 若识别到数字2则LED灯闪烁俩次;或者也可以通过发送到单片机的数据进行判断,将其显示在OLED显示屏上。
具体如下:
while(True): clock.tick() img = sensor.snapshot() if uart.any(): data=uart.readline().decode().strip() #转化为字符串接收 if data=='8': first=0 second=0 three=0 four=0 second_flag=1 three_flag=1 four_flag=1 x=0 flag=0 data='0' if first==0: first=get_first_num(img) if first: second_flag=0 print(first) send_num(first) #led_show(first) if second_flag==0: if data=='1': print('ok1') second=get_num(img) if second==0: second_flag=1 three_flag=0 data='0' print("go") uart.write("F") elif second<=100: second_flag=1 three_flag=0 data='0' print(second) uart.write("L") elif second>100: second_flag=1 three_flag=0 data='0' print(second) uart.write("R") if three_flag==0: if data=='2': print('ok2') three=get_num(img) if three<=100: three_flag=1 four_flag=0 data='0' print(three) uart.write("l") elif three>100: three_flag=1 four_flag=0 data='0' print(three) uart.write("r") if four_flag==0: if data=='3': print('ok3') four=get_num(img) if four<=100: four_flag=1 data='0' print(four) uart.write("a") elif four>100: four_flag=1 data='0' print(four) uart.write("b")
这里我采用的是12路灰度传感器,其中中间6个探头用来完成直行动作,也就是该6个探头只用作红白色处理。
具体如下:
void XunXian(void) { if( l4==0 && l5==0 && l6==1 && l7==1 && l8==0 && l9==0 ) { Forward(); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1, 400); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_2, 380); } //左边 else if( l4==0 && l5==1 && l6==1 && l7==0 && l8==0 && l9==0 ) { Forward(); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1, 350); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_2, 380); } else if( l4==1 && l5==1 && l6==0 && l7==0 && l8==0 && l9==0 ) { Forward(); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1, 250); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_2, 380); } else if( l4==1 && l5==0 && l6==0 && l7==0 && l8==0 && l9==0 ) { Forward(); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1, 100); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_2, 380); } //右边 else if( l4==0 && l5==0 && l6==0 && l7==1 && l8==1 && l9==0 ) { Forward(); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1, 400); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_2, 330); } else if( l4==0 && l5==0 && l6==0 && l7==0 && l8==1 && l9==1 ) { Forward(); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1, 400); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_2, 230); } else if( l4==0 && l5==0 && l6==0 && l7==0 && l8==0 && l9==1 ) { Forward(); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1, 400); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_2, 100); } }
本次任务中的转向均为循环转向,也就是在执行转向操作时会一直向着某个方向转,直至某个探头的状态发生变化才退出循环继续执行巡线操作,这样就不再因为延迟转向受电压影响了。
具体如下:
//左转 if( (l5==1&&l6==1&&l7==1&&l8==1) && LR_flag==4) { delay_ms(100); Left(); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1, 300); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_2, 280); delay_ms(300); while(1) { l7=gpio_get(GPIO_PORT_P6, GPIO_PIN3); if(l7==1) break; } } //右转 else if( (l5==1&&l6==1&&l7==1&&l8==1) && LR_flag==5) { delay_ms(100); Right(); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1, 320); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_2, 280); delay_ms(350); while(1) { l6=gpio_get(GPIO_PORT_P9, GPIO_PIN3); if(l6==1) break; } }
周边4个探头用来执行停止动作,也就是该4个探头只用作黑白色处理(不受红色影响)。当其中某一个探头状态发生变化时,其执行停止指令,该指令也只会在停止点黑色虚线处被执行。
具体如下:
if((l1==1||l2==1||l11==1||l12==1) &&(over==1))
{
Stop();
MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1, 0);
MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_2, 0);
}
该赛图总共分为5个交叉路口,则我将该5个交叉路口封装为5个函数,每当要行驶到某个路口时执行相应的路口操作函数,例如路口一,该路口只对病房①和病房②有效,即可根据OpenMV识别返回到的数字可判断,如果是数字①和数字②,则执行路口一的执行函数,否则直接跳过路口一,直接执行路口二的执行函数,再根据路口二识别到的数字进行判断,如果有相应的数字则根据OpenMV返回的数字坐标进行左右转向判断,否则直接进入路口三再次进行数字识别,根据识别到的数字坐标判断左右转向,如果得到的是左转指令,则进入路口四做最后一次识别,否则进入路口五做最后一次是识别,根据最后一次识别到的数字坐标进入到最后的病房,随机按照原路径返回到药房。
路口于下图所示:
其中,路口一、二、三通过中间6个探头进行判断,当最中间的四个探头状态都发生变化是,则判定此时正处于路口处,路口四和路口五则需在中间6个探头的基础上外加旁边的俩个探头进行判断,因为是“T”型路口,若最左、右俩边的三个探头状态发生改变而对应边的状态并没有发生改变则判定此时正处于“T”型路口处。
原路径返回则是通过在每进行一次转向时会做一次记录,直至记录到成功将药品送到病房后,再依次按照记录的值进行路口转向,直至最外围4个探头状态发生变化,则判定成功返回到药房。
具体操作如下:
void Lukou1(void) { if(openmv_rxflag==1) { //去往1号病房的十字路口左转 if( (l5==1&&l6==1&&l7==1&&l8==1)&& (room1_flag==0)) { room1_flag=1; delay_ms(110); Left(); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1, 300); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_2, 280); delay_ms(300); while(1) { l7=gpio_get(GPIO_PORT_P6, GPIO_PIN3); if(l7==1) break; } stop_flag=1; } //1号病房回到药房的十字路口右转 else if( (l5==1&&l6==1&&l7==1&&l8==1) && (room1_flag==2)) { room1_flag=3; delay_ms(100); Right(); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1, 320); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_2, 280); delay_ms(350); while(1) { l6=gpio_get(GPIO_PORT_P9, GPIO_PIN3); if(l6==1) break; } over=1; } } if(openmv_rxflag==2) { //去往2号病房的十字路口右转 if( (l5==1&&l6==1&&l7==1&&l8==1) && (room2_flag==0)) { room2_flag=1; delay_ms(100); Right(); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1, 320); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_2, 280); delay_ms(350); while(1) { l6=gpio_get(GPIO_PORT_P9, GPIO_PIN3); if(l6==1) break; } stop_flag=1; } //2号病房回到药房的十字路口左转 else if( (l5==1&&l6==1&&l7==1&&l8==1) && (room2_flag==2)) { room2_flag=3; delay_ms(110); Left(); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1, 300); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_2, 280); delay_ms(300); while(1) { l7=gpio_get(GPIO_PORT_P6, GPIO_PIN3); if(l7==1) break; } over=1; } } //1、2号病房停在病房门口 if((l1==1||l2==1||l11==1||l12==1) && stop_flag==1) { stop_flag=2; Stop(); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1, 0); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_2, 0); room1_flag=2; room2_flag=2; button_flag=1; while(button_flag) { button_flag=gpio_get(GPIO_PORT_P7, GPIO_PIN7); } Back(); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1, 300); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_2, 280); delay_ms(500); Left(); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1, 300); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_2, 280); delay_ms(500); while(1) { l7=gpio_get(GPIO_PORT_P6, GPIO_PIN3); if(l7==1) break; } } //返回到药房门口 if((l1==1||l2==1||l11==1||l12==1) &&(over==1)) { Stop(); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1, 0); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_2, 0); TimerA1_Disable(); OLED_ShowString(30, 4, (uint8_t *)"T= S", 16); OLED_ShowNum(47,4,Timer,2,16); } } void Lukou2(void) { //接收到openmv发过来的左转标志 if( (l5==1&&l6==1&&l7==1&&l8==1) && LR_flag==1) { LR_flag=11; delay_ms(100); Left(); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1, 300); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_2, 280); delay_ms(300); while(1) { l7=gpio_get(GPIO_PORT_P6, GPIO_PIN3); if(l7==1) break; } stop_flag=1; room3_flag=1; } //接收到openmv发过来的右转标志 else if( (l5==1&&l6==1&&l7==1&&l8==1) && LR_flag==2) { LR_flag=22; delay_ms(100); Right(); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1, 320); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_2, 280); delay_ms(350); while(1) { l6=gpio_get(GPIO_PORT_P9, GPIO_PIN3); if(l6==1) break; } stop_flag=1; room4_flag=1; } //接收到openmv发过来的直行标志 else if( (l5==1&&l6==1&&l7==1&&l8==1) && LR_flag==3) { LR_flag=33; Forward(); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1, 400); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_2, 380); } else if( (l5==1&&l6==1&&l7==1&&l8==1) && (room3_flag==1)) { room3_flag=2; delay_ms(100); Right(); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1, 300); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_2, 280); delay_ms(300); while(1) { l6=gpio_get(GPIO_PORT_P9, GPIO_PIN3); if(l6==1) break; } } else if( (l5==1&&l6==1&&l7==1&&l8==1) && (room4_flag==1)) { room4_flag=2; delay_ms(100); Left(); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1, 300); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_2, 280); delay_ms(300); while(1) { l7=gpio_get(GPIO_PORT_P6, GPIO_PIN3); if(l7==1) break; } } else if( (l5==1&&l6==1&&l7==1&&l8==1) && (room3_flag==2||room4_flag==2)) { Forward(); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1, 400); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_2, 380); over=1; } //停在病房门口 if( (l1==1||l2==1||l11==1||l12==1) && stop_flag==1) { stop_flag=2; Stop(); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1, 0); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_2, 0); button_flag=1; while(button_flag) { button_flag=gpio_get(GPIO_PORT_P7, GPIO_PIN7); } Back(); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1, 300); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_2, 280); delay_ms(500); Left(); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1, 300); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_2, 280); delay_ms(500); while(1) { l7=gpio_get(GPIO_PORT_P6, GPIO_PIN3); if(l7==1) break; } } //返回到药房门口 else if((l1==1||l2==1||l11==1||l12==1) &&(over==1)) { Stop(); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1, 0); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_2, 0); TimerA1_Disable(); OLED_ShowString(30, 4, (uint8_t *)"T= S", 16); OLED_ShowNum(47,4,Timer,2,16); } } void Lukou3(void) { //接收到openmv发过来的左转标志 if( (l5==1&&l6==1&&l7==1&&l8==1) && LR_flag==4) { LR_flag=44; delay_ms(100); Left(); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1, 300); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_2, 280); delay_ms(300); while(1) { l7=gpio_get(GPIO_PORT_P6, GPIO_PIN3); if(l7==1) break; } } //接收到openmv发过来的右转标志 else if( (l5==1&&l6==1&&l7==1&&l8==1) && LR_flag==5) { LR_flag=55; delay_ms(100); Right(); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1, 320); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_2, 280); delay_ms(350); while(1) { l6=gpio_get(GPIO_PORT_P9, GPIO_PIN3); if(l6==1) break; } } } void Lukou4(void) { //接收到openmv发过来的左转标志 if( (l5==1&&l6==1&&l7==1&&l8==1) && LR_flag==7) { LR_flag=77; delay_ms(100); Left(); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1, 300); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_2, 280); delay_ms(300); while(1) { l7=gpio_get(GPIO_PORT_P6, GPIO_PIN3); if(l7==1) break; } stop_flag=1; } //接收到openmv发过来的右转标志 else if( (l5==1&&l6==1&&l7==1&&l8==1) && LR_flag==8) { LR_flag=88; delay_ms(100); Right(); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1, 320); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_2, 280); delay_ms(350); while(1) { l6=gpio_get(GPIO_PORT_P9, GPIO_PIN3); if(l6==1) break; } stop_flag=1; } else if( (l5==0&&l8==1&&l9==1&&l10==1) && LR_flag==77) { LR_flag=777; delay_ms(100); Right(); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1, 320); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_2, 280); delay_ms(350); while(1) { l6=gpio_get(GPIO_PORT_P9, GPIO_PIN3); if(l6==1) break; } } else if( (l5==0&&l8==1&&l9==1&&l10==1) && LR_flag==777) { LR_flag=7777; delay_ms(100); Right(); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1, 320); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_2, 280); delay_ms(350); while(1) { l6=gpio_get(GPIO_PORT_P9, GPIO_PIN3); if(l6==1) break; } } else if( (l3==1&&l4==1&&l5==1&&l8==0) && LR_flag==88) { LR_flag=888; delay_ms(100); Left(); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1, 300); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_2, 280); delay_ms(300); while(1) { l7=gpio_get(GPIO_PORT_P6, GPIO_PIN3); if(l7==1) break; } } else if( (l5==0&&l8==1&&l9==1&&l10==1) && LR_flag==888) { LR_flag=8888; delay_ms(100); Right(); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1, 320); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_2, 280); delay_ms(350); while(1) { l6=gpio_get(GPIO_PORT_P9, GPIO_PIN3); if(l6==1) break; } } else if( (l5==1&&l6==1&&l7==1&&l8==1) && ((LR_flag==7777)||(LR_flag==8888))) { over=1; Forward(); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1, 400); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_2, 380); } //停在病房门口 if( (l1==1||l2==1||l11==1||l12==1) && stop_flag==1) { stop_flag=2; Stop(); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1, 0); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_2, 0); button_flag=1; while(button_flag) { button_flag=gpio_get(GPIO_PORT_P7, GPIO_PIN7); } Back(); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1, 300); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_2, 280); delay_ms(500); Left(); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1, 300); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_2, 280); delay_ms(500); while(1) { l7=gpio_get(GPIO_PORT_P6, GPIO_PIN3); if(l7==1) break; } } //返回到药房门口 else if((l1==1||l2==1||l11==1||l12==1) &&(over==1)) { Stop(); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1, 0); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_2, 0); TimerA1_Disable(); OLED_ShowString(30, 4, (uint8_t *)"T= S", 16); OLED_ShowNum(47,4,Timer,2,16); } } void Lukou5(void) { //接收到openmv发过来的左转标志 if( (l5==1&&l6==1&&l7==1&&l8==1) && LR_flag==7) { LR_flag=77; delay_ms(100); Left(); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1, 300); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_2, 280); delay_ms(300); while(1) { l7=gpio_get(GPIO_PORT_P6, GPIO_PIN3); if(l7==1) break; } stop_flag=1; } //接收到openmv发过来的右转标志 else if( (l5==1&&l6==1&&l7==1&&l8==1) && LR_flag==8) { LR_flag=88; delay_ms(100); Right(); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1, 320); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_2, 280); delay_ms(350); while(1) { l6=gpio_get(GPIO_PORT_P9, GPIO_PIN3); if(l6==1) break; } stop_flag=1; } else if( (l5==0&&l8==1&&l9==1&&l10==1) && LR_flag==77) { LR_flag=777; delay_ms(100); Right(); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1, 320); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_2, 280); delay_ms(350); while(1) { l6=gpio_get(GPIO_PORT_P9, GPIO_PIN3); if(l6==1) break; } } else if( (l5==0&&l8==1&&l9==1&&l10==1) && LR_flag==777) { LR_flag=7777; delay_ms(100); Left(); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1, 300); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_2, 280); delay_ms(300); while(1) { l7=gpio_get(GPIO_PORT_P6, GPIO_PIN3); if(l7==1) break; } } else if( (l3==1&&l4==1&&l5==1&&l8==0) && LR_flag==88) { LR_flag=888; delay_ms(100); Left(); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1, 300); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_2, 280); delay_ms(300); while(1) { l7=gpio_get(GPIO_PORT_P6, GPIO_PIN3); if(l7==1) break; } } else if( (l5==0&&l8==1&&l9==1&&l10==1) && LR_flag==888) { LR_flag=8888; delay_ms(100); Left(); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1, 300); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_2, 280); delay_ms(300); while(1) { l7=gpio_get(GPIO_PORT_P6, GPIO_PIN3); if(l7==1) break; } } else if( (l5==1&&l6==1&&l7==1&&l8==1) && ((LR_flag==7777)||(LR_flag==8888))) { over=1; Forward(); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1, 400); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_2, 380); } //停在病房门口 if( (l1==1||l2==1||l11==1||l12==1) && stop_flag==1) { stop_flag=2; Stop(); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1, 0); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_2, 0); button_flag=1; while(button_flag) { button_flag=gpio_get(GPIO_PORT_P7, GPIO_PIN7); } Back(); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1, 300); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_2, 280); delay_ms(500); Left(); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1, 300); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_2, 280); delay_ms(500); while(1) { l7=gpio_get(GPIO_PORT_P6, GPIO_PIN3); if(l7==1) break; } } //返回到药房门口 else if((l1==1||l2==1||l11==1||l12==1) &&(over==1)) { Stop(); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1, 0); MAP_Timer_A_setCompareValue(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_2, 0); TimerA1_Disable(); OLED_ShowString(30, 4, (uint8_t *)"T= S", 16); OLED_ShowNum(47,4,Timer,2,16); } }
疑难解答或技术交流联系下方wx即可
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。