ApproximateTimeQueue.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * ArmarX is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * ArmarX is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * @author Fabian Reister ( fabian dot reister at kit dot edu )
17  * @date 2021
18  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
19  * GNU General Public License
20  */
21 
22 #pragma once
23 
24 #include <mutex>
25 #include <set>
26 #include <shared_mutex>
27 
28 #include <boost/thread/concurrent_queues/sync_queue.hpp>
29 
30 #include <Eigen/Geometry>
31 
33 
35 
36 #include "interfaces.h"
37 #include "types.h"
38 
40 {
41  struct LaserMessage
42  {
44  Eigen::Isometry3f
45  robotPoseCorrection; // from pose where data was captured to timestamp pose
46  };
47 
48  using LaserMessages = std::vector<LaserMessage>;
49 
50  struct TimedData
51  {
52  int64_t timestamp; // [µs]
53 
55 
57  };
58 
59  /**
60  * @brief The ApproximateTimeQueue class.
61  *
62  * Synchronizes incoming data and returns shapshots.
63  *
64  */
66  {
67  public:
68  /**
69  * @brief Construct a new Approximate Time Queue object
70  *
71  * @param dt [µs] time delay to limit processing of messages (inverse of frequency)
72  * @param laserSensorIds the laser sensors that are used
73  * @param messageCallee once messages are available, the data will be made available to the MessageCallee
74  */
75  ApproximateTimeQueue(int64_t dt,
76  int64_t dtHistoryLength,
77  const std::set<std::string>& laserSensorIds,
78  MessageCallee& messageCallee,
79  bool useOdometry);
80 
82  void insertOdomData(
84 
85 
86  private:
87  bool allDataAvailable(int64_t timestamp) const;
88 
89  void processAvailableData(int64_t timestamp);
90  void processAllAvailableData(int64_t timestamp);
91  void trimUntil(const int64_t& timestamp);
92 
93  const int64_t dtEps; // [µs]
94  const int64_t dtHistoryLength; // [µs]
95 
96  int64_t lastProcessedTimestamp{0};
97 
98  using LaserTimeQueue =
100 
103  odomQueue;
104  std::unordered_map<std::string, LaserTimeQueue> laserQueues;
105 
106  MessageCallee& messageCallee;
107 
108  void serveMessageCallee();
109 
110  boost::sync_queue<TimedData> timedDataQueue;
111  armarx::SimpleRunningTask<>::pointer_type messageCalleeTask = nullptr;
112  const bool useOdometry;
113  };
114 
115 } // namespace armarx::localization_and_mapping::cartographer_adapter
InterpolatingTimeQueue.h
armarx::localization_and_mapping::cartographer_adapter::TimedData::timestamp
int64_t timestamp
Definition: ApproximateTimeQueue.h:52
armarx::localization_and_mapping::cartographer_adapter::TimedData::odomPose
armarx::localization_and_mapping::cartographer_adapter::PoseStamped odomPose
Definition: ApproximateTimeQueue.h:54
armarx::localization_and_mapping::cartographer_adapter::TimedData
Definition: ApproximateTimeQueue.h:50
armarx::localization_and_mapping::cartographer_adapter::LaserScannerMessage
Definition: types.h:153
interfaces.h
armarx::localization_and_mapping::cartographer_adapter::LaserMessage::robotPoseCorrection
Eigen::Isometry3f robotPoseCorrection
Definition: ApproximateTimeQueue.h:45
message
message(STATUS "Boost-Library-Dir: " "${Boost_LIBRARY_DIRS}") message(STATUS "Boost-LIBRARIES
Definition: CMakeLists.txt:8
armarx::localization_and_mapping::cartographer_adapter::PoseStamped
Definition: InterpolatingTimeQueue.h:43
armarx::localization_and_mapping::cartographer_adapter::InterpolatingTimeQueue
Definition: InterpolatingTimeQueue.h:52
armarx::localization_and_mapping::cartographer_adapter::ApproximateTimeQueue::insertLaserData
void insertLaserData(LaserScannerMessage message)
Definition: ApproximateTimeQueue.cpp:48
armarx::localization_and_mapping::cartographer_adapter::ApproximateTimeQueue
The ApproximateTimeQueue class.
Definition: ApproximateTimeQueue.h:65
armarx::localization_and_mapping::cartographer_adapter::ApproximateTimeQueue::insertOdomData
void insertOdomData(armarx::localization_and_mapping::cartographer_adapter::PoseStamped odomPose)
Definition: ApproximateTimeQueue.cpp:75
armarx::localization_and_mapping::cartographer_adapter::TimedData::laserData
LaserMessages laserData
Definition: ApproximateTimeQueue.h:56
timestamp
std::string timestamp()
Definition: CartographerAdapter.cpp:85
armarx::localization_and_mapping::cartographer_adapter
This file is part of ArmarX.
Definition: ApproximateTimeQueue.cpp:15
TaskUtil.h
armarx::localization_and_mapping::cartographer_adapter::ApproximateTimeQueue::ApproximateTimeQueue
ApproximateTimeQueue(int64_t dt, int64_t dtHistoryLength, const std::set< std::string > &laserSensorIds, MessageCallee &messageCallee, bool useOdometry)
Construct a new Approximate Time Queue object.
Definition: ApproximateTimeQueue.cpp:18
armarx::localization_and_mapping::cartographer_adapter::LaserMessages
std::vector< LaserMessage > LaserMessages
Definition: ApproximateTimeQueue.h:48
armarx::localization_and_mapping::cartographer_adapter::LaserMessage::data
LaserScannerMessage data
Definition: ApproximateTimeQueue.h:43
armarx::localization_and_mapping::cartographer_adapter::MessageCallee
Definition: interfaces.h:43
IceUtil::Handle
Definition: forward_declarations.h:30
types.h
armarx::localization_and_mapping::cartographer_adapter::TimeQueue
Definition: TimeQueue.h:50
dt
constexpr T dt
Definition: UnscentedKalmanFilterTest.cpp:45
armarx::localization_and_mapping::cartographer_adapter::LaserMessage
Definition: ApproximateTimeQueue.h:41