OptoForceUnitObserver.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  * @package
19  * @author
20  * @date
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 #include "OptoForceUnitObserver.h"
25 
31 
33 
34 namespace armarx
35 {
36  void
38  {
39  usingTopic(getProperty<std::string>("OptoForceTopicName").getValue());
40 
41  //offerConditionCheck("updated", new ConditionCheckUpdated());
42  //offerConditionCheck("larger", new ConditionCheckLarger());
43  //offerConditionCheck("equals", new ConditionCheckEquals());
44  //offerConditionCheck("smaller", new ConditionCheckSmaller());
45 
46  offeringTopic(getProperty<std::string>("DebugDrawerTopic").getValue());
47  }
48 
49  void
51  {
52  debugDrawerPrx = getTopic<DebugDrawerInterfacePrx>(
53  getProperty<std::string>("DebugDrawerTopic").getValue());
54  }
55 
56  void
58  {
59  //debugDrawerPrx->removePoseVisu("IMU", "orientation");
60  //debugDrawerPrx->removeLineVisu("IMU", "acceleration");
61  }
62 
63  void
64  OptoForceUnitObserver::reportSensorValues(const std::string& device,
65  const std::string& name,
66  float fx,
67  float fy,
68  float fz,
69  const TimestampBasePtr& timestamp,
70  const Ice::Current& c)
71  {
72  std::unique_lock lock(dataMutex);
73  TimestampVariantPtr timestampPtr = TimestampVariantPtr::dynamicCast(timestamp);
74 
75  if (!existsChannel(name))
76  {
77  offerChannel(name, "Force data");
78  }
79 
80  offerOrUpdateDataField(name, "name", Variant(name), "Name of the sensor");
81  offerOrUpdateDataField(name, "device", Variant(device), "Device name");
82  offerOrUpdateDataField(name, "fx", Variant(fx), "Force x");
83  offerOrUpdateDataField(name, "fy", Variant(fy), "Force y");
84  offerOrUpdateDataField(name, "fz", Variant(fz), "Force z");
85  offerOrUpdateDataField(name, "timestamp", timestampPtr, "Timestamp");
86  offerOrUpdateDataField(name, "force", Vector3(fx, fy, fz), "Force");
87 
88  updateChannel(name);
89  }
90 
91  /*void OptoForceUnitObserver::reportSensorValues(const std::string& device, const std::string& name, const IMUData& values, const TimestampBasePtr& timestamp, const Ice::Current& c)
92  {
93  std::unique_lock lock(dataMutex);
94 
95  TimestampVariantPtr timestampPtr = TimestampVariantPtr::dynamicCast(timestamp);
96 
97  Vector3Ptr acceleration = new Vector3(values.acceleration.at(0), values.acceleration.at(1), values.acceleration.at(2));
98  Vector3Ptr gyroscopeRotation = new Vector3(values.gyroscopeRotation.at(0), values.gyroscopeRotation.at(1), values.gyroscopeRotation.at(2));
99  Vector3Ptr magneticRotation = new Vector3(values.magneticRotation.at(0), values.magneticRotation.at(1), values.magneticRotation.at(2));
100  QuaternionPtr orientationQuaternion = new Quaternion(values.orientationQuaternion.at(0), values.orientationQuaternion.at(1), values.orientationQuaternion.at(2), values.orientationQuaternion.at(3));
101 
102  if (!existsChannel(device))
103  {
104  offerChannel(device, "IMU data");
105  }
106 
107  offerOrUpdateDataField(device, "name", Variant(name), "Name of the IMU sensor");
108  offerValue(device, "acceleration", acceleration);
109  offerValue(device, "gyroscopeRotation", gyroscopeRotation);
110  offerValue(device, "magneticRotation", magneticRotation);
111  offerValue(device, "acceleration", acceleration);
112  offerOrUpdateDataField(device, "orientationQuaternion", orientationQuaternion, "orientation quaternion values");
113  offerOrUpdateDataField(device, "timestamp", timestampPtr, "Timestamp");
114 
115  updateChannel(device);
116 
117  Eigen::Vector3f zero;
118  zero.setZero();
119 
120  DrawColor color;
121  color.r = 1;
122  color.g = 1;
123  color.b = 0;
124  color.a = 0.5;
125 
126  Eigen::Vector3f ac = acceleration->toEigen();
127  ac *= 10;
128 
129  debugDrawerPrx->setLineVisu("IMU", "acceleration", new Vector3(), new Vector3(ac), 2.0f, color);
130 
131  PosePtr posePtr = new Pose(orientationQuaternion->toEigen(), zero);
132  debugDrawerPrx->setPoseVisu("IMU", "orientation", posePtr);
133  debugDrawerPrx->setBoxDebugLayerVisu("floor", new Pose(), new Vector3(5000, 5000, 1), DrawColor {0.7f, 0.7f, 0.7f, 1.0f});
134  }*/
135 
136  void
137  OptoForceUnitObserver::offerValue(std::string device, std::string fieldName, Vector3Ptr vec)
138  {
139  offerOrUpdateDataField(device, fieldName, vec, fieldName + " values");
140  offerOrUpdateDataField(device, fieldName + "_x", vec->x, fieldName + "_x value");
141  offerOrUpdateDataField(device, fieldName + "_y", vec->y, fieldName + "_y value");
142  offerOrUpdateDataField(device, fieldName + "_z", vec->z, fieldName + "_z value");
143  }
144 
147  {
148  return PropertyDefinitionsPtr(
150  }
151 } // 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::Variant
The Variant class is described here: Variants.
Definition: Variant.h:223
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::OptoForceUnitObserver::onInitObserver
void onInitObserver() override
Framework hook.
Definition: OptoForceUnitObserver.cpp:37
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:46
armarx::OptoForceUnitObserver::reportSensorValues
void reportSensorValues(const std::string &device, const std::string &name, float fx, float fy, float fz, const TimestampBasePtr &timestamp, const Ice::Current &c=Ice::emptyCurrent) override
Definition: OptoForceUnitObserver.cpp:64
armarx::Observer::existsChannel
bool existsChannel(const std::string &channelName) const
Definition: Observer.cpp:1552
IceInternal::Handle< TimestampVariant >
TimestampVariant.h
timestamp
std::string timestamp()
Definition: CartographerAdapter.cpp:85
armarx::OptoForceUnitObserverPropertyDefinitions
Definition: OptoForceUnitObserver.h:41
armarx::OptoForceUnitObserver::onConnectObserver
void onConnectObserver() override
Framework hook.
Definition: OptoForceUnitObserver.cpp:50
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
ConditionCheckSmaller.h
armarx::ManagedIceObject::offeringTopic
void offeringTopic(const std::string &name)
Registers a topic for retrival after initialization.
Definition: ManagedIceObject.cpp:300
memoryx::KBM::Vector3
Eigen::Vector3d Vector3
Definition: kbm.h:43
armarx::OptoForceUnitObserver::createPropertyDefinitions
PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: OptoForceUnitObserver.cpp:146
armarx::OptoForceUnitObserver::onExitObserver
void onExitObserver() override
Framework hook.
Definition: OptoForceUnitObserver.cpp:57
OptoForceUnitObserver.h
ConditionCheckLarger.h
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