-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmapping.m
99 lines (93 loc) · 2.29 KB
/
mapping.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
function mapping()
global objectflag;
mylego = legoev3('USB');
mymotor1 = motor(mylego, 'C');
mysonicsensor = sonicSensor(mylego);
SPEED = 35;
resetRotation(mymotor1);
a = readRotation(mymotor1);
disp(a);
%%
i = 0;
while(a<=60)
%a = readRotation(mymotor1); disp(a);
mymotor1.Speed = SPEED;
start(mymotor1);
pause(0.01);
stop(mymotor1, 1);
%disp(dist);
%pause(0.4);
%dist2=readDistance(mysonicsensor);
%dist =(dist1+dist2)/2;
d1 = readDistance(mysonicsensor);disp(d1); pause(0.01);
d2 = readDistance(mysonicsensor);
d = (d1+d2)/2;
r = double(d * 100);
b = double(readRotation(mymotor1));
tab1(i+1,1) = r * (cosd(b));
tab1(i+1,2) = r * (sind(b));
i=i+1;
plot(tab1(:,2),tab1(:,1), ':');
drawnow
hold on
a = readRotation(mymotor1);
if (d1<0.15)
objectflag = 1; disp(d);
else
objectflag = 0;
end
end
stop(mymotor1, 1);
pause(1);
%%
while(a>=5)
a = readRotation(mymotor1);
mymotor1.Speed = -SPEED+20;
start(mymotor1);
a = readRotation(mymotor1);
end
stop(mymotor1, 1);
%%
j=0;
while(a>=-60)
%a = readRotation(mymotor1); disp(a);
mymotor1.Speed = -SPEED;
start(mymotor1);
pause(0.01);
stop(mymotor1, 1);
%disp(dist);
%pause(0.4);
%dist2=readDistance(mysonicsensor);
%dist =(dist1+dist2)/2;
d1 = readDistance(mysonicsensor); pause(0.01);
d2 = readDistance(mysonicsensor);
d = (d1+d2)/2;
r = double(d * 100);
b = double(readRotation(mymotor1));
tab2(j+1,1) = r * (cosd(b));
tab2(j+1,2) = r * (sind(b));
j=j+1;
plot(tab2(:,2),tab2(:,1), ':');
drawnow
hold on
a = readRotation(mymotor1);
end
stop(mymotor1, 1);
%%
%a = readRotation(mymotor1);
while(a<=-10)
a = readRotation(mymotor1);
mymotor1.Speed = SPEED-20;
start(mymotor1);
a = readRotation(mymotor1);
end
stop(mymotor1, 1);
%%
%polarplot(table(:,1), table (:,2));
%[x, y] = pol2cart(table(:,2), table(:,1));
tab = [tab2;tab1];
end
%%
%plot(tab(:,2), tab(:,1));
%plot(x,y, ':');
%hold on;