Borrar filtros
Borrar filtros

How can type the right conditioning parameters from point A to point B and from B to C in my example

2 visualizaciones (últimos 30 días)
I have a homework problem in which i have a robot to cover the area of a room in the least time as possible.
I have developed a code with x and y conditioning to follow a specific path.
Problem: I'm having trouble to get mi "robot" from point B to point C and from point C to pont A. The purpouse of getting back to pint A is so that i can finally place mi initial robot variables to be random in the available area which in the actual code are fixed.
Also I'm asked to add a variant for the path using 5° bouncing from the walls, but i currently have no idea how to implement this on my code.
Do you guys have any tips for this as well?
I will be adding the image that I used to create the grid as well as I you will need it to run the code
Representation image of Point A, B, C:
My code is the following:
clc;
clear;
% Binary occupancy map from an image.
image = imread('prueba11.png');
grayimage = rgb2gray(image);
grid1 = grayimage < 0.5;
gridx = binaryOccupancyMap(grid1,20);
show(gridx);
Sweeping robot initial variables
%startLocation = [0.6 3.8];
px0 = 0.45; % Initial x
py0 = 3.85; % Initial y
% Plot the start and end locations
hold on
plot(px0,py0,'k.');
viscircles([px0,py0],0.15,'Color','r');
hold off
vel = 40
vel = 40
dir = 1;
Adding grid
grid1 = zeros(999,3);
k = 0; % Contador x
for i = 0.2:0.15:4.5
for j = 0.6:0.2:3.8
k = k + 1;
grid1(k,1) = i;
grid1(k,2) = j;
end
end
hold on
plot(grid1(:,1),grid1(:,2),'*')
axis([0 4.55 0 4]);
axis equal;
grid on;
TESTS
% Simulation
for t = 0:1:344 % Number of steps (we have to add more to reach further)
% Calculating new position
px = px0;
py = py0 - 0.15*(dir);
% South-North bounce
if (((py < 1.45 && px == 0.45)) || ((py < 1.05 && px == 0.75)) || ((py < 0.75 && px == 01.05)) || ...
((py < 0.75) && (1.25 < px && px < 1.35)) || ((py < 0.75) && (1.64 < px && px < 1.66)) || ...
((py < 0.75) && (1.94 < px && px < 1.96)) || ((py < 0.75) && (2.24 < px && px < 2.26)) || ...
((py < 0.75) && (2.54 < px && px < 2.56)) || ((py < 1.1) && (2.84 < px && px < 2.86)) || ...
((py < 1.1) && (3.14 < px && px < 3.16)) || ((py < 1.1) && (3.44 < px && px < 3.46)) || ...
((py < 1.1) && (3.74 < px && px < 3.76)) || ((py < 1.1) && (4.04 < px && px < 4.06)))
px = px + 0.15;
dir = -1;
end
% North-South bounce
if (((3.85 < py) && (px == 0.60)) || ((3.1 < py) && (px == 0.90)) || ((3.1 < py) && (px == 1.20)) || ...
((1.95 < py) && (1.49 < px && px < 1.51)) || ((1.95 < py) && (1.79 < px && px < 1.81)) || ...
((1.95 < py) && (2.09 < px && px < 2.11)) || ((1.95 < py) && (2.39 < px && px < 2.41)) || ...
((1.95 < py) && (2.69 < px && px < 2.71)) || ((1.95 < py) && (2.99 < px && px < 3.01)) || ...
((3.1 < py) && (3.29 < px && px < 3.31)) || ((3.1 < py) && (3.59 < px && px < 3.61)) || ...
((3.85 < py) && (3.89 < px && px < 3.91)) || ((3.85 < py) && (4.19 < px && px < 4.21)))
px = px + 0.15;
dir = 1;
% Here i want to add the conditoning from point B to c
% Here i want to add the conditioning from point C to A
end
%pause (0.05) %uncomment to have an animation of the moving robot
% coordinates
px0 = px;
py0 = py;
% Record "robot position"
plot(px,py,'k*');
viscircles([px,py],0.15,'Color','g');
% Distance calculation
dist = sqrt(((grid1(:,1)-px).^2)+((grid1(:,2)-py).^2));
% Finding covered area
l = find(dist < 0.15);
% Recording traveled spaces
grid1(l,3) = 1;
% adding traveled spaces
areacovered = sum(grid1(:,3));
% Percentage convertion
Percent_Cleaned = (areacovered / 330);
% cleaning percentage conditioning
if (Percent_Cleaned > 0.95)
break
end
end
Percent_Cleaned, t
Percent_Cleaned = 0.9394
t = 344

Respuestas (0)

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Productos


Versión

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by