RTABMapRegistration.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package VisionX::ArmarXObjects::RTABMapRegistration
19  * @author Markus Grotz ( markus dot grotz at kit dot edu )
20  * @date 2015
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 
25 #pragma once
26 
27 
30 
31 
34 #include <RobotAPI/interface/core/RobotState.h>
35 
38 #include <MemoryX/interface/components/WorkingMemoryInterface.h>
39 
40 
41 #include <VisionX/interface/components/RTABMapInterface.h>
46 
47 #include <Eigen/Geometry>
48 
49 
50 #include <opencv2/opencv.hpp>
51 #include <Image/IplImageAdaptor.h>
52 
53 #pragma GCC diagnostic push
54 #pragma GCC diagnostic ignored "-Wpedantic"
55 #include <pcl/io/pcd_io.h>
56 #include <pcl/common/transforms.h>
57 #include <pcl/filters/filter.h>
58 #include <pcl/filters/passthrough.h>
59 
60 #include <rtabmap/core/Rtabmap.h>
61 #include <rtabmap/core/RtabmapThread.h>
62 
63 #include <rtabmap/core/CameraEvent.h>
64 #include <rtabmap/core/Odometry.h>
65 
66 #include <rtabmap/core/OdometryThread.h>
67 #include <rtabmap/core/OdometryEvent.h>
68 
69 
70 #include <rtabmap/utilite/UEventsManager.h>
71 #include <rtabmap/utilite/UEventsHandler.h>
72 #include <rtabmap/utilite/ULogger.h>
73 
74 #pragma GCC diagnostic pop
75 
76 namespace armarx
77 {
78  /**
79  * @class RTABMapRegistrationPropertyDefinitions
80  * @brief
81  */
84  {
85  public:
88  {
89  // defineRequiredProperty<std::string>("agentName", "name of the agent for which the sensor values are provided");
90 
91  defineOptionalProperty<std::string>("agentName", "RTABMap", "");
92  defineOptionalProperty<std::string>("providerName", "OpenNIPointCloudProvider", "");
93  //defineOptionalProperty<std::string>("sourceFrameName", "DepthCamera", "the robot node to use as source coordinate system for the captured point clouds");
94  defineOptionalProperty<std::string>("RobotStateComponentName", "RobotStateComponent", "Name of the robot state component that should be used");
95  defineOptionalProperty<std::string>("WorkingMemoryName", "WorkingMemory", "Name of the working memory");
96  defineOptionalProperty<bool>("provideGlobalPointCloud", false, "provide global point cloud if set. otherwise only the current view");
97  defineOptionalProperty<float>("MinDistance", 0.02, "minimum z-axis distance in meters");
98  defineOptionalProperty<float>("MaxDistance", 5.00, "maximum z-axis distance in meters");
99  }
100  };
101 
102  /**
103  * @class RTABMapRegistration
104  *
105  * @ingroup VisionX-Components
106  * @brief A brief description
107  *
108  *
109  * Detailed Description
110  */
112  virtual public visionx::RTABMapInterface,
114  virtual public visionx::ImageProcessor,
115  virtual public UEventsHandler
116  {
117  public:
118  /**
119  * @see armarx::ManagedIceObject::getDefaultName()
120  */
121  std::string getDefaultName() const override
122  {
123  return "RTABMapRegistration";
124  }
125 
126  protected:
127  /**
128  * @see PropertyUser::createPropertyDefinitions()
129  */
131 
132  void onInitCapturingPointCloudProvider() override;
133  void onExitCapturingPointCloudProvider() override;
134  void onStartCapture(float framesPerSecond) override;
135  void onStopCapture() override;
136  bool doCapture() override;
137 
138  void onInitImageProcessor() override;
139  void onConnectImageProcessor() override;
140  void onExitImageProcessor() override;
141  void process() override;
142 
143  void onInitComponent() override
144  {
145  CapturingPointCloudProvider::onInitComponent();
146  ImageProcessor::onInitComponent();
147  }
148 
149  void onConnectComponent() override
150  {
151  ImageProcessor::onConnectComponent();
152  CapturingPointCloudProvider::onConnectComponent();
153  }
154 
155  void onDisconnectComponent() override
156  {
157  CapturingPointCloudProvider::onDisconnectComponent();
158  ImageProcessor::onDisconnectComponent();
159  }
160 
161  void onExitComponent() override
162  {
163  CapturingPointCloudProvider::onExitComponent();
164  ImageProcessor::onExitComponent();
165  }
166 
167  bool handleEvent(UEvent* event) override;
168 
169  visionx::MetaPointCloudFormatPtr getDefaultPointCloudFormat() override;
170 
171 
172  private:
173 
174  bool extractPointCloud(rtabmap::SensorData sensorData, Eigen::Matrix4f transform, pcl::PointCloud<pcl::PointXYZRGBA>::Ptr& tempCloudPtr);
175  void updatePosition(Eigen::Matrix4f pose);
176  void processData();
177 
178  std::string agentName;
179  std::string providerName;
180  std::string sourceFrameName;
181  bool provideGlobalPointCloud;
182 
183  rtabmap::Rtabmap* rtabmap;
184  rtabmap::RtabmapThread* rtabmapThread;
185  rtabmap::OdometryThread* odomThread;
186  rtabmap::CameraModel cameraModel;
187 
188 
189  CByteImage** images;
190  armarx::MetaInfoSizeBasePtr imageMetaInfo;
191  int imageId;
192 
193  Eigen::Matrix4f initialCameraPose;
194 
195  boost::mutex RTABDataMutex;
196  bool hasNewData;
197  boost::condition dataCondition;
198 
199  void requestGlobalPointCloud();
200  std::map<int, rtabmap::Signature> signatures;
201  std::map<int, rtabmap::Transform> poses;
202 
203  boost::mutex resultPointCloudMutex;
204  boost::condition resultCondition;
205  bool hasNewResultPointCloud;
206  pcl::PointCloud<pcl::PointXYZRGBA>::Ptr resultPointCloudPtr;
207 
208  pcl::PassThrough<pcl::PointXYZRGBA> passThroughFilter;
209 
210  armarx::RobotStateComponentInterfacePrx robotStateComponent;
211  memoryx::WorkingMemoryInterfacePrx workingMemory;
212  memoryx::AgentInstancesSegmentBasePrx agentInstancesSegment;
213 
214  memoryx::AgentInstancePtr agentInstance;
215  std::string agentInstanceId;
216 
218  };
219 }
220 
CapturingPointCloudProvider.h
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
armarx::RTABMapRegistration::getDefaultPointCloudFormat
visionx::MetaPointCloudFormatPtr getDefaultPointCloudFormat() override
default point cloud format used to initialize shared memory
Definition: RTABMapRegistration.cpp:500
visionx::ImageProcessor
The ImageProcessor class provides an interface for access to ImageProviders via Ice and shared memory...
Definition: ImageProcessor.h:87
Pose.h
armarx::RTABMapRegistration::doCapture
bool doCapture() override
Main capturing function.
Definition: RTABMapRegistration.cpp:160
armarx::RTABMapRegistrationPropertyDefinitions
Definition: RTABMapRegistration.h:82
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:333
PeriodicTask.h
armarx::RTABMapRegistration::onExitImageProcessor
void onExitImageProcessor() override
Exit the ImapeProcessor component.
Definition: RTABMapRegistration.cpp:427
armarx::RTABMapRegistration::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: RTABMapRegistration.cpp:41
armarx::RTABMapRegistration
A brief description.
Definition: RTABMapRegistration.h:111
IceInternal::Handle< AgentInstance >
visionx::CapturingPointCloudProviderPropertyDefinitions::CapturingPointCloudProviderPropertyDefinitions
CapturingPointCloudProviderPropertyDefinitions(std::string prefix)
Definition: CapturingPointCloudProvider.h:42
armarx::RTABMapRegistration::onConnectImageProcessor
void onConnectImageProcessor() override
Implement this method in the ImageProcessor in order execute parts when the component is fully initia...
Definition: RTABMapRegistration.cpp:383
ImageProcessor.h
FramedPose.h
visionx::CapturingPointCloudProviderPropertyDefinitions
Definition: CapturingPointCloudProvider.h:38
armarx::RTABMapRegistrationPropertyDefinitions::RTABMapRegistrationPropertyDefinitions
RTABMapRegistrationPropertyDefinitions(std::string prefix)
Definition: RTABMapRegistration.h:86
armarx::RTABMapRegistration::onExitComponent
void onExitComponent() override
Definition: RTABMapRegistration.h:161
armarx::RTABMapRegistration::handleEvent
bool handleEvent(UEvent *event) override
Definition: RTABMapRegistration.cpp:191
armarx::RTABMapRegistration::onInitCapturingPointCloudProvider
void onInitCapturingPointCloudProvider() override
This is called when the Component::onInitComponent() is called.
Definition: RTABMapRegistration.cpp:47
armarx::RTABMapRegistration::onDisconnectComponent
void onDisconnectComponent() override
Hook for subclass.
Definition: RTABMapRegistration.h:155
Component.h
visionx::CapturingPointCloudProvider
The CapturingPointCloudProvider provides a callback function to trigger the capturing of point clouds...
Definition: CapturingPointCloudProvider.h:56
armarx::RTABMapRegistration::onStopCapture
void onStopCapture() override
This is called when the point cloud provider capturing has been stopped.
Definition: RTABMapRegistration.cpp:146
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:601
armarx::RTABMapRegistration::process
void process() override
Process the vision component.
Definition: RTABMapRegistration.cpp:437
Entity.h
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::transform
auto transform(const Container< InputT, Alloc > &in, OutputT(*func)(InputT const &)) -> Container< OutputT, typename std::allocator_traits< Alloc >::template rebind_alloc< OutputT > >
Convenience function (with less typing) to transform a container of type InputT into the same contain...
Definition: algorithm.h:315
armarx::RTABMapRegistration::onInitComponent
void onInitComponent() override
Definition: RTABMapRegistration.h:143
IceInternal::ProxyHandle<::IceProxy::armarx::RobotStateComponentInterface >
armarx::RTABMapRegistration::getDefaultName
std::string getDefaultName() const override
Definition: RTABMapRegistration.h:121
ImageUtil.h
AgentInstance.h
armarx::RTABMapRegistration::onStartCapture
void onStartCapture(float framesPerSecond) override
This is called when the point cloud provider capturing has been started.
Definition: RTABMapRegistration.cpp:102
TypeMapping.h
armarx::RTABMapRegistration::onConnectComponent
void onConnectComponent() override
Definition: RTABMapRegistration.h:149
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::RTABMapRegistration::onExitCapturingPointCloudProvider
void onExitCapturingPointCloudProvider() override
This is called when the Component::onExitComponent() setup is called.
Definition: RTABMapRegistration.cpp:82
armarx::RTABMapRegistration::onInitImageProcessor
void onInitImageProcessor() override
Setup the vision component.
Definition: RTABMapRegistration.cpp:376