2018-03-07 19:43:30 -05:00
|
|
|
/*
|
|
|
|
|
Copyright (c) 2010-2016, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
|
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
|
modification, are permitted provided that the following conditions are met:
|
|
|
|
|
* Redistributions of source code must retain the above copyright
|
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
|
* Redistributions in binary form must reproduce the above copyright
|
|
|
|
|
notice, this list of conditions and the following disclaimer in the
|
|
|
|
|
documentation and/or other materials provided with the distribution.
|
|
|
|
|
* Neither the name of the Universite de Sherbrooke nor the
|
|
|
|
|
names of its contributors may be used to endorse or promote products
|
|
|
|
|
derived from this software without specific prior written permission.
|
|
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
|
|
|
|
|
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
|
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2023-02-12 16:18:01 -08:00
|
|
|
#include "rtabmap/core/rtabmap_core_export.h" // DLL export/import defines
|
2018-03-07 19:43:30 -05:00
|
|
|
|
|
|
|
|
#include <rtabmap/core/Transform.h>
|
2023-04-16 17:32:32 -07:00
|
|
|
#include <rtabmap/core/Parameters.h>
|
2018-03-07 19:43:30 -05:00
|
|
|
#include <rtabmap/utilite/UThread.h>
|
|
|
|
|
#include <rtabmap/utilite/UEventsSender.h>
|
|
|
|
|
#include <rtabmap/utilite/UTimer.h>
|
|
|
|
|
|
|
|
|
|
#include <fstream>
|
|
|
|
|
|
2026-08-06 13:32:20 -07:00
|
|
|
namespace rtabmap {
|
2018-03-07 19:43:30 -05:00
|
|
|
|
2023-04-16 17:32:32 -07:00
|
|
|
class IMUFilter;
|
|
|
|
|
|
2018-03-07 19:43:30 -05:00
|
|
|
/**
|
2026-08-06 13:32:20 -07:00
|
|
|
* @class IMUThread
|
|
|
|
|
* @brief Background thread that replays IMU measurements from a CSV file.
|
|
|
|
|
*
|
|
|
|
|
* Reads gyroscope and accelerometer samples from a comma-separated file (EuRoC-style
|
|
|
|
|
* or epoch timestamps), optionally fuses them with @ref IMUFilter, and posts
|
|
|
|
|
* @ref IMUEvent on each step.
|
|
|
|
|
*
|
|
|
|
|
* CSV format:
|
|
|
|
|
* - First line: header (skipped).
|
|
|
|
|
* - Following lines: `stamp,gx,gy,gz,ax,ay,az` (stamp in seconds with a decimal
|
|
|
|
|
* point, or EuRoC nanoseconds without one).
|
|
|
|
|
*
|
|
|
|
|
* Playback rate is limited by @ref setRate() when `rate > 0`; otherwise samples are
|
|
|
|
|
* read as fast as possible (or spaced using inter-sample timestamps after the first
|
|
|
|
|
* pair). When the file ends, the thread posts an empty @ref IMUEvent and stops.
|
|
|
|
|
*
|
|
|
|
|
* @see IMUEvent
|
|
|
|
|
* @see IMUFilter
|
|
|
|
|
* @see SensorCaptureThread::enableIMUFiltering()
|
2018-03-07 19:43:30 -05:00
|
|
|
*/
|
2023-02-12 16:18:01 -08:00
|
|
|
class RTABMAP_CORE_EXPORT IMUThread :
|
2018-03-07 19:43:30 -05:00
|
|
|
public UThread,
|
|
|
|
|
public UEventsSender
|
|
|
|
|
{
|
|
|
|
|
public:
|
2026-08-06 13:32:20 -07:00
|
|
|
/**
|
|
|
|
|
* @brief Constructs the replay thread.
|
|
|
|
|
* @param rate Target playback rate in Hz (`0` = no rate cap until timestamps apply).
|
|
|
|
|
* @param localTransform IMU frame relative to the robot base (stored in each @ref IMU).
|
|
|
|
|
*/
|
2018-03-07 19:43:30 -05:00
|
|
|
IMUThread(int rate, const Transform & localTransform);
|
|
|
|
|
virtual ~IMUThread();
|
|
|
|
|
|
2026-08-06 13:32:20 -07:00
|
|
|
/**
|
|
|
|
|
* @brief Opens and validates an IMU CSV file.
|
|
|
|
|
* @param path Path to the CSV file.
|
|
|
|
|
* @return False if the file is missing or contains no data rows.
|
|
|
|
|
*/
|
2018-03-07 19:43:30 -05:00
|
|
|
bool init(const std::string & path);
|
2026-08-06 13:32:20 -07:00
|
|
|
|
|
|
|
|
/** @brief Sets the target playback rate in Hz. */
|
2018-03-07 19:43:30 -05:00
|
|
|
void setRate(int rate);
|
2026-08-06 13:32:20 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Enables orientation fusion on replayed samples.
|
|
|
|
|
* @param filteringStrategy @ref IMUFilter::Type index (`0` = Madgwick, `1` = complementary).
|
|
|
|
|
* @param parameters Optional ImuFilter/... tuning parameters.
|
|
|
|
|
* @param baseFrameConversion If true, rotate IMU vectors into the base frame before filtering.
|
|
|
|
|
*/
|
|
|
|
|
void enableIMUFiltering(int filteringStrategy = 1, const ParametersMap & parameters = ParametersMap(), bool baseFrameConversion = false);
|
|
|
|
|
|
|
|
|
|
/** @brief Disables fusion and deletes the internal @ref IMUFilter. */
|
2023-04-16 17:32:32 -07:00
|
|
|
void disableIMUFiltering();
|
2018-03-07 19:43:30 -05:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
virtual void mainLoopBegin();
|
|
|
|
|
virtual void mainLoop();
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
int rate_;
|
|
|
|
|
Transform localTransform_;
|
|
|
|
|
std::ifstream imuFile_;
|
|
|
|
|
UTimer frameRateTimer_;
|
|
|
|
|
double captureDelay_;
|
|
|
|
|
double previousStamp_;
|
2023-04-16 17:32:32 -07:00
|
|
|
IMUFilter * _imuFilter;
|
|
|
|
|
bool _imuBaseFrameConversion;
|
2018-03-07 19:43:30 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace rtabmap
|