中科杯机器人应用技术机器人车运行程序文档格式.docx
- 文档编号:5274553
- 上传时间:2023-05-04
- 格式:DOCX
- 页数:59
- 大小:21.11KB
中科杯机器人应用技术机器人车运行程序文档格式.docx
《中科杯机器人应用技术机器人车运行程序文档格式.docx》由会员分享,可在线阅读,更多相关《中科杯机器人应用技术机器人车运行程序文档格式.docx(59页珍藏版)》请在冰点文库上搜索。
sbitO3=P3^2;
//投球
sbitO4=P3^3;
sbitO5=P3^4;
sbitO6=P3^5;
sbitO7=P3^6;
sbitO8=P3^7;
bitW_0;
//传感器低8位
bitW_1;
bitW_2;
bitW_3;
bitW_4;
bitW_5;
bitW_6;
bitW_7;
sbitP0_0=P0^0;
//红蓝
sbitP0_1=P0^1;
sbitP0_2=P0^2;
sbitP0_3=P0^3;
sbitP0_4=P0^4;
//左限位
sbitP0_5=P0^5;
//右限位
sbitP0_6=P0^6;
sbitP0_7=P0^7;
//接近开关
unsignedcharnum,c=0,jp=0,j,co,ball=0,sener;
unsignedcharmode;
#definel1//左电机
#definer2//右电机
#definerl3
//#defineS_B70//基准占空比设置
#definef'
f'
//代表电机正转
#defineforward'
#defineb'
b'
//代表电机反转
#definebackward'
/*=======================================================================
【函数原形】:
voidpwm0_1()
【功能说明】:
PCA时钟源控制寄存器计数初值设置
2011年1月20日
========================================================================*/
voidpwm0_1()
{
CCON=0x00;
CH=0;
CL=0;
CMOD=0x00;
}
voidPWM0(unsignedcharFosc_1)
【参数说明】:
Fosc_0Fosc_0为占空比设置形参
voidPWM0(unsignedintFosc_0)//Fosc_0为占空比设置形参
CCAP0H=CCAP0L=((Fosc_0)*25)/10;
CCAPM0=0X42;
//8位PWM输出,无中断
PCA_PWM0=0x00;
voidPWM1(unsignedcharFosc_1)
Fosc_1Fosc_1为占空比设置形参
voidPWM1(unsignedintFosc_1)
CCAP1H=CCAP1L=((Fosc_1)*25)/10;
CCAPM1=0X42;
PCA_PWM1=0x00;
voiddelay_ms(unsignedintT)
T延时时间设定
【函数功能】:
ms级延时函数
unsignedintCON;
unsignedinti;
for(i=0;
i<
T;
i++)
for(CON=0;
CON<
500;
CON++);
voidmotor(unsignedcharm,unsignedcharz,unsignedintn,)
m电机,z方向,n占空比
voidmotor(unsignedcharm,unsignedcharz,unsignedintn)
{switch(m)
{
caser:
if(z==forward||z==f){CR=1;
PWM0(n);
DIR_0=1;
elseif(z==backward||z==b){CR=1;
DIR_0=0;
break;
casel:
PWM1(n);
DIR_1=1;
}
DIR_1=0;
default:
}
/*====================================================
【函数原形】:
voidstop(unsignedcharm)
【参数说明】:
m:
选择电机
【功能说明】:
停止电机转动
【修改时间】:
====================================================*/
voidstop(unsignedcharm)
switch(m)
{
caser:
/*CR=0;
*/PWM0(0);
break;
casel:
*/PWM1(0);
caserl:
CR=0;
PWM0(0);
PWM1(0);
default:
voidFOLL_FINE(unsignedintS_B,unsignedintti)
16位巡线功能
S_B机器人基准速度设置ti巡线条数的设定
【编写时间】:
2011年1月25日
正巡线数线
voidFOLL_FINE(unsignedintS_B,unsignedintti)
{intn=0;
while
(1)
num=0;
motor(r,f,S_B);
motor(l,f,S_B);
P4_4=0;
//读取低8位
if(WP_8)num++;
if(WP_9)num++;
if(WP_10)num++;
if(WP_11)num++;
if(WP_12)num++;
if(WP_13)num++;
if(WP_14)num++;
if(WP_15)num++;
W_0=WP_8;
W_1=WP_9;
W_2=WP_10;
W_3=WP_11;
W_4=WP_12;
W_5=WP_13;
W_6=WP_14;
W_7=WP_15;
P4_4=1;
//读取高8位
if(num>
8)
for(co=0;
co<
200;
co++);
//寻白条时去除干扰信号的影响
//低位
//高位
c=c+1;
if(c==ti)
c=0;
return;
else
delay_ms(300);
if((S_B>
=60)&
&
(S_B<
=80))
{if(W_7&
WP_8)
n=0;
elseif(W_7)
motor(r,f,S_B-10);
motor(l,f,S_B+10);
elseif(WP_8)
motor(r,f,S_B+10);
motor(l,f,S_B-10);
elseif(W_6)
motor(r,f,S_B-20);
motor(l,f,S_B+15);
n--;
elseif(WP_9)
motor(r,f,S_B+15);
motor(l,f,S_B-20);
n++;
elseif(W_5)
motor(r,f,S_B-25);
elseif(WP_10)
motor(r,f,S_B+20);
motor(l,f,S_B-30);
elseif(W_4)
motor(r,f,S_B-30);
elseif(WP_11)
motor(l,f,S_B-35);
elseif(W_3)
motor(r,f,S_B-35);
motor(l,f,S_B+20);
elseif(WP_12)
motor(l,f,S_B-50);
elseif(W_2)
motor(r,f,S_B-50);
elseif(WP_13)
motor(l,f,S_B-60);
elseif(W_1)
motor(r,f,S_B-60);
elseif(WP_14)
elseif(W_0)
elseif(WP_15)
if(S_B>
80)//基准速度大于80时的巡线程序
{if(W_7&
{
motor(r,f,S_B);
motor(l,f,S_B);
n=0;
}
elseif(W_7)
motor(r,f,S_B-10);
motor(l,f,S_B+10);
elseif(WP_8)
motor(r,f,S_B+10);
motor(l,f,S_B-10);
elseif(W_6)
motor(r,f,S_B-20);
n--;
elseif(WP_9)
motor(l,f,S_B-20);
n++;
elseif(W_5)
motor(r,f,S_B-50);
elseif(WP_10)
motor(l,f,S_B-50);
elseif(W_4)
motor(r,f,S_B-60);
elseif(WP_11)
motor(l,f,S_B-60);
elseif(W_3)
n--;
elseif(WP_12)
n++;
elseif(W_2)
motor(r,f,S_B-70);
elseif(WP_13)
motor(l,f,S_B-70);
elseif(W_1)
motor(r,f,S_B-80);
elseif(WP_14)
elseif(W_0)
elseif(WP_15)
motor(l,f,S_B-80);
elseif(!
(W_0&
W_1&
W_2&
W_3&
W_4&
W_5&
W_6&
W_7&
WP_8&
WP_9&
WP_10&
WP_11&
WP_12&
WP_13&
WP_14&
WP_15)&
n<
0)
DIR_0=0;
DIR_1=1;
delay_ms(80);
motor(r,b,60);
motor(l,f,60);
delay_ms(500);
do
W_1=WP_9;
W_2=WP_10;
W_3=WP_11;
W_4=WP_12;
W_5=WP_13;
W_6=WP_14;
W_7=WP_15;
if(W_7)
delay_ms(3);
}
while(!
(W_7));
n>
DIR_0=1;
DIR_1=0;
motor(r,f,60);
motor(l,b,60);
if(WP_8)
(WP_8));
}
voidTURN_90()
控制左右转向
2011年2月17日
voidTURN_90(unsignedchare)
delay_ms(150);
PWM0(0);
PWM1(0);
delay_ms(10);
if(e==r)//右转控制选择语句
//右
//左
motor(r,b,75);
motor(l,f,65);
delay_ms(1000);
if(W_5||W_4||W_3)
(W_5||W_4||W_3));
if(e==l)//左转控制选择语句
motor(l,b,80);
if(WP_10||WP_11||WP_12)
(WP_10||WP_11||WP_12));
delay_ms(20);
//延时等待继电器动作
voidTURN_90l()
voidTURN_901(unsignedcharh)
if(h==r)//右转控制选择语句
motor(r,b,6
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 中科杯 机器人 应用技术 运行 程序