- #1
dtrent258
- 4
- 0
1. The problem statement.
Create a function in MATLAB for a simulation of a automated robot vacuum to avoid obstacles while cleaning an undisclosed floor plan. the floor plan which will be in the form of a matrix not known beforehand. The robot (represented by a value of 1) can move horizontally (left to right, down one, right to left...) or vertically (top to bottom, over one, bottom to top...), but the robot should "clean" 100% of the floor plan even if the surface has a value of a clean tile (represented by a 4). While traversing the matrix the robot will encounter dirty floor (represented by the value 3) as well as obstacles (represented by the value 0). when a dirty tile is encountered value will be changed to a "4". When an obstacle is encountered the robot should go around it instead of just skipping over, and then continue on cleaning. once the matrix is cleaned the robot will return to the charger (represented by a 2). I've some code written but can not seem to find a good way of avoiding obstacles and return to the same column or row I was on. If anyone has any suggestions it would be greatly appreciated. I've included a sample matrix just for me to practice on, the real matrix will be 30 rows by 25 columns. Values in the matrix are as follows:
1= robot
2= charger (always located at (2,2) in the matrix, also robot will always begin here as well)
3= dirty floor
4= clean floor
0= wall or obstacle (the perimeter of the matrix will always be a wall, but the interior will vary from matrix to matrix)
My code has the robot moving up and down. I have tried writing script to move the robot left or right depending on which way isn't blocked. but I have to do that for each time it hits an obstacle, plus I can't find a good way to return to the row or column that I was on.
a=xlsread('robmat');
p=size(a);
n=p(1);
m=p(2);
time=0; % time taken to clean(1 for clean, 5 for dirty)
bat=0; % battery life used ( +1 for every move)
for i=3:1:n-1;
for i=n-1:-1:2;
a
[fprintf('Time taken equals: %d seconds\n',time);]
[fprintf('Amount of battery charge used equals: %d\n',bat);]
Create a function in MATLAB for a simulation of a automated robot vacuum to avoid obstacles while cleaning an undisclosed floor plan. the floor plan which will be in the form of a matrix not known beforehand. The robot (represented by a value of 1) can move horizontally (left to right, down one, right to left...) or vertically (top to bottom, over one, bottom to top...), but the robot should "clean" 100% of the floor plan even if the surface has a value of a clean tile (represented by a 4). While traversing the matrix the robot will encounter dirty floor (represented by the value 3) as well as obstacles (represented by the value 0). when a dirty tile is encountered value will be changed to a "4". When an obstacle is encountered the robot should go around it instead of just skipping over, and then continue on cleaning. once the matrix is cleaned the robot will return to the charger (represented by a 2). I've some code written but can not seem to find a good way of avoiding obstacles and return to the same column or row I was on. If anyone has any suggestions it would be greatly appreciated. I've included a sample matrix just for me to practice on, the real matrix will be 30 rows by 25 columns. Values in the matrix are as follows:
1= robot
2= charger (always located at (2,2) in the matrix, also robot will always begin here as well)
3= dirty floor
4= clean floor
0= wall or obstacle (the perimeter of the matrix will always be a wall, but the interior will vary from matrix to matrix)
Homework Equations
My code has the robot moving up and down. I have tried writing script to move the robot left or right depending on which way isn't blocked. but I have to do that for each time it hits an obstacle, plus I can't find a good way to return to the row or column that I was on.
The Attempt at a Solution
a=xlsread('robmat');
p=size(a);
n=p(1);
m=p(2);
time=0; % time taken to clean(1 for clean, 5 for dirty)
bat=0; % battery life used ( +1 for every move)
for i=3:1:n-1;
for j=2;
if a(i,j)==3;
a(i,j)=4;
time=time+5;
bat=bat+1;
if a(i,j)==4;
time=time+1;
bat=bat+1;
end
end
end
endfor i=n-1:-1:2;
for j=3;
if a(i,j)==3;
a(i,j)=4;
time=time+5;
bat=bat+1;
if a(i,j)==4;
time=time+1;
bat=bat+1;
end
end
end
enda
[fprintf('Time taken equals: %d seconds\n',time);]
[fprintf('Amount of battery charge used equals: %d\n',bat);]
Attachments
Last edited: