机器人在碰撞时越过边界,而不是在实施粒子过滤器时反弹 [英] Robot crosses boundary on collision rather than bounce back while implementing particle filter
问题描述
我编写了以下代码,试图在其中创建粒子过滤器。我面临的问题是,即使在使用相交方法和其他条件后,机器人有时也会重叠障碍物。而且,它在一次又一次地与该角摆动之后,通过左上角超出了边界。
I have written the following code, where I am trying to create a particle filter. The problem I am facing is that even after using intersects method and other conditions, the robot sometimes overlaps the obstacles. Moreover, it goes out of boundary through upper left corner after wobbling again and again with the corner.
我检查碰撞,然后看是否有碰撞我
I check for the collisions and then if it seems there is a collision I move the robot by amount x in the reverse direction.
我通过以下方法计算数量x,其中x表示当前位置。
I calculate amount x by the following method, where x means current position.
public void setXPosition_robot(int x)
{
double distance=0;
distance = unit_moved + randomDouble(0, forwardNoise);
robot_x= (int) (x + Math.sin(Math.toRadians(robot_orientation))*distance);
//System.out.println("Robot_X:"+robot_x);
}
我正在使用以下代码检查冲突:
I am using the following code to check the collisions:
private void adjustRobotOrientation(Graphics2D g)
{
int x=robot_x;
int y=robot_y;
if((x<0)&&(y<0))
{
robot_orientation=robot_orientation+randomDouble(160, 180);
}
if((x>620)||((y>395))||((x<1))||((y<1)))
{
robot_orientation=robot_orientation+randomDouble(160, 220);
}
}
private void collisionAvoidanceRobot(int x, int y, int r)
{
boolean collide1=false;
boolean collide2=false;
boolean collide3=false;
boolean collide4=false;
boolean collide5=false;
boolean collide6=false;
x+=unit_moved;
y+=unit_moved;
Shape collisionrobot=new Ellipse2D.Double(x,y,r,r);
collide1=collisionrobot.intersects(obst1);
if(collide1)
{
robot_orientation=robot_orientation+randomDouble(160, 220);
}
collide2=collisionrobot.intersects(obst2);
if(collide2)
{
robot_orientation=robot_orientation+randomDouble(160, 220);
}
collide3=collisionrobot.intersects(obst3);
if(collide3)
{
robot_orientation=robot_orientation+randomDouble(160, 220);
}
collide4=collisionrobot.intersects(obst4);
if(collide4)
{
robot_orientation=robot_orientation+randomDouble(160, 220);
}
collide5=collisionrobot.intersects(obst5);
if(collide5)
{
robot_orientation=robot_orientation+randomDouble(160, 220);
}
collide6=collisionrobot.intersects(obst6);
if(collide6)
{
robot_orientation=robot_orientation+randomDouble(160, 220);
}
}
如果要查看,完整的代码位于两个文件中:
1. http://pastebin.com/ZYfSzptc (主类)
2. http://pastebin.com/hqTTyq5n
If you want to see, the complete code is in two files: 1. http://pastebin.com/ZYfSzptc (main class) 2. http://pastebin.com/hqTTyq5n
推荐答案
如果机器人的速度导致其在时钟滴答之间移动 past 一个障碍,则不会检测到碰撞。您可以
If a robot's velocity causes it to move past an obstacle between clock ticks, no collision will be detected. You can
-
使用更细的刻度线和更大的对象来排除效果,如
KineticModel
在此处引用。
如此处所示,预期效果并对其进行补偿。
Anticipate the effect and compensate for it, as shown here.
两个示例都使用引用的矢量方法此处。
Both examples use the vector approach cited here.
这篇关于机器人在碰撞时越过边界,而不是在实施粒子过滤器时反弹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!