Robotics in Wall Collision Problem
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Ho Nam Ernest Yim
il 23 Feb 2018
Risposto: Cam Salzberger
il 23 Feb 2018
I was trying to do Path Planning for a robot by generating random nodes and linking them together. However, when nodes are linked, lines could be outside the map that I set. Therefore, I've tried to find intersections between the wall lines and nodes lines and delete them. The below shows my code of working :
map = [-30,0;-30,40;30,40;30,60;5,60;45,90;85,60;60,60;60,40;120,40;120,60;95,60;135,90;175,60;150,60;150,40;210,40;210,60;185,60;225,90;265,60;240,60;240,40;300,40;300,0]; %repeated features
botSim = BotSim(map,[0,0,0]); %sets up a botSim object a map, and debug mode on.
botSim.drawMap();
N_n = 20; % number of nodes
N = zeros(N_n,2);
a = size(map);
for i = 1:a(1)
n_cor(i,1) = map(i,1);
n_cor(i,2) = map(i,2);
L_w = line(n_cor(i,1),n_cor(i,2));
for i = 1:N_n
q = botSim.getRndPtInMap(10)';
N(i,:) = q;
plot(N(:,1),N(:,2),'o')
plot(N(:,1),N(:,2),'-')
L_n = line(N(:,1),N(:,2));
hold on
end
if L_w == L_n
L_n = [];
end
end
With the above code, I couldn't manage to delete those lines which intersect with walls. Can I know why and will there be an easier/efficient way to work on this?? Thank you
0 Commenti
Risposta accettata
Cam Salzberger
il 23 Feb 2018
It looks like the logic that you are using to see if the lines are intersecting is simply comparing the handles to the graphics objects. Remember that (unless you have overloaded it), the line function creates the graphics object and returns a handle to it. That handle contains information about the line, but direct comparisons to different lines will always return false.
It also looks like you have it set to simply set the variable to empty if the lines are equal. This will not delete the line, just change the value of the variable. To delete the line, use the delete method.
Here are some suggestions for ways to check if the line segments intersect. Then you can just check the path line against each wall.
-Cam
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Robotics in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!