机器人小车(论文)

  • 格式:doc
  • 大小:179.50 KB
  • 文档页数:13

机器人小车 队员:刘汝磊、陈 齐、谈仲武 陈喜、吴天威、沈博伟、孟杰

单位:黄山学院 指导老师:***

2008年7月14日 机器人小车 摘 要:本系统以89C52单片机为核心,辅以步进电机、LCD

显示、红外传感器和触须传感器数据采集等电路组成,实现了机器人小车的前后行走、左右转弯、灵巧避障,寻轨行走、LCD显示等功能。避障采用了红外避障和触须避障两种方案,能更好且更精确的避开障碍物。使用LCD显示,丰富小车功能和构造。

Abstract:The system is designed to construct a wired

monitor system of a master station controlling multiple slave stations,with a micro-controller 89C52 as the key, complimented by stepper motor drive, LCD display, infrared sensors and sensor data acquisition tentacles, and other circuit components, to achieve a robot walking around the car, turning around, ingenious obstacle avoidance, look for tracks Walking, LCD display, and other functions. Obstacle avoidance of the use of infrared obstacle avoidance and tentacles obstacle avoidance two programmes, better and more precise to avoid obstacles. The use of LCD display, rich car functions and structure. 一、 功能与方案 1、 前后行走与左右转弯 小车行走是依靠左右边的两个伺服电机,伺服电机的工作原理与普通的电机不通,它的动力来源于不同频率的脉冲。在这里,给它1.3ms左右的脉冲时,它就正转,如图1所示。给它1.5ms左右的脉冲时,它就静止,如图2所示。给它1.7ms左右的脉冲时,它就反转,如图3所示。

图2 电机转速为零的控制信号时序图 图3 1.7ms的连续脉冲序列使电机逆时针全速旋转

图1 1.3 ms的控制脉冲序列使电机顺时针全速旋转 伺服电机与单片机的连接如图4所示: 不同频率的脉冲是由单片机通过编程送出,如程序一所示: 程序一: while(1) { P1_0=1; //P1_0输出高电平 delay_nus(1500); //延时1.5ms P1_0=0; //P1_0输出低电平 delay_nus(20000); //延时20ms }

(伺服电机静止)

while(1) { P1_0=1; //P1_0输出高电平 delay_nus(1300); //延时1.3ms P1_0=0; //P1_0输出低电平 delay_nus(20000); //延时20ms }

(伺服电机正转)

{ P1_0=1; //P1_0输出高电平 delay_nus(1700); //延时1.7ms P1_0=0; //P1_0输出低电平 delay_nus(20000); //延时20ms

} (伺服电机反转)

图4 伺服电机的连线原理图(左)和实际接线示意图(右) 机器人小车的转弯是通过让一个伺服电机转动,另一个不转或是反转来实现的。

2、机器人小车的避障功能 避障采取了两种方案,一种是红外避障,另一种是触须避障。 a、红外避障 要想让红外接收装置最大范围地接收到反射回来的信号,就一定要调整探头和接收装置的角度问题,尽量让它们工作在同一条直线上。有两种方法可以控制红外的探测范围,一种是软件方法,一种是硬件方法。软件方法是通过程序修改红外的发射频率,从而达到控制探测范围的效果,硬件方法是在红外发射装置上接上一个电阻,便会减小红外探测范围,电阻越大,红外探测也就越小。红外探测电路如图5所示:

图5 例小车左红外探测如程序二: 程序二: #include #include int P1_2state(void) { return (P1&0x04)?1:0; } int main(void) { int counter; int irDetectLeft; uart_Init(); printf("Program Running!\n");

while(1) { for(counter=0;counter<38;counter++) { P1_3=1; delay_nus(13); P1_3=0; delay_nus(13); } irDetectLeft=P1_2state(); printf("irDetectLeft=%d\n",irDetectLeft); delay_nms(100); } }

b、触须探测: 触须也是相当于一个开关作用,当遇到障碍物变形后,便会触碰到触须附近的弹片,这样就相当于形状闭合,电路接通后便会送出一个信号到我们小车上的单片机上,单片机经过处理后,送出一个信号到伺服电机,告诉前方有障碍物,需要转弯,这样就完成了小车避障的功能。 触须探测电路如图6:

图 6 触须探测如程序三: 程序三: #include #include

int P1_4state(void)//获取P1_4的状态 { return (P1&0x10)?1:0; } int P2_3state(void)//获取P2_3的状态 { return (P2&0x08)?1:0; }

int main(void) { uart_Init(); printf("WHISKER STARTES\n"); while(1) { printf("右边胡须的状态:%d ",P1_4state()); printf("左边胡须的状态:%d\n",P2_3state()); delay_nms(150); } } 3、小车寻轨 轨道是用黑色绝缘在白色纸板上做成的一个U字型轨道。利用红外识别轨道,红外遇到白纸被反射,遇到黑色轨道就被吸收。在小车的前端左右两边分别有一个红外探测器,当小车的红外接收装置接收到反射回来的信号时,小车就直走,当红外接收装置没有接收到信号时,小车就转弯,左边接收到就左转弯,右边接收到就右转弯。这样就可以让小车寻着轨道行走了。

轨道如图7所示:

图 7 寻轨如程序四: 程序四: #include #include

#define LeftIR P1_2 //左边红外接受连接到P1_2 #define RightIR P3_5 //右边红外接收连接到P3_5 #define LeftLaunch P1_3 //左边红外发射连接到P1_3 #define RightLaunch P3_6 //右边红外发射连接到P3_6

#define Kpl 70 #define Kpr -70 #define SetPoint 3 #define CenterPulse 1500

unsigned int time; int leftdistance,rightdistance;//左边和右边的距离 int delayCount,distanceLeft,distanceRight,irDetectLeft,irDetectRight; unsigned int frequency[5]={29370,31230,33050,35700,38460};

void timer_init(void) { IE=0x82; //开总中断EA,允许定时器0中断ET0 TMOD |= 0X01; //定时器0工作在模式1:16位定时器模式 }

void FreqOut(unsigned int Freq) { time = 256 - (50000/Freq); TH0 = 0XFF ; TL0 = time ; TR0 = 1; delay_nus(800); TR0 = 0; }

void Timer0_Interrupt(void) interrupt 1 { LeftLaunch = ~LeftLaunch; RightLaunch= ~ RightLaunch; TH0 = 0XFF; TL0 = time; }

void Get_lr_Distances() { unsigned char count; leftdistance = 0; //初始化左边的距离 rightdistance = 0; //初始化右边的距离 for(count = 0;count<5;count++) { FreqOut(frequency[count]); irDetectRight = RightIR; irDetectLeft = LeftIR; if (irDetectLeft == 1)