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
27
28namespace armarx
29{
30
31 const std::size_t MAX_LASER_SCANNER_POINTS = 1024 * 10;
32
33 void
35 {
36 // usingProxy(getProperty<std::string>("LaserScannerUnitName").getValue());
37 usingProxy(getProperty<std::string>("RobotStateComponentName").getValue());
38 resultCloud.reset(new pcl::PointCloud<pcl::PointXYZ>());
39
40 filter.setMeanK(50);
41 filter.setStddevMulThresh(1.0);
42 }
43
44 void
46 {
47
49 getProperty<std::string>("RobotStateComponentName").getValue());
50 // laserScanner = getProxy<LaserScannerUnitInterfacePrx>(getProperty<std::string>("LaserScannerUnitName").getValue());
51
52 localRobot = RemoteRobot::createLocalClone(robotStateComponent);
53
54 // for (const LaserScannerInfo& info : laserScanner->getConnectedDevices())
55 // {
56 // deviceToFrame[info.device] = info.frame;
57 // }
58 }
59
60 void
64
65 void
67 const std::string& name,
68 const LaserScan& scan,
69 const TimestampBasePtr& timestamp,
70 const Ice::Current& c)
71 {
72 pcl::PointCloud<pcl::PointXYZ> cloud;
73 cloud.points.reserve(scan.size());
74
75 for (const LaserScanStep& l : scan)
76 {
77 pcl::PointXYZ p;
78 p.x = -l.distance * std::sin(l.angle);
79 p.y = l.distance * std::cos(l.angle);
80 p.z = 0.0;
81 cloud.points.push_back(p);
82 }
83
84 cloud.height = 1;
85 cloud.width = cloud.points.size();
86
87
88 std::unique_lock<std::mutex> lock(mutex, std::try_to_lock);
89
90 if (!lock.owns_lock())
91 {
92 ARMARX_INFO << deactivateSpam(3) << "unable to process new laser scan";
93 return;
94 }
95
96
97 RemoteRobot::synchronizeLocalClone(localRobot, robotStateComponent);
98 // std::string frameName = deviceToFrame[device];
99
100 const std::string& frameName = name;
101
102 if (localRobot->hasRobotNode(frameName))
103 {
104 Eigen::Matrix4f transform = localRobot->getRobotNode(frameName)->getPoseInRootFrame();
105 pcl::transformPointCloud(cloud, clouds[name], transform);
106
107 resultCloud->clear();
108 for (auto& kv : clouds)
109 {
110 const pcl::PointCloud<pcl::PointXYZ>& c = kv.second;
111 (*resultCloud) += c;
112 }
113 }
114 else
115 {
116 ARMARX_WARNING << deactivateSpam(5) << "Unknown frame for laser scanner: " << frameName;
117 }
118
119 if (resultCloud->empty())
120 {
122 << "Input point cloud is empty. Will not report anything.";
123 return;
124 }
125
126 pcl::PointCloud<pcl::PointXYZ>::Ptr cloudFiltered(new pcl::PointCloud<pcl::PointXYZ>());
127 filter.setInputCloud(resultCloud);
128 filter.filter(*cloudFiltered);
129
130
131 ARMARX_DEBUG << "Publishing point cloud";
132 providePointCloud(cloudFiltered);
133 }
134
137 {
140
141 def->topic<LaserScannerUnitListener>(
142 "LaserScans", "laser_scanner_topic", "Name of the laser scanner topic.");
143
144 return def;
145 }
146
147 visionx::MetaPointCloudFormatPtr
149 {
150 visionx::MetaPointCloudFormatPtr info = new visionx::MetaPointCloudFormat();
151 info->capacity = MAX_LASER_SCANNER_POINTS * sizeof(visionx::Point3D);
152 info->size = info->capacity;
153 info->type = visionx::PointContentType::ePoints;
154 return info;
155 }
156
157 std::string
159 {
160 return "LaserScannerPointCloudProvider";
161 }
162
165
166} // namespace armarx
std::string timestamp()
#define ARMARX_REGISTER_COMPONENT_EXECUTABLE(ComponentT, applicationName)
Definition Decoupled.h:29
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)
Brief description of class LaserScannerPointCloudProvider.
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.