clc
clear variables
close all
fid=fopen('hw3_task2.txt','r');
hr_deg=[60 30 0 330 300 270 240 210 180 150 120 90];
k=1;
x_start=fscanf(fid,'%f',1);
y_start=fscanf(fid,'%f',1);
x_s=fscanf(fid,'%f',1);
y_s=fscanf(fid,'%f',1);
while k<=24
dist(k)=fscanf(fid,'%f',1);
deg(k)=fscanf(fid,'%f',1);
D(k)=fscanf(fid,'%f',1);
S(k)=fscanf(fid,'%f',1);
k=k+1;
end
x_c=[x_start];
y_c=[y_start];
k=1;
while k<=24
x_c(k+1)=dist(k)*cosd(hr_deg(deg(k)));
y_c(k+1)=dist(k)*sind(hr_deg(deg(k)));
k=k+1;
end
k=1;
hold on
x=x_c(1);
y=y_c(1);
hold on
plot(x,y,'go')
text(x,y,'Start')
while k<=25
x(k+1)=x(k)+x_c(k+1);
y(k+1)=y(k)+y_c(k+1);
plot([x(k) x(k+1)], [y(k) y(k+1)], 'b*-')
k=k+1;
end
k=1;
while k<=24
if (s(k)==1)
plot(x(k+1),y(k+1),'bd')
end
if (d(k)==1)
plot(x(k+1),y(k+1),'ms')
end
k=k+1;
end
plot(x(k),y(k),'g*')
text(x(k),y(k),'End')
grid on
xlabel('X Position')
ylabel('Y Position')
title('Robot Task 2')
axis([1 100 1 100]);
fclose(fid)