Component.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 <atomic>
25#include <cstdint>
26#include <experimental/memory>
27#include <memory>
28#include <mutex>
29#include <optional>
30#include <string>
31
32#include <Eigen/Core>
33#include <Eigen/Geometry>
34
35#include <Ice/Current.h>
36
41#include <ArmarXCore/interface/core/PackagePath.h>
42#include <ArmarXCore/interface/observers/ObserverInterface.h>
43#include <ArmarXCore/interface/observers/Timestamp.h>
44
45#include <ArmarXGui/interface/RemoteGuiInterface.h>
46
48#include <RobotAPI/interface/units/LaserScannerUnit.h>
53
58#include <armarx/localization_and_mapping/components/cartographer_mapping_and_localization/ComponentInterface.h>
63
64// forward decl
66{
67 class MapBuilderInterface;
68} // namespace cartographer::mapping
69
70namespace armarx
71{
72 class TransformWriterInterface;
73 class TransformReaderInterface;
75} // namespace armarx
76
78{
79 // forward decl
80 class ArVizDrawer;
82} // namespace armarx::localization_and_mapping::cartographer_adapter
83
85{
86
87
88 /**
89 * @defgroup Component-CartographerMappingAndLocalization CartographerMappingAndLocalization
90 * @ingroup RobotComponents-Components
91 * A description of the component CartographerMappingAndLocalization.
92 *
93 * @class CartographerMappingAndLocalization
94 * @ingroup Component-CartographerMappingAndLocalization
95 * @brief Brief description of class CartographerMappingAndLocalization.
96 *
97 * Detailed description of class CartographerMappingAndLocalization.
98 */
99 class Component :
101 virtual public ArVizComponentPluginUser,
103 virtual public RemoteGuiCallee,
104 virtual public LocalizationRemoteGuiCallee,
106 {
107 public:
108 Component();
109 virtual ~Component();
110
111 /// @see armarx::ManagedIceObject::getDefaultName()
112 std::string getDefaultName() const override;
113 static std::string GetDefaultName();
114
115 // LaserScannerUnitListener interface
116 void reportSensorValues(const ::std::string&,
117 const ::std::string&,
118 const ::armarx::LaserScan&,
119 const ::armarx::TimestampBasePtr&,
120 const ::Ice::Current&) override;
121
122 // PlatformUnitListener interface
123 // TODO: use streaming (RobotUnit)
124 // void reportOdometryPose(const TransformStamped& odometryPose, const Ice::Current&) override;
125 // void reportOdometryVelocity(const TwistStamped& velocity, const Ice::Current&) override;
126
127 // SlamDataCallable interface
128 void onLocalSlamData(const cartographer_adapter::LocalSlamData& slamData) override;
129 // void onGraphOptimized(const OptimizedGraphData& graphData) override;
130 // void onGridMap(const SubMapDataVector& submapData) override;
131 void onLaserSensorData(const cartographer_adapter::LaserScannerData& laserData) override;
132
133 // RemoteGuiCallee
135
136 enum class Mode
137 {
140 };
141
142 void onWorldToMapTransformUpdate(const Eigen::Isometry3f& world_T_map) override;
143
149
150 protected:
151 /// @see armarx::ManagedIceObject::onInitComponent()
152 void onInitComponent() override;
153
154 /// @see armarx::ManagedIceObject::onConnectComponent()
155 void onConnectComponent() override;
156
157 /// @see armarx::ManagedIceObject::onDisconnectComponent()
158 void onDisconnectComponent() override;
159
161
162 /// @see armarx::ManagedIceObject::onDisconnectComponent()
163 void onExitComponent() override;
164
165 /// @see PropertyUser::createPropertyDefinitions()
167
168 Eigen::Isometry3f worldToMapTransform() const override;
169
170 private:
171 void setupMappingAdapter();
172
173 //! adapter to cartographer
174 std::unique_ptr<cartographer_adapter::CartographerAdapter> mappingAdapter;
176
177 //! ArViz plotter
178 std::unique_ptr<cartographer_adapter::ArVizDrawer> arvizDrawer;
179
180 //! Remote GUI to trigger map creation
181 std::unique_ptr<MappingRemoteGui> mappingRemoteGui;
182 std::unique_ptr<LocalizationRemoteGui> localizationRemoteGui;
183
184 // queues to handle incoming messages
186 laserMessageQueue;
188 odomMessageQueue;
189
190 //! helper flag to prevent creation of multiple maps
191 bool mapCreated{false};
192
193 // Eigen::Isometry3f globalPoseFromLongTermMemory(const std::string& agentName, const auto& robot);
194
195 // FIXME remove
196 // std::atomic<int64_t> lastTimestamp{0};
197
198 // topic publisher
199 RemoteGuiInterfacePrx remoteGui;
200 DebugObserverInterfacePrx debugObserver;
201
202 // others
203 // armem::vision::laser_scans::client::Writer laserScansMemoryWriter;
204 // armem::vision::occupancy_grid::client::Writer occupancyGridMemoryWriter;
205 // armem::robot_state::RobotReader robotReader;
206
207 //! properties
208 struct Properties
209 {
210 armarx::data::PackagePath mapPath{.package = "PriorKnowledgeData",
211 .path = "maps/cartographer"};
212
213 std::string mapStorageSubDir;
214
215 armarx::data::PackagePath mapToLoad{.package = "PriorKnowledgeData",
216 .path = "maps/cartographer/..."};
217
218 armarx::data::PackagePath cartographerConfigPath{.package =
219 "armarx_localization_and_mapping",
220 .path = "cartographer/config/"};
221
222 Mode mode = Mode::Mapping;
223 bool enableVisualization = true;
224 bool enableMappingVisualization = true;
225
227
228 int odomQueryPeriodMs = 20;
229 int occupancyGridMemoryUpdatePeriodMs = 1000;
230
231 bool useNativeOdometryTimestamps = true;
232 bool useNativeLaserscannerTimestamps = true;
233
234 std::string laserScanners;
235
236 struct
237 {
238 float global_localization_min_score = 0.5;
239 } cartographer;
240
241 float obstacleRadius = 500; // [mm]
242
243 float occupiedThreshold = 0.55;
244
245 } properties;
246
247 Throttler throttlerLaserScansMemoryWriter{10.F};
248 Throttler throttlerOccupancyGridMemoryWriter{10.F};
249
250 Throttler throttlerArviz{10.F};
251
252 std::unique_ptr<cartographer_adapter::ArVizDrawerMapBuilder> arVizDrawerMapBuilder;
253
254 std::optional<FrequencyReporter> laserDataReporter;
255 std::optional<FrequencyReporter> odomDataReporter;
256 std::optional<FrequencyReporter> slamResultReporter;
257
258 // std::unique_ptr<components::cartographer_localization_and_mapping::RobotUnitReader> robotUnitReader;
259
260 SimplePeriodicTask<>::pointer_type occupancyGridTask;
261 SimplePeriodicTask<>::pointer_type odometryQueryTask;
262
263 std::experimental::observer_ptr<armem::client::plugins::ReaderWriterPlugin<
264 armem::vision::occupancy_grid::client::Writer>>
265 occupancyGridWriterPlugin;
266
267 std::experimental::observer_ptr<
268 armem::client::plugins::ReaderWriterPlugin<navigation::memory::client::costmap::Writer>>
269 costmapWriterPlugin;
270
271 std::experimental::observer_ptr<
272 armem::client::plugins::ReaderWriterPlugin<armem::robot_state::RobotReader>>
273 robotReaderPlugin;
274
275 Eigen::Isometry3f world_T_map = Eigen::Isometry3f::Identity();
276 std::optional<Eigen::Isometry3f> map_T_robot = std::nullopt;
277
278 std::atomic_bool receivingData{false};
279
280
281 std::optional<Eigen::Isometry3f> globalPose() const;
282
283 // armarx::plugins::RobotUnitComponentPlugin* robotUnit;
284
285
286 std::mutex inputMtx;
287
288
289 // used within the odometry task
290 int64_t lastTimestamp = 0;
291 std::atomic_bool robotIsMoving = false;
292
293 plugins::HeartbeatComponentPlugin* heartbeatPlugin = nullptr;
294 };
295} // namespace armarx::localization_and_mapping::components::cartographer_localization_and_mapping
The FrequencyReporter class.
IceUtil::Handle< PeriodicTask< T > > pointer_type
Shared pointer type for convenience.
The purpose of the MessageQueue is to provide a convenient way to process incoming messages sequentia...
void reportSensorValues(const ::std::string &, const ::std::string &, const ::armarx::LaserScan &, const ::armarx::TimestampBasePtr &, const ::Ice::Current &) override
void onLocalSlamData(const cartographer_adapter::LocalSlamData &slamData) override
Eigen::Isometry3f worldToMapTransform() const override
static transformation from world to map
void onCreateMapButtonClicked(const RemoteGuiCallee::ButtonClickContext &ctx) override
void onLaserSensorData(const cartographer_adapter::LaserScannerData &laserData) override
This file offers overloads of toIce() and fromIce() functions for STL container types.
::IceInternal::ProxyHandle<::IceProxy::armarx::DebugObserverInterface > DebugObserverInterfacePrx
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.