Question
Please explain the following code to move a robot in a certain path avoiding collisions and please convert it into C language code: I need
Please explain the following code to move a robot in a certain path avoiding collisions and please convert it into C language code:
I need to understand it by calculations or pictorial representation
m = 50;
n = 50;
goal = [25 25];
obstacles=[14 24; 14 25; 14 26; 15 24; 15 25; 15 26; 16 24; 16 25; 16 26
34 24; 34 25; 34 26; 35 24; 35 25; 35 26; 36 24; 36 25; 36 26];
hi = 100;
lo = 0;
eps = 0.01;
room1 = .5*(hi+lo)*ones([m,n]);
room1(:,1:2) = hi;
room1(:,n-1:n) = hi;
room1(1:2,:) = hi;
room1(m-1:m,:) = hi;
room2 = room1;
[b,c] = size(goal);
for i = 1:1:b
room1(goal(i,1),goal(i,2)) = lo;
end
[d,e] = size(obstacles);
if d ~= 0
for i = 1:1:d
room1(obstacles(i,1),obstacles(i,2)) = hi;
end
end
count = 0;
while 1
for i = 2:1:m-1
for j = 2:1:n-1
room2(i,j) = room1(i-1,j)+room1(i+1,j)+room1(i,j-1)+room1(i,j+1);
end
end
room2=room2/4;
room2(:,1:2) = hi;
room2(:,n-1:n) = hi;
room2(1:2,:) = hi;
room2(m-1:m,:) = hi;
for i = 1:1:b
room2(goal(i,1),goal(i,2)) = lo;
end
if d ~= 0
for i = 1:1:d
room2(obstacles(i,1),obstacles(i,2)) = hi;
end
end
if abs(room2-room1) <= eps
break;
end
room1 = room2;
count = count+1;
end
count
surf(room1);
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started