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