机器人程序Word文档下载推荐.docx
- 文档编号:21110133
- 上传时间:2023-01-27
- 格式:DOCX
- 页数:15
- 大小:17.28KB
机器人程序Word文档下载推荐.docx
《机器人程序Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《机器人程序Word文档下载推荐.docx(15页珍藏版)》请在冰豆网上搜索。
TheLEDsconnectedtoP1_0andP1_1areblinking!
\n"
for(Counter=1;
Counter<
=450;
Counter++)
delay_nus(1300);
delay_nms(20);
delay_nus(1539);
}
=470;
delay_nus(1700);
delay_nus(1461);
}
while
(1);
红外避障
intrins.h>
#defineLeftIRP1_2//左边红外接收连接到P1_2
#defineRightIRP3_5//右边红外接收连接到P3_5
#defineLeftLaunchP1_3//左边红外发射连接到P1_3
#defineRightLaunchP3_6//右边红外发射连接到P3_6
voidIRLaunch(unsignedcharIR)
intcounter;
if(IR=='
L'
)
for(counter=0;
counter<
38;
counter++)
LeftLaunch=1;
_nop_();
_nop_();
LeftLaunch=0;
R'
for(counter=0;
counter++)//右边发射
RightLaunch=1;
RightLaunch=0;
voidForward(void)//向前行走子程序
voidLeft_Turn(void)//左转子程序
inti;
for(i=1;
i<
=80;
i++)
{
P1_1=1;
delay_nus(1300);
P1_1=0;
P1_0=1;
delay_nms(20);
}
voidRight_Turn(void)//右转子程序
delay_nus(1700);
P1_0=0;
voidBackward(void)//向后行走子程序
intirDetectLeft,irDetectRight;
uart_Init();
printf("
ProgramRunning!
while
(1)
IRLaunch('
//右边发射
irDetectRight=RightIR;
//右边接收
//左边发射
irDetectLeft=LeftIR;
//左边接收
if((irDetectLeft==0)&
&
(irDetectRight==0))//两边同时接收到红外线
{
Backward();
Left_Turn();
}
elseif(irDetectLeft==0)//只有左边接收到红外线
Right_Turn();
}
elseif(irDetectRight==0)//只有右边接收到红外线
else
Forward();
俯视的探测器
#include<
#defineLeftIRP1_2//左边红外接收连接到P12
#defineRightIRP3_5//右边红外接收连接到P35
#defineLeftLaunchP1_3//左边红外发射连接到P13
#defineRightLaunchP3_6//右边红外发射连接到P36
intIRLaunch(unsignedcharIR)
intcounter;
if(IR=='
counter++)//左边发射
LeftLaunch=1;
LeftLaunch=0;
else
RightLaunch=1;
RightLaunch=0;
inti,pulseCount;
intpulseLeft,pulseRight;
bitirDetectLeft,irDetectRight;
do
IRLaunch('
irDetectRight=RightIR;
//右边接收
irDetectLeft=LeftIR;
//左边接收
if((irDetectLeft==0)&
(irDetectRight==0))//向前走
pulseCount=1;
pulseLeft=1700;
pulseRight=1300;
elseif((irDetectLeft==1)&
(irDetectRight==0))//右转
pulseCount=10;
pulseLeft=1300;
elseif((irDetectLeft==0)&
(irDetectRight==1))//左转
pulseRight=1700;
else//后退
pulseCount=15;
for(i=0;
pulseCount;
P1_1=1;
delay_nus(pulseLeft);
P1_1=0;
P1_0=1;
delay_nus(pulseRight);
P1_0=0;
delay_nms(20);
while
(1);
/**************************************************************************
编程说明:
----------------
该程序仅是搬运机器人比赛一个案例,采用方式是通过QTI传感器沿黑色道路循迹将色块
搬运到对应堆放区。
堆放区从左到右固定颜色依次为:
黄白红黑蓝
因为比赛规则要求比赛时任意拿出五个色块中的3个色块进行比赛并随机放置在ACE位置
所以用QTI循迹的方式来搬运色块就有5*3种方式。
以下案例是演示的是ACE位置上依次为黄红蓝时循迹案例,给大家做个提示。
需说明:
比赛使用的策略程序有千千万,在规则允许的范围内使用的传感器亦有很多,怎么
配合程序完成比赛需发挥大家的创意。
本案例是在用最常见最少传感器的情况下做出的,
仅供参考。
**************************************************************************/
reg52.h>
#include"
Global.h"
delay.h"
QTI.h"
motion.h"
#defineDIR_LEFT0//跨线方向:
左
#defineDIR_RIGHT1//跨线方向:
右
#defineuintunsignedint
#defineucharunsignedchar
ucharQTIState;
right_motor=1;
right_motor=0;
left_motor=1;
left_motor=0;
voidPivot_Left(void)//左转子程序
delay_nus(1360);
delay_nus(1500);
left_motor=0;
voidPivot_Right(void)//右转子程序
delay_nus(1660);
voidRotate_right(void)
right_motor=1;
delay_nus(1350);
voidRotate_Left(void)
delay_nus(1650);
delay_nus(1650);
voidGet_QTI_State(void)
QTIState=P2&
0x1e;
voidFollow_Line(void)
Get_QTI_State();
switch(QTIState)
case0x0c:
Forward();
break;
case0x0e:
Pivot_Right();
case0x1c:
Pivot_Left();
case0x1e:
break;
default:
voidrun_online(uint8_tsteps)
while(steps)
{
Follow_Line();
voidgoto_across1()
Follow_Line();
//沿着线走到十字路口
voidgoto_across()
//放置物块
voidput_material()
//中线控制
//机器人右偏判断0x10xx或01000x
if((!
P14_state())&
P22_state()&
(!
P23_state())||(!
P21_state()&
P22_state())&
P23_state())&
P24_state()))
motor_motion(1500,1300,1);
//左转修正
//机器人左偏判断xx01x0或x00010
elseif((!
P16_state())&
((!
P23_state())||((!
P21_state())&
motor_motion(1700,1500,1);
//右转修正
//机器人堆放物块1x00x1或xx00x1
elseif((P14_state()&
P16_state())||(!
P16_state())//到堆垛区1001或1x00x1
motor_motion(LEFT_BWD,RIGHT_BWD,40);
//倒退,避免马上转身造成物块被再次夹走
delay_nms(100);
motor_motion(1250,1250,42);
//180度旋转
break;
else
motor_motion(LEFT_FWD,RIGHT_FWD,1);
//前进
voidybr02()
run_online(40);
//put_material();
//放置黄色物料
motor_motion(1500,1500,0);
delay_nms(800);
motor_motion(LEFT_BWD,RIGHT_BWD,35);
motor_motion(1250,1250,52);
goto_across();
delay_nms(200);
motor_motion(1500,1250,26);
//90度支点左旋
//沿线走40个脉冲
motor_motion(LEFT_BWD,RIGHT_BWD,35);
motor_motion(1250,1250,42);
//put_material();
//放置红色物料
goto_across();
/*motor_motion(1500,1250,26);
run_online(100);
//沿线走100个脉冲
motor_motion(LEFT_BWD,RIGHT_BWD,40);
//放置lan色物料
delay_nms(500);
*/
}
voidmain()
delay_nms(2000);
motor_motion(1680,1300,80);
//前进,躲避出发区的三角地带(QTI看到的是1111)
motor_motion(1680,1300,20);
delay_nms(300);
//到十字路口,暂停100ms,使机器人不抖动(尾部抬高),造成机器人的方向的不准确
motor_motion(1650,1650,42);
//90度支点左旋
ybr02();
//黄红蓝次序
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 机器人 程序
![提示](https://static.bdocx.com/images/bang_tan.gif)