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