Professional Documents
Culture Documents
smartcar
2013 6 16
1 ...........................................................................................................1
1.1 ..................................................................................................1
1.2 ..................................................................................................1
1.3 ..................................................................................................2
2 ...........................................................................................................3
2.1 ............................................................................................3
2.2 .............................................................................................10
4 .........................................................................................................14
1
1.1
2 Zigbee
ARM
1.2
robotrobota1920
Robot
, 3
1959
(20 70 )
(20 80 )
60
SRI Nits Nilssen Charles Rosen 1966 1972
Shake
20 80
AMRIndoor Autonomous Mobile Robot
DARPA
DARPA
ALV19831990 10
RIPS19861995
80
1994
THMR111
AGV
1996
1.3
1994 (Dante),
,,
,
,(AMR)
,,
1
1.1
2.1
Arduino
1Arduino UNO
4
L298N
5 + + + + + +
PVC
android
#defineDEBUG
//
set
to
to
to
serial
monitor,
to
#include
<Servo.h>
Servo
//
const
const
disable
//
headservo;
int
int
EchoPin
2;
TrigPin
3;
constintleftmotorpin1
const
int
constintrightmotorpin1
constintrightmotorpin2
//
4;
//
//
Constants
leftmotorpin2
=
=
=
5;
6;
7;
constintHeadServopin = 9; //
Sharppin
=
const
int
11;
//
9 10
constintmaxStart
//run
//
int
int
800;
isStart
maxStart;
currDist
0;
boolean
dec
//
Variables
false;
//
running
time
voidsetup()
Serial.begin(9600);
//
//
pinMode(EchoPin,
INPUT);
pinMode(Sharppin,
//
for(int
INPUT);
pinindex
pinMode(pinindex,
3;
OUTPUT);
pinindex
//
set
<
pins
11;
3
to
pinindex++)
10
as
outputs
}
//
headservo.attach(HeadServopin);
//
headservo.write(70);
delay(2000);
headservo.write(20);
delay(2000);
}
voidloop()
if(DEBUG){
Serial.print("running:");
if(running){
Serial.println("true");
}
else{
Serial.println("false");
}
}
if(isStart
if(running){
0)
<=
//
totalhalt();
stop!
}
intfindsomebody
if(DEBUG){
Serial.print("findsomebody:");
digitalRead(Sharppin);
Serial.println(findsomebody);
}
if(findsomebody
isStart
0)
>
=
{
maxStart;
}
delay(4000);
return;
}
isStart--;
delay(100);
if(DEBUG){
Serial.print("isStart:
");
Serial.println(isStart);
}
currDist
//
MeasuringDistance();
if(DEBUG){
Serial.print("Current
Distance:
");
Serial.println(currDist);
}
if(currDist
30)
>
nodanger();
}
elseif(currDist
15){
<
backup();
randTrun();
}
else{
//whichway();
randTrun();
}
}
//
MeasuringDistance()
long
longduration;
//pinMode(TrigPin,
OUTPUT);
digitalWrite(TrigPin,
LOW);
delayMicroseconds(2);
digitalWrite(TrigPin,
HIGH);
delayMicroseconds(5);
digitalWrite(TrigPin,
LOW);
//pinMode(EchoPin,
duration
INPUT);
=
returnduration
pulseIn(EchoPin,
29
HIGH);
/
2;
//
voidnodanger()
running
true;
digitalWrite(leftmotorpin1,
LOW);
digitalWrite(leftmotorpin2,
HIGH);
digitalWrite(rightmotorpin1,
LOW);
digitalWrite(rightmotorpin2,
HIGH);
6
return;
}
//
voidbackup()
running
true;
digitalWrite(leftmotorpin1,
HIGH);
digitalWrite(leftmotorpin2,
LOW);
digitalWrite(rightmotorpin1,
HIGH);
digitalWrite(rightmotorpin2,
LOW);
delay(1000);
}
//
voidwhichway()
running
true;
stop!
//
totalhalt();
first
headservo.write(20);
delay(1000);
intlDist
//
headservo.write(120);
intrDist
//
MeasuringDistance();
totalhalt();
//
//
if(lDist
turn
left
the
distance
right
delay(1000);
check
right
distance
//
MeasuringDistance();
totalhalt();
check
<
servo
rDist)
body_lturn();
}
else{
body_rturn();
}
return;
}
//
voidtotalhalt()
digitalWrite(leftmotorpin1,
HIGH);
digitalWrite(leftmotorpin2,
HIGH);
digitalWrite(rightmotorpin1,
HIGH);
digitalWrite(rightmotorpin2,
HIGH);
headservo.write(70);
//
set
servo
7
to
face
forward
running
false;
return;
delay(1000);
}
//
voidbody_lturn()
running
true;
digitalWrite(leftmotorpin1,
LOW);
digitalWrite(leftmotorpin2,
HIGH);
digitalWrite(rightmotorpin1,
HIGH);
digitalWrite(rightmotorpin2,
LOW);
delay(1500);
totalhalt();
}
//
voidbody_rturn()
running
true;
digitalWrite(leftmotorpin1,
HIGH);
digitalWrite(leftmotorpin2,
LOW);
digitalWrite(rightmotorpin1,
LOW);
digitalWrite(rightmotorpin2,
HIGH);
delay(1500);
totalhalt();
}
voidrandTrun(){
longrandNumber;
randomSeed(analogRead(0));
randNumber
if(randNumber
=
>
random(0,
10);
5)
body_rturn();
}
else
{
body_lturn();
}
}
2.2
Arduino SEGWAY
Arduino
1 L3G4200D
2 ADXL345
3Arduino
4L298N
5
= -
PID PWM
PID::PID(double*
doubleKp,
Input,
double
Ki,
double*
double
Output,
Kd,
int
double*
Setpoint,
ControllerDirection)
{
PID::SetOutputLimits(0,
//the
255);
//default
arduino
10
output
limit
pwm
corresponds
to
limits
SampleTime
100;
//default
Controller
Sample
Time
is
0.1
seconds
PID::SetControllerDirection(ControllerDirection);
PID::SetTunings(Kp,
lastTime
Ki,
=
Kd);
millis()-SampleTime;
inAuto
false;
myOutput
Output;
myInput
Input;
mySetpoint
Setpoint;
PID LIB
Input ()
Output PID PWM
Setpoint
KpKiKd KPI
Steady-state error
I
+(PI)
D
(delay)
+
+(PD)
PID
11
//PID
setupPID();
....
Kalman_Filter(Adxl_angle,
//
Gyro_sensor);
Input
//PID
//
myPID.Compute();
Drive(Output);
angle
angle;
Output
Output
voidsetupPID(){
Input
Setpoint
=
=
17;
//
//
//myPID.SetOutputLimits(0,
myPID.SetSampleTime(100);
0;
17
100ms
2000);
myPID.SetMode(AUTOMATIC);
1220 PID
kp,ki,kd
4
[1] www.arduino.cc
12