CartographerMapRegistration.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 
25 #include <pcl/point_cloud.h>
26 #include <pcl/point_types.h>
27 
29 
30 #include <RobotAPI/libraries/armem_vision/client/laser_scans/Reader.h>
31 
32 #include <MemoryX/interface/components/PriorKnowledgeInterface.h>
33 #include <MemoryX/interface/components/WorkingMemoryInterface.h>
35 
36 
37 // #include <ArmarXCore/libraries/ArmarXCoreComponentPlugins/DebugObserverComponentPlugin.h>
38 
39 // #include <ArmarXGui/libraries/ArmarXGuiComponentPlugins/LightweightRemoteGuiComponentPlugin.h>
40 
42 
43 #include "RobotComponents/components/CartographerMapRegistration/RemoteGui.h"
44 
45 #include "ArVizDrawer.h"
46 
47 namespace armarx
48 {
49  class LaserScanAggregator;
50 }
51 
52 namespace armarx::cartographer
53 {
54 
55  /**
56  * @defgroup Component-CartographerMapRegistration CartographerMapRegistration
57  * @ingroup RobotComponents-Components
58  * A description of the component CartographerMapRegistration.
59  *
60  * @class CartographerMapRegistration
61  * @ingroup Component-CartographerMapRegistration
62  * @brief Brief description of class CartographerMapRegistration.
63  *
64  * Detailed description of class CartographerMapRegistration.
65  */
67  virtual public armarx::Component
68  // , virtual public armarx::DebugObserverComponentPluginUser
69  // , virtual public armarx::LightweightRemoteGuiComponentPluginUser
70  ,
71  virtual public armarx::ArVizComponentPluginUser,
73  {
74  public:
75  using Point = pcl::PointXYZ;
76  using PointCloud = pcl::PointCloud<Point>;
77  using PointClouds = std::vector<PointCloud>;
78 
81 
82  /// @see armarx::ManagedIceObject::getDefaultName()
83  std::string getDefaultName() const override;
84 
85  // RemoteGuiCallee interface
86  void loadGraph() override;
87  void loadDataFromMemory() override;
88  void selectBoundingBoxCorner(int i) override;
89  void alignBoundingBox() override;
90  void findAssociations() override;
91  void computeCoarseCorrection() override;
92  void computeFineCorrection() override;
93  void storeRegistrationResult() override;
94 
95 
96  protected:
97  /// @see PropertyUser::createPropertyDefinitions()
99 
100  /// @see armarx::ManagedIceObject::onInitComponent()
101  void onInitComponent() override;
102 
103  /// @see armarx::ManagedIceObject::onConnectComponent()
104  void onConnectComponent() override;
105 
106  /// @see armarx::ManagedIceObject::onDisconnectComponent()
107  void onDisconnectComponent() override;
108 
109  /// @see armarx::ManagedIceObject::onExitComponent()
110  void onExitComponent() override;
111 
112  /* (Requires armarx::LightweightRemoteGuiComponentPluginUser.)
113  /// This function should be called once in onConnect() or when you
114  /// need to re-create the Remote GUI tab.
115  void createRemoteGuiTab();
116 
117  /// After calling `RemoteGui_startRunningTask`, this function is
118  /// called periodically in a separate thread. If you update variables,
119  /// make sure to synchronize access to them.
120  void RemoteGui_update() override;
121  */
122 
123 
124  private:
125  void updateArViz();
126 
127  // Private methods go here.
128 
129  // Forward declare `Properties` if you used it before its defined.
130  // struct Properties;
131 
132  /* (Requires the armarx::ArVizComponentPluginUser.)
133  /// Draw some boxes in ArViz.
134  void drawBoxes(const Properties& p, viz::Client& arviz);
135  */
136 
137  Eigen::Affine3f selectedBoundingBoxCorner() const;
138 
139 
140  // Private member variables go here.
141  std::unique_ptr<armem::vision::laser_scans::client::Reader> mappingDataReader;
142 
143  memoryx::PriorKnowledgeInterfacePrx priorKnowledge;
144  memoryx::WorkingMemoryInterfacePrx workingMemory;
145  armarx::RobotStateComponentInterfacePrx robotStateComponent;
146 
147  // publisher
148  RemoteGuiInterfacePrx remoteGuiInterface;
149 
150 
151  memoryx::ObjectClassSegmentWrapper objectClassSegment;
152 
153  /// Properties shown in the Scenario GUI.
154  struct Properties
155  {
156  std::string mapPath = "./RobotComponents/maps/";
157  std::string mapToLoad;
158  std::string cartographerConfigPath = "./RobotComponents/cartographer/config/";
159 
160  float minLaserRange = 400.F;
161  };
162 
163  Properties properties;
164  /* Use a mutex if you access variables from different threads
165  * (e.g. ice functions and RemoteGui_update()).
166  std::mutex propertiesMutex;
167  */
168 
169  /* (Requires the armarx::ArVizComponentPluginUser.)
170  * When used from different threads, an ArViz client needs to be synchronized.
171  /// Protects the arviz client inherited from the ArViz plugin.
172  std::mutex arvizMutex;
173  */
174  ArVizDrawer arvizDrawer;
175 
176  std::vector<wykobi::Model> models;
177 
178  std::unique_ptr<LaserScanAggregator> aggregator;
179 
180  std::unique_ptr<MapRegistration> mapRegistration;
181  std::vector<MapRegistration::Association> associations;
182 
183  Eigen::Affine3f world_T_map = Eigen::Affine3f::Identity();
184 
185  std::unique_ptr<armarx::cartographer_map_registration::RemoteGui> remoteGui;
186 
187  int boundingBoxCorner{0};
188  };
189 
190 } // namespace armarx::cartographer
ObjectClassSegmentWrapper.h
armarx::cartographer::CartographerMapRegistration::findAssociations
void findAssociations() override
Definition: CartographerMapRegistration.cpp:365
ArVizComponentPlugin.h
ArVizDrawer.h
armarx::cartographer::ArVizDrawer
Definition: ArVizDrawer.h:44
armarx::cartographer::CartographerMapRegistration::onConnectComponent
void onConnectComponent() override
Definition: CartographerMapRegistration.cpp:120
armarx::cartographer::CartographerMapRegistration::selectBoundingBoxCorner
void selectBoundingBoxCorner(int i) override
Definition: CartographerMapRegistration.cpp:344
memoryx::ObjectClassSegmentWrapper
Definition: ObjectClassSegmentWrapper.h:22
armarx::cartographer::CartographerMapRegistration::PointClouds
std::vector< PointCloud > PointClouds
Definition: CartographerMapRegistration.h:77
armarx::cartographer::CartographerMapRegistration::~CartographerMapRegistration
virtual ~CartographerMapRegistration()
armarx::cartographer::CartographerMapRegistration::onInitComponent
void onInitComponent() override
Definition: CartographerMapRegistration.cpp:110
armarx::cartographer
Definition: MapRegistration.cpp:42
GfxTL::Identity
void Identity(MatrixXX< N, N, T > *a)
Definition: MatrixXX.h:570
armarx::ArVizComponentPluginUser
Provides a ready-to-use ArViz client arviz as member variable.
Definition: ArVizComponentPlugin.h:35
armarx::cartographer::CartographerMapRegistration::alignBoundingBox
void alignBoundingBox() override
Definition: CartographerMapRegistration.cpp:354
armarx::cartographer::CartographerMapRegistration::storeRegistrationResult
void storeRegistrationResult() override
Definition: CartographerMapRegistration.cpp:452
armarx::cartographer::CartographerMapRegistration::getDefaultName
std::string getDefaultName() const override
Definition: CartographerMapRegistration.cpp:169
armarx::cartographer_map_registration::RemoteGuiCallee
Definition: RemoteGui.h:33
Point
Definition: PointCloud.h:21
armarx::cartographer::CartographerMapRegistration::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: CartographerMapRegistration.cpp:65
armarx::cartographer::CartographerMapRegistration::onExitComponent
void onExitComponent() override
Definition: CartographerMapRegistration.cpp:164
Component.h
armarx::Component
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition: Component.h:91
PointCloud
Definition: PointCloud.h:85
armarx::cartographer::CartographerMapRegistration::CartographerMapRegistration
CartographerMapRegistration()
Definition: CartographerMapRegistration.cpp:103
armarx::cartographer::CartographerMapRegistration
Brief description of class CartographerMapRegistration.
Definition: CartographerMapRegistration.h:66
armarx::cartographer::CartographerMapRegistration::computeCoarseCorrection
void computeCoarseCorrection() override
Definition: CartographerMapRegistration.cpp:392
IceUtil::Handle< class PropertyDefinitionContainer >
IceInternal::ProxyHandle<::IceProxy::armarx::RobotStateComponentInterface >
armarx::cartographer::CartographerMapRegistration::loadDataFromMemory
void loadDataFromMemory() override
Definition: CartographerMapRegistration.cpp:228
armarx::cartographer::CartographerMapRegistration::loadGraph
void loadGraph() override
Definition: CartographerMapRegistration.cpp:198
armarx::cartographer::CartographerMapRegistration::computeFineCorrection
void computeFineCorrection() override
Definition: CartographerMapRegistration.cpp:416
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::cartographer::CartographerMapRegistration::onDisconnectComponent
void onDisconnectComponent() override
Definition: CartographerMapRegistration.cpp:159