]> rtime.felk.cvut.cz Git - eurobot/public.git/blobdiff - src/robomon/RobomonAtlantis.cpp
robomon: More error prone hokuyo simulation
[eurobot/public.git] / src / robomon / RobomonAtlantis.cpp
index d48c466b4ba23cd602897efef0cecd3eafbd726e..379a47331eb3e85681214b511b0f0b170bf6ff47 100644 (file)
@@ -540,9 +540,7 @@ void RobomonAtlantis::simulateObstaclesHokuyo()
        for (i=0; i<HOKUYO_ARRAY_SIZE; i++) {
                wall_distance = distanceToWallHokuyo(i);
 
-               // TODO: Replace with function to calculate the real distance to the simulated cylinder
-               distance = realDistanceToObstacleHokuyo(i, simulatedObstacle, SIM_OBST_SIZE_M);
-               //distance = distanceToObstacleHokuyo(i, simulatedObstacle, SIM_OBST_SIZE_M/*meters*/);
+               distance = distanceToCircularObstacleHokuyo(i, simulatedObstacle, SIM_OBST_SIZE_M);
                if (wall_distance < distance)
                        distance = wall_distance;
                hokuyo[i] = distance*1000;
@@ -904,7 +902,7 @@ double RobomonAtlantis::distanceToWallHokuyo(int beamnum)
        return min_distance;
 }
 
-double RobomonAtlantis::realDistanceToObstacleHokuyo(int beamnum, Point obstacle, double obstacleSize)
+double RobomonAtlantis::distanceToCircularObstacleHokuyo(int beamnum, Point center, double diameter)
 {
        struct robot_pos_type e = orte.est_pos_best;
        double sensor_a;
@@ -923,18 +921,21 @@ double RobomonAtlantis::realDistanceToObstacleHokuyo(int beamnum, Point obstacle
        double distance = sensorRange;
        double angle;
 
-       angle = sensor.angleTo(obstacle) - sensor_a;
+       angle = sensor.angleTo(center) - sensor_a;
        angle = fmod(angle, 2.0*M_PI);
        if (angle > +M_PI) angle -= 2.0*M_PI;
        if (angle < -M_PI) angle += 2.0*M_PI;
        angle = fabs(angle);
 
        double k = tan(sensor_a);
-       double r = obstacleSize / 2.0;
+       double r = diameter / 2.0;
 
        double A = 1 + k*k;
-       double B = 2 * (sensor.y*k - obstacle.x - k*k*sensor.x - obstacle.y*k);
-       double C = obstacle.x*obstacle.x + obstacle.y*obstacle.y + k*k*sensor.x*sensor.x - 2*sensor.y*k*sensor.x + sensor.y*sensor.y + 2*k*sensor.x*obstacle.y - 2*sensor.y*obstacle.y - r*r;
+       double B = 2 * (sensor.y*k - center.x - k*k*sensor.x - center.y*k);
+       double C = center.x*center.x + center.y*center.y +
+               k*k*sensor.x*sensor.x - 2*sensor.y*k*sensor.x +
+               sensor.y*sensor.y + 2*k*sensor.x*center.y -
+               2*sensor.y*center.y - r*r;
 
        double D = B*B - 4*A*C;
        
@@ -949,26 +950,16 @@ double RobomonAtlantis::realDistanceToObstacleHokuyo(int beamnum, Point obstacle
                double distance1 = sensor.distanceTo(ob1);
                double distance2 = sensor.distanceTo(ob2);
                distance = (distance1 < distance2) ? distance1 : distance2;
-       }
-
-       if (D == 0) {
+       } else if (D == 0) {
                Point ob;
                ob.x = -B / (2*A);
                ob.y = k * (ob.x - sensor.x) + sensor.y;
                distance = sensor.distanceTo(ob);
        }
-
-       if (angle < atan(obstacleSize/2.0 / distance)) {
-               // We can see the obstackle from here.
-               if (angle < M_PI/2.0) {
-                       distance = distance/cos(angle);
-               }
-               if (distance > sensorRange) {
-                       distance = sensorRange;
-               }
-       } else {
+       if (D < 0 || angle > atan(r / distance))
+               distance = sensorRange;
+       if (distance > sensorRange)
                distance = sensorRange;
-       }
 
        return distance;
 }