LaserScannerUnitObserver.cpp
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 * @author Fabian Paus ( fabian dot paus at kit dot edu )
19 * @date 2017
20 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
21 * GNU General Public License
22 */
24
25#include <cfloat>
26
32
34
35namespace armarx
36{
37 void
47
48 void
52
53 void
57
64
65 void
67 const std::string& name,
68 const LaserScan& scan,
69 const TimestampBasePtr& timestamp,
70 const Ice::Current& c)
71 {
72 std::unique_lock lock(dataMutex);
73
74 if (!existsChannel(device))
75 {
76 offerChannel(device, "laser scans");
77 }
78
79 TimestampVariantPtr timestampPtr = TimestampVariantPtr::dynamicCast(timestamp);
80 offerOrUpdateDataField(device, "timestamp", timestampPtr, "Timestamp");
81
82 // Calculate some statistics on the laser scan
83 float minDistance = FLT_MAX;
84 float minAngle = 0.0f;
85 float maxDistance = -FLT_MAX;
86 float maxAngle = 0.0f;
87 float distanceSum = 0.0f;
88 for (LaserScanStep const& step : scan)
89 {
90 distanceSum += step.distance;
91 if (step.distance < minDistance)
92 {
93 minDistance = step.distance;
94 minAngle = step.angle;
95 }
96 if (step.distance > maxDistance)
97 {
98 maxDistance = step.distance;
99 maxAngle = step.angle;
100 }
101 }
102
103 if (scan.size() > 0)
104 {
105 offerOrUpdateDataField(device, "minDistance", minDistance, "minimal distance in scan");
107 device, "minAngle", minAngle, "angle with minimal distance in scan");
108 offerOrUpdateDataField(device, "maxDistance", maxDistance, "maximal distance in scan");
110 device, "maxAngle", maxAngle, "angle with maximal distance in scan");
111 float averageDistance = distanceSum / scan.size();
113 device, "averageDistance", averageDistance, "average distance in scan");
114 }
115
116 updateChannel(device);
117 }
118} // namespace armarx
std::string timestamp()
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)
Checks if the numbers published in the relevant data fields equal a reference value.
Checks if the numbers published in the relevant data fields are larger than a reference value.
Checks if the numbers published in the relevant data fields are smaller than a reference value.
Checks if the relevant data fields have been updated since the installation of this condition.
void onConnectObserver() override
Framework hook.
void onExitObserver() override
Framework hook.
PropertyDefinitionsPtr createPropertyDefinitions() override
void reportSensorValues(const std::string &device, const std::string &name, const LaserScan &scan, const TimestampBasePtr &timestamp, const Ice::Current &c) override
void onInitObserver() override
Framework hook.
void usingTopic(const std::string &name, bool orderedPublishing=false)
Registers a proxy for subscription after initialization.
bool existsChannel(const std::string &channelName) const
void offerChannel(std::string channelName, std::string description)
Offer a channel.
Definition Observer.cpp:131
void offerConditionCheck(std::string checkName, ConditionCheck *conditionCheck)
Offer a condition check.
Definition Observer.cpp:301
void updateChannel(const std::string &channelName, const std::set< std::string > &updatedDatafields=std::set< std::string >())
Update all conditions for a channel.
Definition Observer.cpp:788
bool offerOrUpdateDataField(std::string channelName, std::string datafieldName, const Variant &value, const std::string &description)
Definition Observer.cpp:242
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
IceInternal::Handle< TimestampVariant > TimestampVariantPtr