-
Notifications
You must be signed in to change notification settings - Fork 0
/
line_follow.m
46 lines (45 loc) · 1.36 KB
/
line_follow.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
function [right_motor, left_motor] = line_follow(right, middle, left, mode, speed, scanspeed)
persistent time
if ~exist ("time","var")
time = 0;
end
if mode == 1
if left == 0 && middle == 1 && right == 0
%Straight
right_motor = speed;
left_motor = speed;
elseif left == 1 && middle == 1 && right == 0
%RightSlight
right_motor = speed;
left_motor = speed/2;
elseif left == 1 && middle == 0 && right == 0
%Right
right_motor = speed;
left_motor = -speed;
elseif left == 0 && middle == 1 && right == 1
%LeftSlight
right_motor = speed/2;
left_motor = speed;
elseif left == 0 && middle == 0 && right == 1
%Left
right_motor = speed;
left_motor = -speed;
else %scanning
time = time + 1;
if time < scanspeed %change to time off
%scan right
left_motor = scanspeed;
right_motor = -scanspeed;
elseif time >= scanspeed && time < 30 %change to time off
%scan left
left_motor = -scanspeed;
right_motor = scanspeed;
elseif time >= 30 && time < 40 %change to time off
left_motor = scanspeed;
right_motor = -scanspeed;
else
left_motor = -scanspeed;
right_motor = -scanspeed;
end
end
end