1. OpenSourceRoboticsFoundation
  2. Simulation
  3. gazebo
  4. Issues
Issue #3 closed

RaySensor race condition

jagielka
created an issue

When using <sensor:ray name="laser"> and update rate is quite short you receive lots of warnings:

Warning [RaySensor.cc:206] ranges not constructed yet (zero sized)

Quick solution for this issue is to move the locking mechanism before reading laserMsg.ranges in function RaySensor::GetRange

{{{

!c++

double RaySensor::GetRange(int _index) { boost::mutex::scoped_lock(*this->mutex);

if (this->laserMsg.ranges_size() == 0) { gzwarn << "ranges not constructed yet (zero sized)\n"; return 0.0; } if (_index < 0 || _index >= this->laserMsg.ranges_size()) { gzerr << "Invalid range index[" << _index << "]\n"; return 0.0; }

// Move locking mechanism to the beginning of the function // boost::mutex::scoped_lock(*this->mutex); return this->laserMsg.ranges(_index); }

}}}

Comments (5)

  1. jagielka reporter

    Could someone apply this simple patch? It's really annoying to see those warnings displayed every second.

    *** gazebo/sensors/RaySensor.cc     2012-08-03 22:53:38.888807826 +0200
    --- gazebo/sensors/RaySensor.cc     2012-08-03 22:53:06.384805780 +0200
    ***************
    *** 201,206 ****
    --- 201,207 ----
      //////////////////////////////////////////////////
      double RaySensor::GetRange(int _index)
      {
    +   boost::mutex::scoped_lock(*this->mutex);
        if (this->laserMsg.ranges_size() == 0)
        {
          gzwarn << "ranges not constructed yet (zero sized)\n";
    ***************
    *** 212,218 ****
          return 0.0;
        }
      
    -   boost::mutex::scoped_lock(*this->mutex);
        return this->laserMsg.ranges(_index);
      }
      
    --- 213,218 ----
    
  2. Log in to comment