Date post: | 24-Jun-2015 |
Category: |
Science |
Upload: | vladimir-kulyukin |
View: | 79 times |
Download: | 2 times |
Theory of Computation
Line Following Automaton for
Junun Mark III Robot
Vladimir Kulyukin
http://www.vkedco.blogspot.com/
Outline
● Hardware & Software Details of Junun Mark III Robot● A Line Following Automaton for Mark III Junun Robot
Hardware & Software Details of Junun Mark III Robot
Follow Line Start to End
Line Following Problem
Follow Line & Avoid Obstacles
Line Following Problem
Junun Mark III Robot
This robot has the 16f84a chip. The chip runs programs written in 16f84a Assembler.
16f84a Assembler Sample Code
Spot1 equ H'30'Spot2 equ H'31'
movlw D'5'movwf Spot1movlw D'2'addwf Spot1,Wmovwf Spot2movlw D'3'subwf Spot2,Wmovwf Spot1clrwclrf Spot1clrf Spot2nopend
What Does This Program Do?
16f84a Assembler Execution
Spot1 Spot2 W
movlw D'5'
BEFORE:
AFTER:
Spot1 Spot2
5
W
16f84a Assembler Execution
5
Spot1 Spot2 W
movwf Spot1
BEFORE:
AFTER: 5
Spot1 Spot2
5
W
16f84a Assembler Execution
5 5
Spot1 Spot2 W
movlw D’2’
BEFORE:
AFTER: 5
Spot1 Spot2
2
W
16f84a Assembler Execution
5 2
Spot1 Spot2 W
addwf Spot1,W
BEFORE:
AFTER: 5
Spot1 Spot2
7
W
Example: 16f84a Assembler
5 7
Spot1 Spot2 W
movwf Spot2
BEFORE:
AFTER: 5
Spot1
7
Spot2
7
W
Example: 16f84a Assembler
5 7 7
Spot1 Spot2 W
movlw D’3’
BEFORE:
AFTER: 5
Spot1
7
Spot2
3
W
Example: 16f84a Assembler
5 7 3
Spot1 Spot2 W
subwf Spot2,W
BEFORE:
AFTER: 5
Spot1
7
Spot2
4
W
Example: 16f84a Assembler
5 7 4
Spot1 Spot2 W
movwf Spot1
BEFORE:
AFTER: 4
Spot1
7
Spot2
4
W
Example: 16f84a Assembler
4 7 4
Spot1 Spot2 W
clrw
BEFORE:
AFTER: 4
Spot1
7
Spot2
0
W
Example: 16f84a Assembler
4 7 0
Spot1 Spot2 W
clrf Spot1
BEFORE:
AFTER: 0
Spot1
7
Spot2
0
W
Example: 16f84a Assembler
0 7 0
Spot1 Spot2 W
clrf Spot2
BEFORE:
AFTER: 0
Spot1
0
Spot2
0
W
16f84a Assembler
● We could program Junun Mark III robots directly in 16f84a Assembler● The two well known problems of Assemblers are:
– Hard to debug– Hard to maintain
● That is why software developers seek higher level alternatives that can be compiled into the target assembly
● JAL is one higher level alternative for 16f84a Assembler
JAL Sample Code: Fibonaccifunction fib(byte in n) return byte is var byte fib_rslt = 0 if ( n == 0 | n == 1 ) then fib_rslt = 1 return fib_rslt else var byte temp = 0 var byte prev = 0 var byte curr = 1 var byte count = n while ( count != 0 ) loop temp = curr curr = prev + curr prev = temp count = count - 1 end loop
return currend ifend function
16f84a Assembler JAL
Spot1 equ H'30'Spot2 equ H'31'
movlw D'5'movwf Spot1movlw D'2'addwf Spot1,Wmovwf Spot2movlw D'3'subwf Spot2,Wmovwf Spot1clrwclrf Spot1clrf Spot2nopend
function fib(byte in n) return byte is var byte fib_rslt = 0 if ( n == 0 | n == 1 ) then fib_rslt = 1 return fib_rslt else var byte temp = 0 var byte prev = 0 var byte curr = 1 var byte count = n while ( count != 0 ) loop temp = curr curr = prev + curr prev = temp count = count - 1 end loop return currend ifend function
Line Following
How can we make Mark III follow
a black line on the floor?
Line Following
Left Sensor
Middle Sensor
Right Sensor
Left Sensor returns black_on_left when it detects blackness.Middle Sensor returns black_on_center when it detects blackness.Right Sensor returns black_on_right when it detects blackness.
Line Following
if ( black_on_center ) move_forward;
We assume that the robotstarts with the middle sensoraligned with the line. So, ifthe middle sensor detectsblackness, the robot movesforward.
LEFT CENTER RIGHT
Line Following
if ( black_on_left ) turn_left;
If the left sensor detectsblackness, the robot turnsleft to align the middlesensor with the line.
LEFT CENTER RIGHT
Line Following
if ( black_on_right ) turn_right; If the right sensor detects
blackness, the robot turnsright to align the middlesensor with the line.
LEFT CENTER RIGHT
An FA for Line Following
read_sensors
turn_left
black_on_left
move_completed
turn_right
black_on_rightmove_completed
move_forward
black_on_center/no_black
move_completed
Line Following in JAL
JAL Code: Required INCLUDEs
include 16f877_20include jlibinclude markiii
JAL Code: FOLLOW_LINEprocedure follow_line is
forever loop -- left line sensor f877_adc_8(0, 7, adc8bitL) -- center line sensor f877_adc_8(0 ,6 , adc8bitC) -- right line sensor f877_adc_8(0 ,5 , adc8bitR)
take_line_follow_action
end loop
end procedure
JAL Code: TAKE_LINE_FOLLOW_ACTION
procedure take_line_follow_action is if ( adc8bitL > 128 ) then turn_left(25) elsif ( adc8bitC > 128 ) then move_forward(1) elsif ( adc8bitR > 128 ) then turn_right(25) else turn_left(5) end if
end procedure
JAL Code: TURN_LEFT & TURN_RIGHT
procedure turn_left (byte in delay) is left_wheel(4) right_wheel(9) delay_1ms(delay) robot_stopend procedure
procedure turn_right (byte in delay) is left_wheel(9) right_wheel(4) delay_1ms(delay) robot_stopend procedure
JAL Code: TURN_LEFT & TURN_RIGHT
procedure move_forward(byte in delay) is left_wheel(7) right_wheel(7) delay_10ms(delay) robot_stopend procedure
References
● Mark III User Guide● Line Following Competition