Distance covered by wheels and the angle it turns by (physics and robotics)

236 Views Asked by At

Let me try and describe what I'm working on.

I'm trying to code the controller for a vacuum cleaning robot. The entire project is done within the Webots platform. How it works is that when the robot hits a wall, it turns by a random angle and continues cleaning the house.

The issue: what I found was that the amount it turns by is inaccurate. If I specify for it to turn by 90 degrees, it only turns by 60. If I specify for it to turn by 360 degrees, it only turns by 240 or so (visual guesstimation).

I found a workaround - a temporary workaround. I found that multiplying the angle by a certain amount (1.2275) will turn the angle very close to the real angle specified in the question. So if I specify the angle to turn as 180, and multiply that with 1.2275, I get a value that is probably 175 or 177 (again from visual guesstimation).

The problem is that this error stacks up over time. So initially it might be an offset of just 2-3 degrees, which is nothing, but over 30 minutes of running the simulation it might build to relatively high numbers. This is unacceptable.

I asked a friend and he suggested that I scale the offset as the simulation progresses so that the offset scales with the error, but I feel this is a temporary workaround.

I would appreciate some help with the physics of it all as I don't really understand or know much about the mechanical field it works in. Any help would be appreciated.

Provided below is the code for the turn function.

static void turn(double angle) {
    double l_offset = wb_position_sensor_get_value(left_position_sensor);
    double r_offset = wb_position_sensor_get_value(right_position_sensor);
    double orient;

    stop();

    angle = angle * ANGLE_OFFSET;   //the important part
    double neg = (angle < 0.0) ? -1.0 : 1.0;

    step();

    wb_motor_set_velocity(left_motor,   neg * HALF_SPEED);
    wb_motor_set_velocity(right_motor, -neg * HALF_SPEED);

    do {
        double l  = wb_position_sensor_get_value(left_position_sensor) - l_offset;
        double r  = wb_position_sensor_get_value(right_position_sensor) - r_offset;
        double dl = l * WHEEL_RADIUS;  // distance covered by left wheel in meter
        double dr = r * WHEEL_RADIUS;  // distance covered by right wheel in meter

        orient = neg * (dl - dr) / AXLE_LENGTH; // delta orientation in radian

        step();
    } while (orient < neg * angle);

    stop();
    step();
}

Let me provide some explanation for the code. angle obviously specifies the angle to turn the robot by. The second line shows the workaround that I'm currently using. Reading through the next few lines you can see that the robot turns by moving the left wheel backwards, and the right wheel forwards. It continuously gets the distance covered by the wheels and checks for a condition. When that condition is true, it stops turning.

My guess is that there might be something wrong in orient = neg * (dl - dr) / AXLE_LENGTH; // delta orientation in radian this line. Any tips? Maybe someone who can verify if the physics/mechanics aspect of it is correct?

1

There are 1 best solutions below

3
On

Can you segment the cause of the discrepancy between the desired angle and the actual (visual) angle? I seems diving in and fixing that would be a better use of time than patching a patch.