Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
matlabbe committed Dec 8, 2024
1 parent 3bdbcdf commit 9a4c585
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
1 change: 1 addition & 0 deletions rtabmap_odom/include/rtabmap_odom/OdometryROS.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ class OdometryROS : public nodelet::Nodelet, public UThread
USemaphore dataReady_;
rtabmap::SensorData dataToProcess_;
std_msgs::Header dataHeaderToProcess_;
bool bufferedDataToProcess_;

bool paused_;
int resetCountdown_;
Expand Down
33 changes: 26 additions & 7 deletions rtabmap_odom/src/OdometryROS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,13 +436,24 @@ void OdometryROS::callbackIMU(const sensor_msgs::ImuConstPtr& msg)
cv::Mat(3,3,CV_64FC1,(void*)msg->linear_acceleration_covariance.data()).clone(),
localTransform);

UScopeMutex m(imuMutex_);
{
UScopeMutex m(imuMutex_);

imus_.insert(std::make_pair(stamp, imu));
if(imus_.size() > 1000)
imus_.insert(std::make_pair(stamp, imu));
if(imus_.size() > 1000)
{
NODELET_WARN("Dropping imu data!");
imus_.erase(imus_.begin());
}
}
if(dataMutex_.lockTry() == 0)
{
NODELET_WARN("Dropping imu data!");
imus_.erase(imus_.begin());
if(bufferedDataToProcess_ && dataHeaderToProcess_.stamp.toSec() <= stamp)
{
bufferedDataToProcess_ = false;
dataReady_.release();
}
dataMutex_.unlock();
}
}
}
Expand All @@ -454,6 +465,7 @@ void OdometryROS::processData(SensorData & data, const std_msgs::Header & header
{
dataToProcess_ = data;
dataHeaderToProcess_ = header;
bufferedDataToProcess_ = false;
dataReady_.release();
dataMutex_.unlock();
}
Expand Down Expand Up @@ -497,8 +509,15 @@ void OdometryROS::mainLoop()

if(waitIMUToinit_ && (imus_.empty() || imus_.rbegin()->first < header.stamp.toSec()))
{
NODELET_ERROR("Make sure IMU is published faster than data rate! (last image stamp=%f and last imu stamp received=%f)",
data.stamp(), imus_.empty()?0:imus_.rbegin()->first);
if(bufferedDataToProcess_) {
NODELET_ERROR("Make sure IMU is published faster than data rate! (last image stamp=%f and last imu stamp received=%f). Previous image is dropped, buffering the new image until an imu with same or greater stamp is received.",
data.stamp(), imus_.empty()?0:imus_.rbegin()->first);
}
else {
NODELET_WARN("Make sure IMU is published faster than data rate! (last image stamp=%f and last imu stamp received=%f). Buffering the image until an imu with same or greater stamp is received.",
data.stamp(), imus_.empty()?0:imus_.rbegin()->first);
bufferedDataToProcess_ = true;
}
return;
}
// process all imu data up to current image stamp (or just after so that underlying odom approach can do interpolation of imu at image stamp)
Expand Down

0 comments on commit 9a4c585

Please sign in to comment.