2 edited body
source | link

Your function calculateRange() uses a variable robot_orientation which I cannot see from your code snippedssnippets that it is set or changed.

I would expect something like:

double particle_orientation = particleListOrientation.get(index);

inside your function measurementProbability() and then call calculateRange() with that additional parameter.

private int calculateRange(double x, double y, double robot_orientation)
{
    double Vx = x, double Vy = y;
    int pace = 2;
    int counter = 0;
    while(robotIsWithinBoundary(Vx, Vy))
    {
        Vx += pace* Math.sin(Math.toRadians(robot_orientation));
        Vy += pace* Math.cos(Math.toRadians(robot_orientation));
        counter++;
        Line2D line1 = new Line2D.Double(x,y,Vx,Vy);
        if(line1.intersects(obst1))
        {
            break;
        }
        if(line1.intersects(obst2))
        {
            break;
        }

    }
    return counter*pace;
}

Your function calculateRange() uses a variable robot_orientation which I cannot see from your code snippeds that it is set or changed.

I would expect something like:

double particle_orientation = particleListOrientation.get(index);

inside your function measurementProbability() and then call calculateRange() with that additional parameter.

private int calculateRange(double x, double y, double robot_orientation)
{
    double Vx = x, double Vy = y;
    int pace = 2;
    int counter = 0;
    while(robotIsWithinBoundary(Vx, Vy))
    {
        Vx += pace* Math.sin(Math.toRadians(robot_orientation));
        Vy += pace* Math.cos(Math.toRadians(robot_orientation));
        counter++;
        Line2D line1 = new Line2D.Double(x,y,Vx,Vy);
        if(line1.intersects(obst1))
        {
            break;
        }
        if(line1.intersects(obst2))
        {
            break;
        }

    }
    return counter*pace;
}

Your function calculateRange() uses a variable robot_orientation which I cannot see from your code snippets that it is set or changed.

I would expect something like:

double particle_orientation = particleListOrientation.get(index);

inside your function measurementProbability() and then call calculateRange() with that additional parameter.

private int calculateRange(double x, double y, double robot_orientation)
{
    double Vx = x, double Vy = y;
    int pace = 2;
    int counter = 0;
    while(robotIsWithinBoundary(Vx, Vy))
    {
        Vx += pace* Math.sin(Math.toRadians(robot_orientation));
        Vy += pace* Math.cos(Math.toRadians(robot_orientation));
        counter++;
        Line2D line1 = new Line2D.Double(x,y,Vx,Vy);
        if(line1.intersects(obst1))
        {
            break;
        }
        if(line1.intersects(obst2))
        {
            break;
        }

    }
    return counter*pace;
}
1
source | link

Your function calculateRange() uses a variable robot_orientation which I cannot see from your code snippeds that it is set or changed.

I would expect something like:

double particle_orientation = particleListOrientation.get(index);

inside your function measurementProbability() and then call calculateRange() with that additional parameter.

private int calculateRange(double x, double y, double robot_orientation)
{
    double Vx = x, double Vy = y;
    int pace = 2;
    int counter = 0;
    while(robotIsWithinBoundary(Vx, Vy))
    {
        Vx += pace* Math.sin(Math.toRadians(robot_orientation));
        Vy += pace* Math.cos(Math.toRadians(robot_orientation));
        counter++;
        Line2D line1 = new Line2D.Double(x,y,Vx,Vy);
        if(line1.intersects(obst1))
        {
            break;
        }
        if(line1.intersects(obst2))
        {
            break;
        }

    }
    return counter*pace;
}