机器人程序Word文档下载推荐.docx

上传人:b****6 文档编号:21110133 上传时间:2023-01-27 格式:DOCX 页数:15 大小:17.28KB
下载 相关 举报
机器人程序Word文档下载推荐.docx_第1页
第1页 / 共15页
机器人程序Word文档下载推荐.docx_第2页
第2页 / 共15页
机器人程序Word文档下载推荐.docx_第3页
第3页 / 共15页
机器人程序Word文档下载推荐.docx_第4页
第4页 / 共15页
机器人程序Word文档下载推荐.docx_第5页
第5页 / 共15页
点击查看更多>>
下载资源
资源描述

机器人程序Word文档下载推荐.docx

《机器人程序Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《机器人程序Word文档下载推荐.docx(15页珍藏版)》请在冰豆网上搜索。

机器人程序Word文档下载推荐.docx

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();

//黄红蓝次序

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 解决方案 > 学习计划

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1