Arduino wifi小车.doc_第1页
Arduino wifi小车.doc_第2页
Arduino wifi小车.doc_第3页
Arduino wifi小车.doc_第4页
Arduino wifi小车.doc_第5页
已阅读5页,还剩12页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

Arduinowifi小车简介wifi小车中用到了openwrt路由器,怎样刷路由器以及连接uvc摄像头所需软件不在此文档中详细描述,arduino通过网线连接ENC28J60网络模块再连接路由器,是由于TTL方式始终没有成功才增加的。本项目借用在路由器中luci所在的服务器提供web服务,增加控制页面实现了电脑键盘控制,客户端支持谷歌浏览器,手机终端用的ME722键盘控制也测试通过。注意舵机电源不要用控制板的VCC会导致电源不稳定,在本项目中连接的是电机驱动的5V端口,电机驱动需要和主控板共地。存在的问题是通过鼠标操作有些不方便,下面是详细信息以及源码。设备连接图网络图设备清单序号型号功能描述价格(含运费)1智能小车底盘带4WD驱动(MT-2电机驱动)小车地盘以及电机驱动模块1152Arduino MEGA2560 R3 开发板 2012新版,ATMEGA16U2-MU(官方板)主控板723Arduino MEGA Sensor Shield V2.0 专用传感器扩展板控制板扩展接口3047电发烧数显移动电源盒4节18650锂电池 5V至13V可变电压移动电源带4节18650电池1405ENC28J60网络模块控制板与路由器之间通信246正品天敏S604HD笔记本电脑免驱摄像头高清摄像头内置麦克风包邮摄像75.67水晶MW151RM 加USB 闪存 64M内存 openwrt 路由器无线通信1058二自由度云台(2个MG995舵机以及云台支架)控制摄像头方向769辅材若干杜邦线、网线、usb线20合计657.6接口文件irobot_main.h/-#ifndef _irobot_main_H_#define _irobot_main_H_/- #include #include #include #include #include /- /- / Put yout declarations here /- /=/ - DO NOT WRITE ANYTHING BETWEEN HERE./ This section is reserved for automated code generation/ This process tries to detect all user-created/ functions in main_sketch.cpp, and inject their/ declarations into this file./ If you do not want to use this automated process,/simply delete the lines below, with &MM_DECLA text/=/- DO NOT DELETE THIS LINE - MM_DECLA_BEG-void setServo(Servo &servo,int val);void setYServo(int val);void setXServo(int val);void pause(int gap);void turn();void right();void left();void back();void front();void setSpeedVal(int speedVal);void action(int command);void loop();void setup();int parseint(char* s);/- DO NOT DELETE THIS LINE - MM_DECLA_END-/ - .AND HERE. This space is reserved for automated code generation!/= /-#endif/- 源文件irobot_main.cpp/*project: irobotauthor: description: control program for robot*/#include irobot_main.h #define TCP_FLAGS_FIN_V 1 /as declared in net.h#define TCP_FLAGS_ACK_V 0x10 /as declared in net.hconst byte myip = 192,168,42,69 ;const byte gwip = 192,168,42,1 ;const byte mymac = 0x74,0x69,0x69,0x2D,0x30,0x39 ;byte Ethernet:buffer512; / tcp ip send and receive buffer const char success PROGMEM =HTTP/1.0 200 OKrnContent-Type: text/htmlrnrnresult: success, message:ok; /moto pinconst unsigned short motorA1 = A2;const unsigned short motorA2 = A3;const unsigned short motorB1 = A6;const unsigned short motorB2 = A7;const unsigned short motorC1 = A10;const unsigned short motorC2 = A11;const unsigned short motorD1 = A14;const unsigned short motorD2 = A15;const unsigned short ENA = 42;const unsigned short ENB = 43;const unsigned short ENC = 44;const unsigned short END = 45;const unsigned short minSpeedVal = 150;const unsigned short maxSpeedVal = 255;unsigned short speedVal = maxSpeedVal; /servo pinServo servoX;unsigned short servoXVal = 90;const unsigned short servoXPin = 46;Servo servoY;unsigned short servoYVal = 90;const unsigned short servoYPin = 48;const unsigned short gap = 10; /小车方向控制#define W 87#define S 83#define A 65#define D 68/云台方向控制#define LeftArrow 37#define UpArrow 38#define RightArrow 39#define DownArrow 40char* substr(const char*str,unsigned start, unsigned end)unsigned n = end - start;static char stbuf256;strncpy(stbuf, str + start, n);stbufn = 0;return stbuf; char* trim(char* str)if(str=NULL)return NULL;int st = 0;char* val = str; /* avoid getfield opcode */int len = strlen(str);int tmp = len;while (st len) & (valst = )st+;while (st len) & (vallen - 1 0 | lentmp)return substr(str,st, len);elsereturn str; int parseint(char* s)int retval=0;int n=1;if (*s=-)n=-1;s+;while (*s!=0)retval=retval*10+(*s-0);s+;return(n*retval); void setup() Serial.begin(9600); / MISO 50,MOSI 51,SCK 52,CS 53 for the mega ethernet shield and cs 10 for normal ethernet shieldif (ether.begin(sizeof Ethernet:buffer, mymac , 53) = 0) Serial.println( Failed to access Ethernet controller);ether.staticSetup(myip, gwip); servoX.attach(servoXPin);servoX.write(servoXVal);servoY.attach(servoYPin);servoY.write(servoYVal); pinMode(motorA1,OUTPUT);pinMode(motorA2,OUTPUT);pinMode(motorB1,OUTPUT);pinMode(motorB2,OUTPUT);pinMode(motorC1,OUTPUT);pinMode(motorC2,OUTPUT);pinMode(motorD1,OUTPUT);pinMode(motorD2,OUTPUT); void loop() word pos = ether.packetLoop(ether.packetReceive();/ check if valid tcp data is receivedif (pos) char* data = (char *) Ethernet:buffer + pos;const char* tag = ?action=;if (strncmp(GET /, data, 5) = 0) char* tmp = strstr(data,tag);char* charNum = trim(substr(tmp,8,10);/Serial.print(*);/Serial.print(charNum);/Serial.println(*);action(parseint(charNum);ether.httpServerReplyAck(); / send ack to the requestmemcpy_P(ether.tcpOffset(), success, sizeof success);ether.httpServerReply_with_flags(sizeof success - 1,TCP_FLAGS_ACK_V|TCP_FLAGS_FIN_V); Serial.flush(); void action(int command) Serial.println(command); switch(command)/控制方向case W:front();break;case S:back();break;case A:left();break;case D:right();break;/设置舵机case LeftArrow:setXServo(servoXVal+gap);break;case RightArrow:setXServo(servoXVal-gap);break;case UpArrow:setYServo(servoYVal-gap);break;case DownArrow:setYServo(servoYVal+gap);break; void setSpeedVal(int speedVal)analogWrite(ENA,speedVal);analogWrite(ENB,speedVal);analogWrite(ENC,speedVal);analogWrite(END,speedVal); void front() setSpeedVal(speedVal);/前轮digitalWrite(motorB1,HIGH);digitalWrite(motorB2,LOW);digitalWrite(motorD1,HIGH);digitalWrite(motorD2,LOW); /后轮digitalWrite(motorA1,LOW);digitalWrite(motorA2,HIGH);digitalWrite(motorC1,LOW);digitalWrite(motorC2,HIGH);pause(400); void back() setSpeedVal(speedVal);/前轮digitalWrite(motorB1,LOW);digitalWrite(motorB2,HIGH);digitalWrite(motorD1,LOW);digitalWrite(motorD2,HIGH); /后轮digitalWrite(motorA1,HIGH);digitalWrite(motorA2,LOW);digitalWrite(motorC1,HIGH);digitalWrite(motorC2,LOW);pause(400); void left() setSpeedVal(speedVal);/左侧digitalWrite(motorA1,LOW);digitalWrite(motorA2,HIGH);digitalWrite(motorB1,HIGH);digitalWrite(motorB2,LOW); /右侧digitalWrite(motorC1,HIGH);digitalWrite(motorC2,LOW);digitalWrite(motorD1,LOW);digitalWrite(motorD2,HIGH);pause(250); void right() setSpeedVal(speedVal);/左侧digitalWrite(motorA1,HIGH);digitalWrite(motorA2,LOW);digitalWrite(motorB1,LOW);digitalWrite(motorB2,HIGH); /右侧digitalWrite(motorC1,LOW);digitalWrite(motorC2,HIGH);digitalWrite(motorD1,HIGH);digitalWrite(motorD2,LOW);pause(250); void turn() left(); void pause(int gap) delay(gap);digitalWrite(motorA1,LOW);digitalWrite(motorA2,LOW);digitalWrite(motorB1,LOW);digitalWrite(motorB2,LOW);digitalWrite(motorC1,LOW);digitalWrite(motorC2,LOW);digitalWrite(motorD1,LOW);digitalWrite(motorD2,LOW); void setXServo(int val) int value =constrain(val,10,180);setServo(servoX,value);servoXVal = value; void setYServo(int val) int value =constrain(val,0,100);setServo(servoY,value);servoYVal = value; void setServo(Servo &servo,int val) servo.write(val);/Serial.print(Servo1 is set to:);/Serial.println(val);路由器中luci增加jquery-easyui工程iRobotvar localip = 7;var pcbip = 9;var sliderValue = 100;var light = false;function addIframe(tabId,title,url,clos)if($(#+tabId).tabs(exists,title)$(#+tabId).tabs(close,title);/refreshTab(tabTitle:title,url:url); var content =; $(#+tabId).tabs(add,title:title,content:content,style:overflow:hidden;padding:2px,closable:clos); $(function() addIframe(tabs,在线监测,http:/+localip+:8080/javascript_simple.html,false););$(function()document.onkeydown = function(e)var ev = document.all

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论