張興華,莊國銳
Arduino避障小車控制程序設計
張興華,莊國銳
(廣東白云學院 機電工程學院,廣東廣州,510450)
本文介紹了Arduino UNO微控制器控制的智能避障小車的控制程序,小車主控制器采用Arduino UNO,左右前輪采用直流電機驅(qū)動,后輪是從動萬向輪。舵機驅(qū)動的云臺上放置一個超聲波傳感器。可以自動避障。
Arduino;智能小車;舵機云臺;自動避障
隨著現(xiàn)代計算機技術(shù)的不斷發(fā)展和普及,機器人的發(fā)展已經(jīng)遍及近年來機器人的智能水平不斷提高,并且迅速的改變著人們的生活方式。
智能小車主控制器采用Arduino UNO,三輪結(jié)構(gòu),左右前輪采用直流電機驅(qū)動,后輪是從動萬向輪。舵機驅(qū)動的云臺上放置一個超聲波傳感器。
#include
#include
LiquidCrystal lcd(13,12,7,6,5,4,3);
int Echo = A1; int Trig =A0;
int F_D = 0;int L_D = 0;int R_D = 0;
int L_m_b=8;int L_m_g=9; //左電機后退(IN1)
//左電機前進(IN2)
int R_m_g=10; // 右電機前進(IN3)
int R_m_b=11; // 右電機后退(IN4)
int key=A2;int sp=2;
int ang,pw,v;
void setup(){
Serial.begin(9600); // 初始化串口
pinMode(L_m_g,OUTPUT);//PIN8 pinMode(L_m_b,OUTPUT); // PIN 9
pinMode(R_m_g,OUTPUT);// PIN 10
pinMode(R_m_b,OUTPUT);//PIN 11
pinMode(key,INPUT); pinMode(beep,OUTPUT);
pinMode(Echo, INPUT); // 超聲波輸入腳
pinMode(Trig, OUTPUT); // 超聲波輸出腳
lcd.begin(16,2);//初始化液晶
pinMode(sp,OUTPUT);}//舵機接口
void run(int time){
digitalWrite(R_m_g,HIGH); digitalWrite(R_m_b,LOW);
analogWrite(R_m_g,165);//PWM調(diào)速
analogWrite(R_m_b,0);
digitalWrite(L_m_g,HIGH); digitalWrite(L_m_b,LOW);
analogWrite(L_m_g,115); analogWrite(L_m_b,0);
delay(time * 100);} //執(zhí)行時間,可調(diào)整
void brake(int time); //剎車,停車
void left(int time);//左輪不動,右輪前進
void spin_left(int time);
void right(int time);void back(int time);
void spin_right(int time);
float D_test(){
digitalWrite(Trig, LOW);
delayMicroseconds(2);// 延時2μs
digitalWrite(Trig, HIGH);
delayMicroseconds(10);
digitalWrite(Trig, LOW);
float FD = pulseIn(Echo, HIGH);
FD= FD/58; return FD;}
void D_display(int D){
if((2 lcd.home();lcd.print(" D: "); //顯示 lcd.setCursor(6,2);//光標定位在第2行 lcd.print(D);lcd.print("cm"); } else{ lcd.home();lcd.print("Out of range"); } delay(250); lcd.clear();} Void servopulse(int sp,int ang){//servopin pw=(ang*11)+500;//將角度對應500~2480值 digitalWrite(sp,HIGH); delayMicroseconds(pw);//延時微秒數(shù) digitalWrite(sp,LOW); delay(20-pw/1000);}//延時毫秒數(shù) void front_detection(){ for(int i=0;i<=5;i++) //延時以轉(zhuǎn)到角度 servopulse(sp,90); F_D = D_test();} void left_detection(){ for(int i=0;i<=15;i++) servopulse(sp,175); L_D = D_test();} void right_detection(){ for(int i=0;i<=15;i++) servopulse(sp,5); R_D = D_test();} void loop(){ while(1) { front_detection();//測量前方距離 if(F_D < 32){ back(2);brake(2); left_detection();D_display(L_D); right_detection();D_display(R_D); if((L_D < 35 ) &&( R_D < 35 )) spin_left(0.7);//旋轉(zhuǎn)掉頭 else if(L_D > R_D) {left(3);brake(1); } else if(L_D < R_D) {right(3);brake(1); } } else run(); //無障礙物,直行 } } 在未來的社會中智能也是大勢所趨,只能機器人的發(fā)展水平可反應出一個國家的高科技水平和綜合國力,是國家綜合國力強大的標志,也是人類文明進步的標志。 [1] 《Make:Arduino Bots and Gadgets》Kimmo Karvinen,Tero Karvinen,O'Reilly. [2] 《愛上Arduino》Massimo Benzi,2014.05,人民郵電出版社。 [3] 趙云娥,吳振強.基于Arduino的雙模式智能避障小車系統(tǒng)設計與實現(xiàn)[J].現(xiàn)代電子技術(shù),2017,40(21):94-97. [4] 于洋. 基于Arduino的自動避障及通信控制智能小車系統(tǒng)的研究與設計[D].吉林大學,2017. [5] 卞云松.基于Arduino單片機的避障小車機器人[J].自動化技術(shù)與應用,2014,33(01):16-19. Control program design of Arduino vehicle for obstacle avoidance Zhang Xinghua, Zhuang Guorui Institute of mechanical and electrical engineering of Guangdong Baiyun University, Guangzhou 510450 This paper introduces the control program of the intelligent obstacle avoidance car controlled by Arduino UNO micro controller. The main controller of the car adopts Arduino UNO,the left and right front wheels are driven by DC motor and the rear wheel is a driven universal wheel. An ultrasonic sensor is placed on the platform driven by the steering gear. It can automatic obstacle avoidance. Arduino; intelligent car; steering gear pan; automatic obstacle avoidance. 10.19551/j.cnki.issn1672-9129.2019.03.038 TP212 A 1672-9129(2019)03-0110-02 張興華,(1967-)男,碩士,工程師,廣東白云學院。研究方向智能裝備、工業(yè)機器人設計。E-mail:2209282216@qq.com。 莊國銳,(1995-)男,廣東白云學院。材料成型及控制工程專業(yè)。E-mail:2209282216@qq.com。2 結(jié)束語: