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 
35 namespace armarx
36 {
37  void
39  {
40  usingTopic(getProperty<std::string>("LaserScannerTopicName").getValue());
41 
46  }
47 
48  void
50  {
51  }
52 
53  void
55  {
56  }
57 
60  {
63  }
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
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:788
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:66
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:242
armarx::LaserScannerUnitObserver::onConnectObserver
void onConnectObserver() override
Framework hook.
Definition: LaserScannerUnitObserver.cpp:49
armarx::LaserScannerUnitObserverPropertyDefinitions
Definition: LaserScannerUnitObserver.h:41
armarx::ConditionCheckSmaller
Definition: ConditionCheckSmaller.h:40
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:46
armarx::Observer::existsChannel
bool existsChannel(const std::string &channelName) const
Definition: Observer.cpp:1552
IceInternal::Handle< TimestampVariant >
armarx::ConditionCheckUpdated
Definition: ConditionCheckUpdated.h:41
armarx::LaserScannerUnitObserver::onExitObserver
void onExitObserver() override
Framework hook.
Definition: LaserScannerUnitObserver.cpp:54
TimestampVariant.h
armarx::LaserScannerUnitObserver::createPropertyDefinitions
PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: LaserScannerUnitObserver.cpp:59
armarx::ManagedIceObject::usingTopic
void usingTopic(const std::string &name, bool orderedPublishing=false)
Registers a proxy for subscription after initialization.
Definition: ManagedIceObject.cpp:254
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:79
LaserScannerUnitObserver.h
ConditionCheckSmaller.h
armarx::LaserScannerUnitObserver::onInitObserver
void onInitObserver() override
Framework hook.
Definition: LaserScannerUnitObserver.cpp:38
IceUtil::Handle
Definition: forward_declarations.h:30
armarx::ConditionCheckEquals
Definition: ConditionCheckEquals.h:46
armarx::Observer::offerConditionCheck
void offerConditionCheck(std::string checkName, ConditionCheck *conditionCheck)
Offer a condition check.
Definition: Observer.cpp:301
ConditionCheckLarger.h
armarx::ConditionCheckLarger
Definition: ConditionCheckLarger.h:40
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:35
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
ConditionCheckUpdated.h
armarx::Observer::offerChannel
void offerChannel(std::string channelName, std::string description)
Offer a channel.
Definition: Observer.cpp:131