LaserScannerPointCloudProvider.cpp
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  * @package VisionX::ArmarXObjects::LaserScannerPointCloudProvider
17  * @author Markus Grotz ( markus dot grotz at kit dot edu )
18  * @date 2017
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
25 
26 namespace armarx
27 {
28 
29  const std::size_t MAX_LASER_SCANNER_POINTS = 1024 * 10;
30 
31 
33  {
34  // usingProxy(getProperty<std::string>("LaserScannerUnitName").getValue());
35  usingProxy(getProperty<std::string>("RobotStateComponentName").getValue());
36  resultCloud.reset(new pcl::PointCloud<pcl::PointXYZ>());
37 
38  filter.setMeanK(50);
39  filter.setStddevMulThresh(1.0);
40 
41  }
42 
44  {
45 
46  robotStateComponent = getProxy<RobotStateComponentInterfacePrx>(getProperty<std::string>("RobotStateComponentName").getValue());
47  // laserScanner = getProxy<LaserScannerUnitInterfacePrx>(getProperty<std::string>("LaserScannerUnitName").getValue());
48 
49  localRobot = RemoteRobot::createLocalClone(robotStateComponent);
50 
51  // for (const LaserScannerInfo& info : laserScanner->getConnectedDevices())
52  // {
53  // deviceToFrame[info.device] = info.frame;
54  // }
55 
56  }
57 
59  {
60  }
61 
62 
63 
64  void armarx::LaserScannerPointCloudProvider::reportSensorValues(const std::string& device, const std::string& name, const LaserScan& scan, const TimestampBasePtr& timestamp, const Ice::Current& c)
65  {
66  pcl::PointCloud<pcl::PointXYZ> cloud;
67  cloud.points.reserve(scan.size());
68 
69  for (const LaserScanStep& l : scan)
70  {
71  pcl::PointXYZ p;
72  p.x = -l.distance * std::sin(l.angle);
73  p.y = l.distance * std::cos(l.angle);
74  p.z = 0.0;
75  cloud.points.push_back(p);
76  }
77 
78  cloud.height = 1;
79  cloud.width = cloud.points.size();
80 
81 
82  std::unique_lock<std::mutex> lock(mutex, std::try_to_lock);
83 
84  if (!lock.owns_lock())
85  {
86  ARMARX_INFO << deactivateSpam(3) << "unable to process new laser scan";
87  return;
88  }
89 
90 
91  RemoteRobot::synchronizeLocalClone(localRobot, robotStateComponent);
92  // std::string frameName = deviceToFrame[device];
93 
94  const std::string& frameName = name;
95 
96  if (localRobot->hasRobotNode(frameName))
97  {
98  Eigen::Matrix4f transform = localRobot->getRobotNode(frameName)->getPoseInRootFrame();
99  pcl::transformPointCloud(cloud, clouds[name], transform);
100 
101  resultCloud->clear();
102  for (auto& kv : clouds)
103  {
104  const pcl::PointCloud<pcl::PointXYZ>& c = kv.second;
105  (*resultCloud) += c;
106  }
107  }
108  else
109  {
110  ARMARX_WARNING << deactivateSpam(5) << "Unknown frame for laser scanner: " << frameName;
111  }
112 
113  if(resultCloud->empty())
114  {
115  ARMARX_INFO << deactivateSpam(10) << "Input point cloud is empty. Will not report anything.";
116  return;
117  }
118 
119  pcl::PointCloud<pcl::PointXYZ>::Ptr cloudFiltered(new pcl::PointCloud<pcl::PointXYZ>());
120  filter.setInputCloud(resultCloud);
121  filter.filter(*cloudFiltered);
122 
123 
124  ARMARX_DEBUG << "Publishing point cloud";
125  providePointCloud(cloudFiltered);
126  }
127 
128 
130  {
133 
134  def->topic<LaserScannerUnitListener>("LaserScans", "laser_scanner_topic", "Name of the laser scanner topic.");
135 
136  return def;
137  }
138 
139 
141  {
142  visionx::MetaPointCloudFormatPtr info = new visionx::MetaPointCloudFormat();
143  info->capacity = MAX_LASER_SCANNER_POINTS * sizeof(visionx::Point3D);
144  info->size = info->capacity;
145  info->type = visionx::PointContentType::ePoints;
146  return info;
147  }
148 
149 }
armarx::LaserScannerPointCloudProviderPropertyDefinitions
Definition: LaserScannerPointCloudProvider.h:51
armarx::RemoteRobot::synchronizeLocalClone
static bool synchronizeLocalClone(VirtualRobot::RobotPtr robot, RobotStateComponentInterfacePrx robotStatePrx)
Definition: RemoteRobot.cpp:448
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
deactivateSpam
SpamFilterDataPtr deactivateSpam(SpamFilterDataPtr const &spamFilter, float deactivationDurationSec, const std::string &identifier, bool deactivate)
Definition: Logging.cpp:72
armarx::LaserScannerPointCloudProvider::getDefaultPointCloudFormat
visionx::MetaPointCloudFormatPtr getDefaultPointCloudFormat() override
default point cloud format used to initialize shared memory
Definition: LaserScannerPointCloudProvider.cpp:140
armarx::LaserScannerPointCloudProvider::onConnectPointCloudProvider
void onConnectPointCloudProvider() override
This is called when the Component::onConnectComponent() setup is called.
Definition: LaserScannerPointCloudProvider.cpp:43
ARMARX_DEBUG
#define ARMARX_DEBUG
Definition: Logging.h:177
armarx::MAX_LASER_SCANNER_POINTS
const std::size_t MAX_LASER_SCANNER_POINTS
Definition: LaserScannerPointCloudProvider.cpp:29
LaserScannerPointCloudProvider.h
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:74
armarx::LaserScannerPointCloudProvider::onInitPointCloudProvider
void onInitPointCloudProvider() override
This is called when the Component::onInitComponent() is called.
Definition: LaserScannerPointCloudProvider.cpp:32
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:601
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
armarx::RemoteRobot::createLocalClone
VirtualRobot::RobotPtr createLocalClone()
Clones the structure of this remote robot to a local instance.
Definition: RemoteRobot.cpp:328
armarx::LaserScannerPointCloudProvider::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: LaserScannerPointCloudProvider.cpp:129
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::LaserScannerPointCloudProvider::reportSensorValues
void reportSensorValues(const std::string &, const std::string &, const LaserScan &, const TimestampBasePtr &, const Ice::Current &c=Ice::emptyCurrent) override
Definition: LaserScannerPointCloudProvider.cpp:64
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
Logging.h
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:34
armarx::LaserScannerPointCloudProvider::onExitPointCloudProvider
void onExitPointCloudProvider() override
This is called when the Component::onExitComponent() setup is called.
Definition: LaserScannerPointCloudProvider.cpp:58
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28