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
27namespace 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
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
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
std::string timestamp()
SpamFilterDataPtr deactivateSpam(SpamFilterDataPtr const &spamFilter, float deactivationDurationSec, const std::string &identifier, bool deactivate)
Definition Logging.cpp:75
constexpr T c
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition Component.cpp:90
Property< PropertyType > getProperty(const std::string &name)
void reportSensorValues(const std::string &, const std::string &, const LaserScan &, const TimestampBasePtr &, const Ice::Current &c=Ice::emptyCurrent) override
visionx::MetaPointCloudFormatPtr getDefaultPointCloudFormat() override
default point cloud format used to initialize shared memory
void onConnectPointCloudProvider() override
This is called when the Component::onConnectComponent() setup is called.
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void onInitPointCloudProvider() override
This is called when the Component::onInitComponent() is called.
void onExitPointCloudProvider() override
This is called when the Component::onExitComponent() setup is called.
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
VirtualRobot::RobotPtr createLocalClone()
Clones the structure of this remote robot to a local instance.
static bool synchronizeLocalClone(VirtualRobot::RobotPtr robot, RobotStateComponentInterfacePrx robotStatePrx)
void providePointCloud(PointCloudPtrT pointCloudPtr)
offer the new point cloud.
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
#define ARMARX_DEBUG
The logging level for output that is only interesting while debugging.
Definition Logging.h:184
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:193
This file offers overloads of toIce() and fromIce() functions for STL container types.
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
const std::size_t MAX_LASER_SCANNER_POINTS
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.