theory of computation (fall 2014): line following automaton for junun mark iii robot
TRANSCRIPT
![Page 1: Theory of Computation (Fall 2014): Line Following Automaton for Junun Mark III Robot](https://reader034.vdocuments.us/reader034/viewer/2022052601/5589e1b2d8b42a6d2c8b4658/html5/thumbnails/1.jpg)
Theory of Computation
Line Following Automaton for
Junun Mark III Robot
Vladimir Kulyukin
http://www.vkedco.blogspot.com/
![Page 2: Theory of Computation (Fall 2014): Line Following Automaton for Junun Mark III Robot](https://reader034.vdocuments.us/reader034/viewer/2022052601/5589e1b2d8b42a6d2c8b4658/html5/thumbnails/2.jpg)
Outline
● Hardware & Software Details of Junun Mark III Robot● A Line Following Automaton for Mark III Junun Robot
![Page 3: Theory of Computation (Fall 2014): Line Following Automaton for Junun Mark III Robot](https://reader034.vdocuments.us/reader034/viewer/2022052601/5589e1b2d8b42a6d2c8b4658/html5/thumbnails/3.jpg)
Hardware & Software Details of Junun Mark III Robot
![Page 4: Theory of Computation (Fall 2014): Line Following Automaton for Junun Mark III Robot](https://reader034.vdocuments.us/reader034/viewer/2022052601/5589e1b2d8b42a6d2c8b4658/html5/thumbnails/4.jpg)
Follow Line Start to End
Line Following Problem
![Page 5: Theory of Computation (Fall 2014): Line Following Automaton for Junun Mark III Robot](https://reader034.vdocuments.us/reader034/viewer/2022052601/5589e1b2d8b42a6d2c8b4658/html5/thumbnails/5.jpg)
Follow Line & Avoid Obstacles
Line Following Problem
![Page 6: Theory of Computation (Fall 2014): Line Following Automaton for Junun Mark III Robot](https://reader034.vdocuments.us/reader034/viewer/2022052601/5589e1b2d8b42a6d2c8b4658/html5/thumbnails/6.jpg)
Junun Mark III Robot
This robot has the 16f84a chip. The chip runs programs written in 16f84a Assembler.
![Page 7: Theory of Computation (Fall 2014): Line Following Automaton for Junun Mark III Robot](https://reader034.vdocuments.us/reader034/viewer/2022052601/5589e1b2d8b42a6d2c8b4658/html5/thumbnails/7.jpg)
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
![Page 8: Theory of Computation (Fall 2014): Line Following Automaton for Junun Mark III Robot](https://reader034.vdocuments.us/reader034/viewer/2022052601/5589e1b2d8b42a6d2c8b4658/html5/thumbnails/8.jpg)
What Does This Program Do?
![Page 9: Theory of Computation (Fall 2014): Line Following Automaton for Junun Mark III Robot](https://reader034.vdocuments.us/reader034/viewer/2022052601/5589e1b2d8b42a6d2c8b4658/html5/thumbnails/9.jpg)
16f84a Assembler Execution
Spot1 Spot2 W
movlw D'5'
BEFORE:
AFTER:
Spot1 Spot2
5
W
![Page 10: Theory of Computation (Fall 2014): Line Following Automaton for Junun Mark III Robot](https://reader034.vdocuments.us/reader034/viewer/2022052601/5589e1b2d8b42a6d2c8b4658/html5/thumbnails/10.jpg)
16f84a Assembler Execution
5
Spot1 Spot2 W
movwf Spot1
BEFORE:
AFTER: 5
Spot1 Spot2
5
W
![Page 11: Theory of Computation (Fall 2014): Line Following Automaton for Junun Mark III Robot](https://reader034.vdocuments.us/reader034/viewer/2022052601/5589e1b2d8b42a6d2c8b4658/html5/thumbnails/11.jpg)
16f84a Assembler Execution
5 5
Spot1 Spot2 W
movlw D’2’
BEFORE:
AFTER: 5
Spot1 Spot2
2
W
![Page 12: Theory of Computation (Fall 2014): Line Following Automaton for Junun Mark III Robot](https://reader034.vdocuments.us/reader034/viewer/2022052601/5589e1b2d8b42a6d2c8b4658/html5/thumbnails/12.jpg)
16f84a Assembler Execution
5 2
Spot1 Spot2 W
addwf Spot1,W
BEFORE:
AFTER: 5
Spot1 Spot2
7
W
![Page 13: Theory of Computation (Fall 2014): Line Following Automaton for Junun Mark III Robot](https://reader034.vdocuments.us/reader034/viewer/2022052601/5589e1b2d8b42a6d2c8b4658/html5/thumbnails/13.jpg)
Example: 16f84a Assembler
5 7
Spot1 Spot2 W
movwf Spot2
BEFORE:
AFTER: 5
Spot1
7
Spot2
7
W
![Page 14: Theory of Computation (Fall 2014): Line Following Automaton for Junun Mark III Robot](https://reader034.vdocuments.us/reader034/viewer/2022052601/5589e1b2d8b42a6d2c8b4658/html5/thumbnails/14.jpg)
Example: 16f84a Assembler
5 7 7
Spot1 Spot2 W
movlw D’3’
BEFORE:
AFTER: 5
Spot1
7
Spot2
3
W
![Page 15: Theory of Computation (Fall 2014): Line Following Automaton for Junun Mark III Robot](https://reader034.vdocuments.us/reader034/viewer/2022052601/5589e1b2d8b42a6d2c8b4658/html5/thumbnails/15.jpg)
Example: 16f84a Assembler
5 7 3
Spot1 Spot2 W
subwf Spot2,W
BEFORE:
AFTER: 5
Spot1
7
Spot2
4
W
![Page 16: Theory of Computation (Fall 2014): Line Following Automaton for Junun Mark III Robot](https://reader034.vdocuments.us/reader034/viewer/2022052601/5589e1b2d8b42a6d2c8b4658/html5/thumbnails/16.jpg)
Example: 16f84a Assembler
5 7 4
Spot1 Spot2 W
movwf Spot1
BEFORE:
AFTER: 4
Spot1
7
Spot2
4
W
![Page 17: Theory of Computation (Fall 2014): Line Following Automaton for Junun Mark III Robot](https://reader034.vdocuments.us/reader034/viewer/2022052601/5589e1b2d8b42a6d2c8b4658/html5/thumbnails/17.jpg)
Example: 16f84a Assembler
4 7 4
Spot1 Spot2 W
clrw
BEFORE:
AFTER: 4
Spot1
7
Spot2
0
W
![Page 18: Theory of Computation (Fall 2014): Line Following Automaton for Junun Mark III Robot](https://reader034.vdocuments.us/reader034/viewer/2022052601/5589e1b2d8b42a6d2c8b4658/html5/thumbnails/18.jpg)
Example: 16f84a Assembler
4 7 0
Spot1 Spot2 W
clrf Spot1
BEFORE:
AFTER: 0
Spot1
7
Spot2
0
W
![Page 19: Theory of Computation (Fall 2014): Line Following Automaton for Junun Mark III Robot](https://reader034.vdocuments.us/reader034/viewer/2022052601/5589e1b2d8b42a6d2c8b4658/html5/thumbnails/19.jpg)
Example: 16f84a Assembler
0 7 0
Spot1 Spot2 W
clrf Spot2
BEFORE:
AFTER: 0
Spot1
0
Spot2
0
W
![Page 20: Theory of Computation (Fall 2014): Line Following Automaton for Junun Mark III Robot](https://reader034.vdocuments.us/reader034/viewer/2022052601/5589e1b2d8b42a6d2c8b4658/html5/thumbnails/20.jpg)
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
![Page 21: Theory of Computation (Fall 2014): Line Following Automaton for Junun Mark III Robot](https://reader034.vdocuments.us/reader034/viewer/2022052601/5589e1b2d8b42a6d2c8b4658/html5/thumbnails/21.jpg)
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
![Page 22: Theory of Computation (Fall 2014): Line Following Automaton for Junun Mark III Robot](https://reader034.vdocuments.us/reader034/viewer/2022052601/5589e1b2d8b42a6d2c8b4658/html5/thumbnails/22.jpg)
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
![Page 23: Theory of Computation (Fall 2014): Line Following Automaton for Junun Mark III Robot](https://reader034.vdocuments.us/reader034/viewer/2022052601/5589e1b2d8b42a6d2c8b4658/html5/thumbnails/23.jpg)
Line Following
How can we make Mark III follow
a black line on the floor?
![Page 24: Theory of Computation (Fall 2014): Line Following Automaton for Junun Mark III Robot](https://reader034.vdocuments.us/reader034/viewer/2022052601/5589e1b2d8b42a6d2c8b4658/html5/thumbnails/24.jpg)
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.
![Page 25: Theory of Computation (Fall 2014): Line Following Automaton for Junun Mark III Robot](https://reader034.vdocuments.us/reader034/viewer/2022052601/5589e1b2d8b42a6d2c8b4658/html5/thumbnails/25.jpg)
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
![Page 26: Theory of Computation (Fall 2014): Line Following Automaton for Junun Mark III Robot](https://reader034.vdocuments.us/reader034/viewer/2022052601/5589e1b2d8b42a6d2c8b4658/html5/thumbnails/26.jpg)
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
![Page 27: Theory of Computation (Fall 2014): Line Following Automaton for Junun Mark III Robot](https://reader034.vdocuments.us/reader034/viewer/2022052601/5589e1b2d8b42a6d2c8b4658/html5/thumbnails/27.jpg)
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
![Page 28: Theory of Computation (Fall 2014): Line Following Automaton for Junun Mark III Robot](https://reader034.vdocuments.us/reader034/viewer/2022052601/5589e1b2d8b42a6d2c8b4658/html5/thumbnails/28.jpg)
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
![Page 29: Theory of Computation (Fall 2014): Line Following Automaton for Junun Mark III Robot](https://reader034.vdocuments.us/reader034/viewer/2022052601/5589e1b2d8b42a6d2c8b4658/html5/thumbnails/29.jpg)
Line Following in JAL
![Page 30: Theory of Computation (Fall 2014): Line Following Automaton for Junun Mark III Robot](https://reader034.vdocuments.us/reader034/viewer/2022052601/5589e1b2d8b42a6d2c8b4658/html5/thumbnails/30.jpg)
JAL Code: Required INCLUDEs
include 16f877_20include jlibinclude markiii
![Page 31: Theory of Computation (Fall 2014): Line Following Automaton for Junun Mark III Robot](https://reader034.vdocuments.us/reader034/viewer/2022052601/5589e1b2d8b42a6d2c8b4658/html5/thumbnails/31.jpg)
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
![Page 32: Theory of Computation (Fall 2014): Line Following Automaton for Junun Mark III Robot](https://reader034.vdocuments.us/reader034/viewer/2022052601/5589e1b2d8b42a6d2c8b4658/html5/thumbnails/32.jpg)
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
![Page 33: Theory of Computation (Fall 2014): Line Following Automaton for Junun Mark III Robot](https://reader034.vdocuments.us/reader034/viewer/2022052601/5589e1b2d8b42a6d2c8b4658/html5/thumbnails/33.jpg)
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
![Page 34: Theory of Computation (Fall 2014): Line Following Automaton for Junun Mark III Robot](https://reader034.vdocuments.us/reader034/viewer/2022052601/5589e1b2d8b42a6d2c8b4658/html5/thumbnails/34.jpg)
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
![Page 35: Theory of Computation (Fall 2014): Line Following Automaton for Junun Mark III Robot](https://reader034.vdocuments.us/reader034/viewer/2022052601/5589e1b2d8b42a6d2c8b4658/html5/thumbnails/35.jpg)
References
● Mark III User Guide● Line Following Competition