Light Seeking Robot

advertisement
 Light Seeking Robot
Table of Contents
Introduction
This report is a detailed description of our robot mini project “Light Seeking
robot”. Our robot sensing the light and directed to the high luminance area. Our robot
has sensors to detect the luminance density. Also, it has ultrasonic sensors that will
allow it to avoid any obstacles that may prevent it to reach the high luminance area
successfully. This paper will present some approaches done by ourselves.
Integrating System
This section gives a description of the interfaced components of our robot:
Our robot has different components to implement the following tasks:
¾ Three LDR sensor to detect the luminance difference around the robot. These
three sensors were separated by 120 degrees to easily detect the light around it.
¾ Sonar Range Finder – One SFR04 ultrasound sensors is used navigate the
robot without any collision.
¾ Motor controller: We used 2 stepper motors to drive the robot and
ULAN2003A used to control the stepper motor.
Mobile Platform
The platform consists of three wheel and a fiber glass plate. This plate hold all the
components of the system, such as the microcontroller, battery, motor driver, etc; one
fiber glass holder the ultrasound sensor.
Sensors
Devantech SRF04 Range Finder
The SRF04 was designed to be just as easy to use as the Polaroid sonar,
requiring a short trigger pulse and providing an echo pulse.
The SRF04 Timing diagram is shown below. You only need to supply a short
10uS pulse to the trigger input to start the ranging. The SRF04 will send out an 8
cycle burst of ultrasound at 40khz and raise its echo line high. It then listens for an
echo, and as soon as it detects one it lowers the echo line again. The echo line is
therefore a pulse whose width is proportional to the distance to the object. By timing
the pulse it is possible to calculate the range in inches/centimeters or anything else. If
nothing is detected then the SRF04 will lower its echo line anyway after about 36mS.
Beam Pattern
LDR
We used three LDR sensors to detect the luminance difference around the
robot. These three sensors were separated by 120 degrees to easily detect the light
around it. To isolate the LDR voltage variation from the PIC controller we used
LM229 comparator.
Comparators constantly compare pairs of voltages and provide a digital
indication ('1' or '0') of which voltage is higher. Using the dedicated chip frees the
microcontroller, which is now only interrupted when the digital signal changes.
The LM239 is a quad, single-supply comparator. Quad: Can compare four
different pairs of voltages.
This comparator can operate up to 36 volts (or +18 V to -18 V). Since we
intend to connect it to a microcontroller, so we made this as +5 V and GND.
The LM239 is pin compatible with MC3303, LM339, and LM2901 chips.
Although their operating temperature ranges differ (and a few other differences)
they'll all work fine in this project.
This is our final source cods of the PIC controller
'****************************************************************
'* Name
: lightseeking.BAS
'* Date
: 6/27/2006
*
'* Version : 1.0
*
'* Notes
:
*
'*
:
*
'****************************************************************
A var byte
B var Byte
C var Byte
X var byte
input
Y var byte
Z var byte
'input signal from front light sensor
'input signal from back right side light sensor
'input signal from back left side light sensor
'input from buffer switch right back side
'input from buffer switch left back side input
'input from front SRF sensor input
FM var Byte
'stop motion status variable
CWF var byte
'clock wise fast rotatwe status variable
CWS var byte
'clock wise slowrotatwe status variable
CCWF var byte
'counter clock wise fast rotatwe status
variable
CCWS var Byte
'counter clock wise slow rotatwe status
variable
MF var byte
' move forward status variable
MB var byte
'move reverse status variable
RS var byte
'rotate robot status variable
CW var Byte
'clock wise rotate rotate status
CCW var Byte
'counter clock wise rotate status
OAS var byte
' bumper switch status
F var byte
R var byte
CF var byte
CCR var Byte
CCF var Byte
CR var word
CRC var word
stepArray var byte(8)
Rcm_10
var word
Rcm_10_total var word
Rcm_10_Average var word
i var byte
j var byte
Tm var word
k var word
Zavr var word[5]
period var word
NL var word
FL var word
symbol EchoPin
= PORTC.7
'difine port C pin 7 as SRF echo input
symbol TrigPin
output
= PORTB.0
'difine port B pin 0 as SRF trigure
symbol Motor_out = PORTD
Symbol OBSLed
*
= PORTE.1
TRISD = 0
' Define the port D as output
TRISC = 255
'Define the port C as input
TRISB = 0
'Define the port B as output
TRISE
=
0
'Define portD aa output
PORTD= 0
'set the port D output to 0
PORTB= 0
'set the port B output to 0
PORTE
=
0
'set the port E output to 0
Main:
gosub
read_inputs
if FM = 1 then gosub Free_move
If RS = 1 then gosub rotate
IF MF = 1 then gosub Move_forward
goto main
read_inputs:
if PORTC.0 = 1 then
a = 1
else
A=0
endif
if PORTC.1 = 1 then
B = 1
else
B=0
endif
if PORTC.2 = 1 then
c = 1
else
c=0
endif
'b = PORTC.1
'c = PORTC.2
if (PORTC.0 = 0) and (PORTC.1 = 0) and (PORTC.2 = 0) then
NL = 1
else
NL = 0
endif
FL = A&B&C
FM = FL|NL
gosub Read_frontSRF
if z = 1 then gosub Avoid_Obstale
CWF = (~A)&C
CWS = A&(~B)&C
CCWF = (~A)&B&(~C)
CCWS = A&B&(~C)
CW = CWF|CWS
CCW = CCWF|CCWS
RS = CWF|CWS|CCWF|CCWS
MF = (~B)&(~C)&A
return
Move_forward:
gosub Move_forward_accelerate
gosub Move_forward_constant
gosub read_inputs
'IF MF = 1 then Move_forward_constant
return
rotate:
If CWF
IF CWS
if CCWF
if CCWS
=
=
=
=
1
1
1
1
then
then
then
then
gosub
gosub
gosub
gosub
Clockwise_Fast
Clockwise_Slow
C_Clock_Fast
C_Clock_Slow
gosub read_inputs
If RS = 1 then gosub rotate
goto main
Move_forward_accelerate:
for j = 100 to 20 step -10
stepArray[0]
stepArray[1]
stepArray[2]
stepArray[3]
=
=
=
=
%11001001
%01100011
%00110110
%10011100
for i = 0 to 3 step 1
PORTD = stepArray[i]
period = j
pause period
next i
next j
return
Move_forward_constant:
for i = 0 to 3 step 1
PORTD = stepArray[i]
pause 20
next i
gosub read_inputs
IF MF = 1 then Move_forward_constant
return
Clockwise_Fast:
gosub Clockwise_Fast_accelerate
gosub Clockwise_Fast_constant
gosub read_inputs
If CWF = 1 then gosub Clockwise_Fast_constant
if RS =1 then GOSUB rotate
goto main
Clockwise_Fast_accelerate:
for j = 100 to 30 step -10
stepArray[0]
stepArray[1]
stepArray[2]
stepArray[3]
=
=
=
=
%11000000
%01100000
%00110000
%10010000
'Clock wise with Fast motion'
for i=0 to 3 step 1
PORTD = stepArray[i]
period = j
pause period
next i
next j
gosub read_inputs
'if RS =1 then GOSUB rotate
return
Clockwise_Fast_constant:
stepArray[0] = %11000000
stepArray[1] = %01100000
stepArray[2] = %00110000
stepArray[3] = %10010000
for i=0 to 3 step 1
PORTD = stepArray[i]
pause 30
next i
gosub read_inputs
If CWF = 1 then gosub Clockwise_Fast_constant
if RS =1 then GOSUB rotate
return
C_Clock_Fast:
gosub C_Clock_Fast_accelerate
gosub C_Clock_Fast_constant
gosub read_inputs
If CCwF = 1 then gosub C_Clock_Fast_constant
if RS =1 then GOSUB rotate
goto main
C_Clock_Fast_accelerate:
'Clock wise with Fast motion'
for j = 100 to 30 step -10
stepArray[0] = %00001100
stepArray[1] = %00000110
stepArray[2] = %00000011
stepArray[3] = %00001001
for i = 3 to 0 step -1
PORTD = stepArray[i]
period = j
pause period
next i
next j
gosub read_inputs
if RS =1 then GOSUB rotate
return
C_Clock_Fast_constant:
stepArray[0] = %00001100
stepArray[1] = %00000110
stepArray[2] = %00000011
stepArray[3] = %00001001
for i= 3 to 0 step -1
PORTD = stepArray[i]
pause 30
next i
gosub read_inputs
If CCWF = 1 then gosub C_Clock_Fast_constant
if RS =1 then GOSUB rotate
return
Clockwise_Slow:
stepArray[0] = %11000000
stepArray[1] = %01100000
stepArray[2] = %00110000
stepArray[3] = %10010000
for i= 0 to 3 step 1
PORTD = stepArray[i]
pause 60
next i
return
C_Clock_Slow:
stepArray[0] =
stepArray[1] =
stepArray[2] =
stepArray[3] =
%00001100
%00000110
%00000011
%00001001
for i= 3 to 0 step -1
PORTD = stepArray[i]
pause 60
next i
return
Free_Move:
gosub Move_forward
for k = 0 to 50 step 1
gosub read_inputs
if FM = 1 then
gosub Move_forward_constant
else
goto main
endif
next k
gosub
read_inputs
if FM = 1 then
gosub Clockwise_Fast_accelerate
gosub Clockwise_Fast_accelerate
else
goto main
endif
return
Read_frontSRF:
Tm
= 0
Rcm_10
= 0
Rcm_10_total = 0
PulsOut TrigPin,10
' sonar output, 10 us
PulsIn EchoPin, 1, Tm
If Tm = 0 Then gosub OverRange
If Tm > 1800 Then gosub OverRange
Rcm_10 = Tm *
IF
10 / 58
' assumes 10 us per tick on pulsin
( Rcm_10 <= 25 ) and ( Rcm_10 > 0 )
Z
OBSLed
= 1
= 1
else
Z
OBSLed
= 0
= 0
endif
pause 10
return
OverRange:
Rcm_10 = 0
return
Avoid_Obstale:
gosub Clockwise_Fast_accelerate
gosub Clockwise_Fast_accelerate
gosub Move_forward
gosub read_inputs
gosub Move_forward
goto main
then
Further Development
1. Improvement of light sensing can be made with a array of LDR sensors. That
will give a high accuracy of readings.
2. We can use separate PIC controllers for Light sensors, sonar sensors, and
motor controller.
Conclusion
Our overall experience making this robot has been a great learning
opportunity. We made several mistakes and was able to correct some of them. If we
were to design and build this robot again we would have built the platform very early
in the semester because that was the most time consuming portion of the robot. As far
as enhancements go, Overall, it was a great learning experience and this project has
helped me further realize the importance of good time management.
Appendix A
Vendor Information:
Devantech SRF04 Ultrasound Sensor
Acroname Inc.
4894 Sterling Drive
Boulder , CO 80301
www.acroname.com
Part #:R145-SRF08
$42.50
Download