-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMATLAB CODE
More file actions
32 lines (31 loc) · 835 Bytes
/
MATLAB CODE
File metadata and controls
32 lines (31 loc) · 835 Bytes
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
clear all;
a = arduino('COM7', 'Uno', 'Libraries', {'Ultrasonic', 'Servo'});
sensor = ultrasonic(a, 'D12', 'D13');
servo_motor = servo(a, 'D3');
i = 1;
table = zeros(180,2);
for theta = 0 : 1/180 : 1
writePosition(servo_motor, theta);
dist1 = readDistance(sensor);
pause(.04);
dist2 = readDistance(sensor);
dist = (dist1+dist2)/2;
table(i,1) = (i-1);
table(i,2) = round(dist * 100,2);
i = i + 1;
end
j = 1;
for theta = 1 : -1/180 : 0
writePosition(servo_motor, theta);
dist1 = readDistance(sensor);
pause(.04);
dist2 = readDistance(sensor);
dist = (dist1+dist2)/2;
table(i-j,2) = (table(i-j,2) + round(dist * 100,2))/2;
j = j + 1;
end
polarplot (table(:,1)*pi/180, table (:,2));
disp(polarplot (table(:,1)*pi/180, table (:,2)))
title('Map of the Environment');
thetalim([0 180]);
grid on;