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 
31 
33 
34 #include <cfloat>
35 
36 namespace armarx
37 {
39  {
40  usingTopic(getProperty<std::string>("LaserScannerTopicName").getValue());
41 
46  }
47 
48 
49 
51  {
52  }
53 
54 
56  {
57  }
58 
59 
61  {
63  }
64 
65  void LaserScannerUnitObserver::reportSensorValues(const std::string& device, const std::string& name, const LaserScan& scan, const TimestampBasePtr& timestamp, const Ice::Current& c)
66  {
67  std::unique_lock lock(dataMutex);
68 
69  if (!existsChannel(device))
70  {
71  offerChannel(device, "laser scans");
72  }
73 
74  TimestampVariantPtr timestampPtr = TimestampVariantPtr::dynamicCast(timestamp);
75  offerOrUpdateDataField(device, "timestamp", timestampPtr, "Timestamp");
76 
77  // Calculate some statistics on the laser scan
78  float minDistance = FLT_MAX;
79  float minAngle = 0.0f;
80  float maxDistance = -FLT_MAX;
81  float maxAngle = 0.0f;
82  float distanceSum = 0.0f;
83  for (LaserScanStep const& step : scan)
84  {
85  distanceSum += step.distance;
86  if (step.distance < minDistance)
87  {
88  minDistance = step.distance;
89  minAngle = step.angle;
90  }
91  if (step.distance > maxDistance)
92  {
93  maxDistance = step.distance;
94  maxAngle = step.angle;
95  }
96  }
97 
98  if (scan.size() > 0)
99  {
100  offerOrUpdateDataField(device, "minDistance", minDistance, "minimal distance in scan");
101  offerOrUpdateDataField(device, "minAngle", minAngle, "angle with minimal distance in scan");
102  offerOrUpdateDataField(device, "maxDistance", maxDistance, "maximal distance in scan");
103  offerOrUpdateDataField(device, "maxAngle", maxAngle, "angle with maximal distance in scan");
104  float averageDistance = distanceSum / scan.size();
105  offerOrUpdateDataField(device, "averageDistance", averageDistance, "average distance in scan");
106  }
107 
108  updateChannel(device);
109  }
110 }
111 
armarx::Observer::updateChannel
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:715
armarx::LaserScannerUnitObserver::reportSensorValues
void reportSensorValues(const std::string &device, const std::string &name, const LaserScan &scan, const TimestampBasePtr &timestamp, const Ice::Current &c) override
Definition: LaserScannerUnitObserver.cpp:65
ConditionCheckEquals.h
Pose.h
armarx::Observer::offerOrUpdateDataField
bool offerOrUpdateDataField(std::string channelName, std::string datafieldName, const Variant &value, const std::string &description)
Definition: Observer.cpp:222
armarx::LaserScannerUnitObserver::onConnectObserver
void onConnectObserver() override
Framework hook.
Definition: LaserScannerUnitObserver.cpp:50
armarx::LaserScannerUnitObserverPropertyDefinitions
Definition: LaserScannerUnitObserver.h:40
armarx::ConditionCheckSmaller
Definition: ConditionCheckSmaller.h:40
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
armarx::Observer::existsChannel
bool existsChannel(const std::string &channelName) const
Definition: Observer.cpp:1433
IceInternal::Handle< TimestampVariant >
armarx::ConditionCheckUpdated
Definition: ConditionCheckUpdated.h:41
armarx::LaserScannerUnitObserver::onExitObserver
void onExitObserver() override
Framework hook.
Definition: LaserScannerUnitObserver.cpp:55
TimestampVariant.h
armarx::LaserScannerUnitObserver::createPropertyDefinitions
PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: LaserScannerUnitObserver.cpp:60
armarx::ManagedIceObject::usingTopic
void usingTopic(const std::string &name, bool orderedPublishing=false)
Registers a proxy for subscription after initialization.
Definition: ManagedIceObject.cpp:248
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:74
LaserScannerUnitObserver.h
ConditionCheckSmaller.h
armarx::LaserScannerUnitObserver::onInitObserver
void onInitObserver() override
Framework hook.
Definition: LaserScannerUnitObserver.cpp:38
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::ConditionCheckEquals
Definition: ConditionCheckEquals.h:46
armarx::Observer::offerConditionCheck
void offerConditionCheck(std::string checkName, ConditionCheck *conditionCheck)
Offer a condition check.
Definition: Observer.cpp:273
ConditionCheckLarger.h
armarx::ConditionCheckLarger
Definition: ConditionCheckLarger.h:40
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:34
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
ConditionCheckUpdated.h
armarx::Observer::offerChannel
void offerChannel(std::string channelName, std::string description)
Offer a channel.
Definition: Observer.cpp:126