智能车制作

 找回密码
 注册

扫一扫,访问微社区

查看: 11599|回复: 2
打印 上一主题 下一主题

基于手势控制的智能小车

[复制链接]

1

主题

2

帖子

0

精华

注册会员

Rank: 2

积分
34
威望
21
贡献
11
兑换币
9
注册时间
2016-5-17
在线时间
1 小时
毕业学校
天津大学
跳转到指定楼层
1#
发表于 2016-5-17 20:59:27 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
arduino +MPU6050+mc33886驱动 制作一个手势控制的智能小车
现在代码有了,但那个代码两个L298N驱动两个电机的代码,并且使用的是Arduino Mega2560的板子,现在我想改用arduino UNO的板子,并且电机驱动使用MC33886驱动小车,应该怎样改程序。
原电路图如下:

代码如下:
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的板子,不知道如何修改程序的管脚代码,管脚如何连接,希望有懂得大神可以解答一下。
实物图如下:

这是驱动图片,因该如何连接ARDUINO UNO 管脚,代码应该怎样修改


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复

使用道具 举报

25

主题

211

帖子

1

精华

常驻嘉宾

Rank: 8Rank: 8

积分
3041
威望
1103
贡献
1584
兑换币
661
注册时间
2015-2-20
在线时间
177 小时
2#
发表于 2016-5-19 22:38:37 | 只看该作者
校级电赛刚做完这玩意哎
回复 支持 反对

使用道具 举报

1

主题

2

帖子

0

精华

注册会员

Rank: 2

积分
34
威望
21
贡献
11
兑换币
9
注册时间
2016-5-17
在线时间
1 小时
毕业学校
天津大学
3#
 楼主| 发表于 2016-5-20 07:40:43 | 只看该作者
长安 发表于 2016-5-19 22:38
校级电赛刚做完这玩意哎

您好,那您能看看我的程序应该如何修改吗?能麻烦您帮我修改下吗?
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

关于我们|联系我们|小黑屋|智能车制作 ( 黑ICP备2022002344号

GMT+8, 2024-12-26 15:17 , Processed in 0.072974 second(s), 36 queries , Gzip On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表