Project

General

Profile

Revision dd065971

IDdd06597107703ab49d87799b117d5bc3d81c6c21
Parent da0e1359
Child e6633046, 9d9e04ba

Added by Alex Zirbel over 11 years ago

Fixed sonar out of range bug. Max range now at 9.144 m.

View differences:

scout/scoutsim/src/scout.cpp
268 268
            if (d_x < 0 || d_x >= walls_image.GetWidth() ||
269 269
                d_y < 0 || d_y >= walls_image.GetHeight())
270 270
            {
271
                return d;
271
                break;
272 272
            }
273 273

  
274 274
            // Max range
275
            if (d > scoutsim::SONAR_MAX_RANGE)
275
            if (d > scoutsim::SONAR_MAX_RANGE_PIX)
276 276
            {
277
                return d;
277
                break;
278 278
            }
279 279

  
280 280
            // Get the sonar reading at the current position of the sonar
......
284 284
    
285 285
            reading = rgb_to_grey(r, g, b);
286 286
        
287

  
288 287
            d++;
289 288
        }
290 289
        /// @todo Consider using different cutoffs for different features
......
324 323
        }
325 324

  
326 325
        // Convert from pixels to mm and return
327
        return (unsigned int) (1000 * d / PIX_PER_METER);
326
        return (unsigned int) ((1000 / PIX_PER_METER) * d);
328 327
    }
329 328

  
330 329
    // x and y is current position of the sonar
scout/scoutsim/src/scout_constants.h
76 76
    // @todo Inaccurate. Update
77 77
    const float ENCODER_TICKS_PER_METER = 363.78;
78 78

  
79
    const unsigned int SONAR_MAX_RANGE = 255;
79
    // @todo Update this
80
    const float SONAR_MAX_RANGE_M = 9.144;
81
    const unsigned int SONAR_MAX_RANGE_PIX = (unsigned int)
82
        (SONAR_MAX_RANGE_M * PIX_PER_METER);
80 83

  
81 84
    // Time it takes for the sonar to spin from position 0 to position 23
82 85
    const float SONAR_HALF_SPIN_TIME = 0.5;

Also available in: Unified diff