英文:
How to measure the distance for robot center to obstacles?
问题
I want to orient my robot based on the distance from the obstacle, but I do not know how to measure the distance from robot center to the obstacle surrounding.
英文:
I want to orient my robot based on the distance from the obstacle, but I do not know how to measure the distance from robot center to the obstacle surrounding.
答案1
得分: 0
1.- 获取/构建准确的地图
让我们开始将提供的地图二值化,并在随机位置放置一个点机器人,排除所有障碍点。
close all;clear all;clc
% 获取地图
A1=imread('001.jpg'); % 这是你所询问的地图
% figure;imshow(A1)
A2=~imbinarize(A1(:,:,1));
figure(1);
ax1=gca;imshow(A2)
[ny,nx]=size(A2);
[X,Y]=meshgrid(1:nx,1:ny);
% 障碍物
P1=[140 311; 153 311; 153 7; 140 7; 140 311]; % 140 311 153 7
P2=[374 491; 386 491; 386 186; 374 186; 374 491]; % 374 491 386 186
P3=[1 497; 496 497; 496 492; 1 492; 1 497]; % 1 497 496 492
P4=[1 6; 496 6; 496 1; 1 1; 1 6]; % 6 1 496 1
P5=[1 491; 3 491; 3 7; 1 7; 1 491]; % 左边框 1 491 3 7
P6=[492 491; 496 491; 496 7; 492 7; 492 491]; % 右边框 % 492 491
Pobst=[P1(:);P2(:);P3(:);P4(:);P5(:);P6(:)];
Nobst=6;
% 将障碍点重新排列
Pobst=reshape(Pobst,[size(P1,1),size(P1,2),Nobst]);
% 地图上机器人不能在的位置
[in1,on1]=inpolygon(X(:),Y(:),P1(:,1),P1(:,2));
[in2,on2]=inpolygon(X(:),Y(:),P2(:,1),P2(:,2));
[in3,on3]=inpolygon(X(:),Y(:),P3(:,1),P3(:,2));
Xout=X(~in1 & ~in2 & ~in3);
Yout=Y(~in1 & ~in2 & ~in3);
% 在随机位置放置机器人,排除障碍点
nP2=randi([1 numel(Xout)],1,1);
Pnet=[Xout(nP2) Yout(nP2)];
% Pnet=[47 365]; % 静态测试点
hold(ax1,'on')
plot(ax1,Pnet(1),Pnet(2),'or','LineStyle','none');
2.- 360度扫描
现在让我们进行360度射线扫描。
不使用角度,而是直接覆盖机器人所在位置的所有外围点。
Ns=2*size(A2,1)+2*size(A2,2)-4; % 外围点的数量
% 外围点定义,从左上角开始,然后顺时针
P0=[ones(1,size(A2,1)) 2:1:size(A2,2)-1 size(A2,2)*ones(1,size(A2,1)) size(A2,2)-1:-1:2; % x
1:1:size(A2,1) size(A2,1)*ones(1,size(A2,2)-2) size(A2,1):-1:1 ones(1,size(A2,2)-2)]';
PR=[0 0];
for k1=1:10:Ns
L2=floor(linspace(Pnet(2),P0(k1,1),max([Pnet(1) Pnet(2) abs(P0(k1,2)-Pnet(2)) abs(P0(k1,1)-Pnet(1)) ]) )); % x
L1=floor(linspace(Pnet(1),P0(k1,2),max([Pnet(1) Pnet(2) abs(P0(k1,2)-Pnet(2)) abs(P0(k1,1)-Pnet(1)) ]) )); % y
p1=1;
while A2(L2(p1),L1(p1))==0
p1=p1+1;
end
PR=[PR;L1(p1) L2(p1)]; % 记录外围点 [x y]
end
PR(1,:)=[];
变量 `PR` 包含了你所要求的点,针对特定机器人位置 `Pnet`。
快速检查所有射线和最近的障碍点是否正确
```matlab
for k2=1:10:Ns
plot(ax1,PR(k2,1),PR(k2,2),'r*')
plot(ax1,[Pnet(1) PR(k2,1)],[Pnet(2) PR(k2,2)],'g-')
end
3.- 对得到的外围点进行评论
在这一点上,对于特定的机器人位置 Pnet
,变量 PR
包含了所有最近的障碍点。
如此所做,PR
中的外围障碍点是机器人应该避开的硬障碍的第一个点/属于的点。
因此,机器人不应该考虑这一点,而是应该考虑第一个可用的点,也就是每条射线上离机器人更近的点,而不是障碍物的一部分。
4.- 不要使用机器人中心点来判断何时/在哪里/如何避开障碍物
在进行障碍物避让时,机器人的中心几乎没有任何用处。是的,你可以在某些计算中使用它,但仅将机器人看作一个点,你的机器人将撞到东西的机会非常大。
我的建议是:
4.1.- 找到机器人的最远点,而不是机器人的中心点
4.2.- 将机器人视为一个带有最远点
英文:
1.- GET/BUILD AN ACCURATE MAP
Let's start binarizing the supplied may and dropping a point bot on a random position excluding all obstacle points.
close all;clear all;clc
% get the map
A1=imread('001.jpg'); % this is your map in question
% figure;imshow(A1)
A2=~imbinarize(A1(:,:,1));
figure(1);
ax1=gca;imshow(A2)
[ny,nx]=size(A2);
[X,Y]=meshgrid(1:nx,1:ny);
% obstacles
P1=[140 311; 153 311; 153 7; 140 7; 140 311]; % 140 311 153 7
P2=[374 491; 386 491; 386 186; 374 186; 374 491]; % 374 491 386 186
P3=[1 497; 496 497; 496 492; 1 492; 1 497]; % 1 497 496 492
P4=[1 6; 496 6; 496 1; 1 1; 1 6]; % 6 1 496 1
P5=[1 491; 3 491; 3 7; 1 7; 1 491]; % left frame 1 491 3 7
P6=[492 491; 496 491; 496 7; 492 7; 492 491]; % right frame % 492 491
Pobst=[P1(:);P2(:);P3(:);P4(:);P5(:);P6(:)];
Nobst=6;
Po
bst=reshape(Pobst,[size(P1,1),size(P1,2),Nobst]);
% map points where bot cannot be
[in1,on1]=inpolygon(X(:),Y(:),P1(:,1),P1(:,2));
[in2,on2]=inpolygon(X(:),Y(:),P2(:,1),P2(:,2));
[in3,on3]=inpolygon(X(:),Y(:),P3(:,1),P3(:,2));
Xout=X(~in1 & ~in2 & ~in3);Yout=Y(~in1 & ~in2 & ~in3);
% dropping bot on random location, excluding obstacle points
nP2=randi([1 numel(Xout)],1,1);
Pnet=[Xout(nP2) Yout(nP2)];
% Pnet=[47 365]; % static test point
hold(ax1,'on')
plot(ax1,Pnet(1),Pnet(2),'or','LineStyle','none');
2.- 360º SWEEP
Now let's do a 360º ray sweep.
NOT using angles BUT directly covering all outer perimeter points, from wherever the bot is located.
Ns=2*size(A2,1)+2*size(A2,2)-4; % amount outer perimeter points
% outer perimeter defined starting top left corner and then CW
P0=[ones(1,size(A2,1)) 2:1:size(A2,2)-1 size(A2,2)*ones(1,size(A2,1)) size(A2,2)-1:-1:2; % x
1:1:size(A2,1) size(A2,1)*ones(1,size(A2,2)-2) size(A2,1):-1:1 ones(1,size(A2,2)-2)]'; % y
PR=[0 0];
for k1=1:10:Ns
L2=floor(linspace(Pnet(2),P0(k1,1),max([Pnet(1) Pnet(2) abs(P0(k1,2)-Pnet(2)) abs(P0(k1,1)-Pnet(1)) ]) )); % x
L1=floor(linspace(Pnet(1),P0(k1,2),max([Pnet(1) Pnet(2) abs(P0(k1,2)-Pnet(2)) abs(P0(k1,1)-Pnet(1)) ]) )); % y
p1=1;
while A2(L2(p1),L1(p1))==0
p1=p1+1;
end
PR=[PR;L1(p1) L2(p1)]; % logging perimeter point [x y]
end
PR(1,:)=[];
Variable PR
contains the points you are asking for, for a particular bot position Pnet
Quick check all rays and nearest obstacle points are ok
for k2=1:10:Ns
plot(ax1,PR(k2,1),PR(k2,2),'r*')
plot(ax1,[Pnet(1) PR(k2,1)],[Pnet(2) PR(k2,2)],'g-')
end
3.- Comment on Obtained Perimeter
At this point, for a particular bot position Pnet
the variable perimeter PR
contains all the closest obstacle points.
As here done, the perimeter obstacle points in PR
are the 1st point of/belonging to the hard obstacle that the boot should avoid.
Therefore the bot should NOT consider this point but the 1st one available, thius is, 1 pixel closer to the bot, along each ray, that is NOT part of any obstacle.
4.- Do not use the bot centre point to know when/where/how to avoid obstacles
When working out obstacle avoidance the centre of the bot is hardly ever of any use. Yes you can use it for some calculations
but the chances that just considering the bot a a point your bot is going to hit things.
My suggestion is to :
4.1.- find the furthermost point of the robot, not the centre of the robot
4.2.- assume the bot as a ball with radius that furthest point
4.3.- and then include an additional safety area around the ball, not the point that is your bot.
Yes again, you may actually want the bot to hit a surface, but if you do not control when your bot is not hitting things there's no way you are going to be able to know where/when/how to have it hitting any surface of choice ay time soon.
答案2
得分: -1
I think it might depend on how your robot moves. For instance, if your robot navigation algorithm guides the robot to move one direction at a time, (x then y, or y then x, along axes in XoY space), the Manhattan distance would be more appropriate, as shown in the picture below.
然而,如果您的机器人导航算法指导机器人一次只移动一个方向(先x然后y,或者先y然后x,在XoY空间的轴上),曼哈顿距离可能更合适,如下图所示。
The Yellow and Blue distances are the same, while the Green distance is the Euclidean distance that will be described below.
黄色和蓝色的距离是相同的,而绿色的距离是下面将要描述的欧几里得距离。
However, most modern robots may move in any direction rather than one at a time. But from point A to point B the straight line is the obvious best solution to save a great effort. Then, the Euclidean distance should be chosen, as shown below.
然而,大多数现代机器人可能一次可以沿任何方向移动,而不是一个方向。但从点A到点B,直线是明显的最佳解决方案,可以节省大量的工作。然后,应选择欧几里得距离,如下所示。
英文:
I think it might depend on how your robot moves. For instance, if your robot navigation algorithm guides the robot to move one direction at a time, (x then y, or y then x, along axes in XoY space), the Manhattan distance would be more appropriate, as shown in the picture below. The Yellow and Blue distances are the same, while the Green distance is the Euclidean distance that will be described below.
However, most modern robots may move in any direction rather than one at a time. But from point A to point B the straight line is the obvious best solution to save a great effort. Then, the Euclidean distance should be chosen, as shown below.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论