OKVIS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ImuFrameSynchronizer.hpp
Go to the documentation of this file.
1 /*********************************************************************************
2  * OKVIS - Open Keyframe-based Visual-Inertial SLAM
3  * Copyright (c) 2015, Autonomous Systems Lab / ETH Zurich
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  * * Neither the name of Autonomous Systems Lab / ETH Zurich nor the names of
14  * its contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  *
29  * Created on: Sep 13, 2014
30  * Author: Pascal Gohl
31  * Modified: Stefan Leutenegger (s.leutenegger@imperial.ac.uk)
32  * Modified: Andreas Forster (an.forster@gmail.com)
33  *********************************************************************************/
34 
43 #ifndef INCLUDE_OKVIS_IMUFRAMESYNCHRONIZER_H_
44 #define INCLUDE_OKVIS_IMUFRAMESYNCHRONIZER_H_
45 
46 #include <atomic>
47 #include <mutex>
48 #include <condition_variable>
49 
50 #include <okvis/Time.hpp>
51 
53 namespace okvis {
54 
60  public:
65 
70  void gotImuData(const okvis::Time& stamp);
71 
77  bool waitForUpToDateImuData(const okvis::Time& frame_stamp);
78 
80  void shutdown();
81 
82  private:
85  std::condition_variable gotNeededImuData_;
86  std::mutex mutex_;
87  std::atomic_bool shutdown_;
88 };
89 
90 } /* namespace okvis */
91 
92 #endif /* INCLUDE_OKVIS_IMUFRAMESYNCHRONIZER_H_ */
This class is to safely notify different threads whether IMU measurements up to a timestamp (e...
Definition: ImuFrameSynchronizer.hpp:59
std::condition_variable gotNeededImuData_
Condition variable for waiting and notyfing.
Definition: ImuFrameSynchronizer.hpp:85
Header file for the TimeBase, Time and WallTime class.
bool waitForUpToDateImuData(const okvis::Time &frame_stamp)
Wait until a IMU measurement with a timestamp equal or newer to the supplied one is registered...
Definition: ImuFrameSynchronizer.cpp:64
std::atomic_bool shutdown_
True if shutdown() was called.
Definition: ImuFrameSynchronizer.hpp:87
~ImuFrameSynchronizer()
Destructor.
Definition: ImuFrameSynchronizer.cpp:51
void gotImuData(const okvis::Time &stamp)
Tell the synchronizer that a new IMU measurement has been registered.
Definition: ImuFrameSynchronizer.cpp:57
std::mutex mutex_
Mutex.
Definition: ImuFrameSynchronizer.hpp:86
void shutdown()
Tell the synchronizer to shutdown. This will notify all waiting threads to wake up.
Definition: ImuFrameSynchronizer.cpp:78
ImuFrameSynchronizer()
Constructor.
Definition: ImuFrameSynchronizer.cpp:48
Time representation. May either represent wall clock time or ROS clock time.
Definition: Time.hpp:187
okvis::Time newestImuDataStamp_
Newest IMU data timestamp.
Definition: ImuFrameSynchronizer.hpp:83
okvis::Time imuDataNeededUntil_
A thread is waiting for IMU data newer or equal to this timestamp.
Definition: ImuFrameSynchronizer.hpp:84