Robotics in Wall Collision Problem
조회 수: 2 (최근 30일)
이전 댓글 표시
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
채택된 답변
Cam Salzberger
2018년 2월 23일
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Robotics에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!