arduino +MPU6050+mc33886驱动 制作一个手势控制的智能小车 现在代码有了,但那个代码两个L298N驱动两个电机的代码,并且使用的是Arduino Mega2560的板子,现在我想改用arduino UNO的板子,并且电机驱动使用MC33886驱动小车,应该怎样改程序。 原电路图如下: [attach]85642[/attach] 代码如下: int pinI1=3;//定义I1接口 int pinI2=4;//定义I2接口 int pinI3=5; int pinI4=6; int pinI5=7; int pinI6=8; int pinI7=12; int pinI8=13; unsigned char Re_buf[11],counter=0; unsigned char sign=0; float a[3],w[3],angle[3],T; void setup() { pinMode(pinI1,OUTPUT);//定义该接口为输出接口 pinMode(pinI2,OUTPUT); pinMode(pinI3,OUTPUT); pinMode(pinI4,OUTPUT); pinMode(pinI5,OUTPUT); pinMode(pinI6,OUTPUT); pinMode(pinI7,OUTPUT); pinMode(pinI8,OUTPUT); Serial.begin(115200); } void not_move() { analogWrite(pinI1,0); analogWrite(pinI2,0); analogWrite(pinI3,0); analogWrite(pinI4,0); analogWrite(pinI5,0); analogWrite(pinI6,0); analogWrite(pinI7,0); analogWrite(pinI8,0); delay(10); } voidforward() { analogWrite(pinI1,100); analogWrite(pinI2,0); analogWrite(pinI3,100); analogWrite(pinI4,0); analogWrite(pinI5,100); analogWrite(pinI6,0); analogWrite(pinI7,100); analogWrite(pinI8,0); delay(10); } void backward() { analogWrite(pinI1,0); analogWrite(pinI2,100); analogWrite(pinI3,0); analogWrite(pinI4,100); analogWrite(pinI5,0); analogWrite(pinI6,100); analogWrite(pinI7,0); analogWrite(pinI8,100); delay(10); } void turn_left_forward() { analogWrite(pinI1,100); analogWrite(pinI2,0); analogWrite(pinI3,100); analogWrite(pinI4,0); analogWrite(pinI5,0); analogWrite(pinI6,0); analogWrite(pinI7,0); analogWrite(pinI8,0); delay(10); } void turn_left_backward() { analogWrite(pinI1,0); analogWrite(pinI2,100); analogWrite(pinI3,0); analogWrite(pinI4,100); analogWrite(pinI5,0); analogWrite(pinI6,0); analogWrite(pinI7,0); analogWrite(pinI8,0); delay(10); } void turn_right_forward() { analogWrite(pinI1,0); analogWrite(pinI2,0); analogWrite(pinI3,0); analogWrite(pinI4,0); analogWrite(pinI5,100); analogWrite(pinI6,0); analogWrite(pinI7,100); analogWrite(pinI8,0); delay(10); } voidturn_right_backward() { analogWrite(pinI1,0); analogWrite(pinI2,0); analogWrite(pinI3,0); analogWrite(pinI4,0); analogWrite(pinI5,0); analogWrite(pinI6,100); analogWrite(pinI7,0); analogWrite(pinI8,100); delay(10); } void loop() { if(sign) { sign=0; if(Re_buf[0]==0x55) //检查帧头 { switch(Re_buf [1]) { case 0x51: a[0] = (short(Re_buf [3]<<8| Re_buf[2]))/32768.0*16; a[1] = (short(Re_buf [5]<<8| Re_buf[4]))/32768.0*16; a[2] = (short(Re_buf [7]<<8| Re_buf[6]))/32768.0*16; T = (short(Re_buf [9]<<8| Re_buf[8]))/340.0+36.25; break; case 0x52: w[0] = (short(Re_buf [3]<<8| Re_buf[2]))/32768.0*2000; w[1] = (short(Re_buf [5]<<8| Re_buf[4]))/32768.0*2000; w[2] = (short(Re_buf [7]<<8| Re_buf[6]))/32768.0*2000; T = (short(Re_buf [9]<<8| Re_buf[8]))/340.0+36.25; break; case 0x53: angle[0] = (short(Re_buf[3]<<8| Re_buf [2]))/32768.0*180; angle[1] = (short(Re_buf [5]<<8| Re_buf[4]))/32768.0*180; angle[2] = (short(Re_buf [7]<<8| Re_buf[6]))/32768.0*180; T = (short(Re_buf [9]<<8| Re_buf[8]))/340.0+36.25; if(abs(angle[1])>=25) { if(angle[1]>=25) { if(angle[1]>=70) { not_move();} else if(abs(angle[0])<=25){not_move();} else if(angle[0]>25) {turn_right_forward();} else {turn_right_backward();} } else { if(angle[1]<=-70) {not_move();} elseif(abs(angle[0])<=25) {not_move();} else if(angle[0]>25) {turn_left_forward();} else {turn_left_backward();} } } else if(abs(angle[0])>=25) if(angle[0]>=25) {forward();} else{backward();} else {not_move();} } } } } void serialEvent() { while (Serial.available()) { //char inChar = (char)Serial.read();Serial.print(inChar); //Output Original Data, use this code Re_buf[counter]=(unsignedchar)Serial.read(); if(counter==0&&Re_buf[0]!=0x55)return; //第0号数据不是帧头 counter++; if(counter==11) //接收到11个数据 { counter=0; //重新赋值,准备下一帧数据的接收 sign=1; } } } 小车可以运行,但现在改成arduino UNO的板子,再使用MC33886的板子,不知道如何修改程序的管脚代码,管脚如何连接,希望有懂得大神可以解答一下。 实物图如下: [attach]85643[/attach] 这是驱动图片,因该如何连接ARDUINO UNO 管脚,代码应该怎样修改 |
长安 发表于 2016-5-19 22:38
校级电赛刚做完这玩意哎
欢迎光临 智能车制作 (http://111.231.132.190/) | Powered by Discuz! X3.2 |