-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdirection.m
38 lines (36 loc) · 965 Bytes
/
direction.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
% Calculate velocity direction based on position and angle
% alfa - current robot orientation
% wheel_now - wheel coordinates x,y from this iteration
% wheel_last - wheel coordinates x,y from last iteration
% dir - 1 - forward -1 - backward
function dir = direction(alfa, wheel_now, wheel_last)
if alfa < 0
alfa = alfa + 360;
end
angle = mod(alfa, 360);
if (angle >= 45) && (angle < 135)
if wheel_now(2) >= wheel_last(2)
dir = 1;
else
dir = -1;
end
elseif (angle >= 135) && (angle < 225)
if wheel_now(1) <= wheel_last(1)
dir = 1;
else
dir = -1;
end
elseif (angle >= 225) && (angle < 315)
if wheel_now(2) <= wheel_last(2)
dir = 1;
else
dir = -1;
end
else
if wheel_now(1) >= wheel_last(1)
dir = 1;
else
dir = -1;
end
end
end