InertialMeasurementUnitObserver.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 RobotAPI::units
19  * @author David Schiebener <schiebener at kit dot edu>
20  * @date 2014
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
25 
32 
34 
35 
36 namespace armarx
37 {
39  {
40  usingTopic(getProperty<std::string>("IMUTopicName").getValue());
41 
46 
47  if (getProperty<bool>("EnableVisualization").getValue())
48  {
49  offeringTopic(getProperty<std::string>("DebugDrawerTopic").getValue());
50  }
51  }
52 
54  {
55  if (getProperty<bool>("EnableVisualization").getValue())
56  {
57  debugDrawerPrx = getTopic<DebugDrawerInterfacePrx>(getProperty<std::string>("DebugDrawerTopic").getValue());
58  }
59  }
60 
62  {
63  if (getProperty<bool>("EnableVisualization").getValue())
64  {
65  debugDrawerPrx->removePoseVisu("IMU", "orientation");
66  debugDrawerPrx->removeLineVisu("IMU", "acceleration");
67  }
68  }
69 
71  const std::string& device, const std::string& name, const IMUData& values,
72  const TimestampBasePtr& timestamp, const Ice::Current&)
73  {
74  std::unique_lock lock(dataMutex);
75 
76  TimestampVariantPtr timestampPtr = TimestampVariantPtr::dynamicCast(timestamp);
77 
78 
79  if (!existsChannel(device))
80  {
81  offerChannel(device, "IMU data");
82  }
83 
84  offerOrUpdateDataField(device, "name", Variant(name), "Name of the IMU sensor");
85  Vector3Ptr acceleration;
86  QuaternionPtr orientationQuaternion;
87  if (values.acceleration.size() > 0)
88  {
89  ARMARX_CHECK_EXPRESSION(values.acceleration.size() == 3);
90  acceleration = new Vector3(values.acceleration.at(0), values.acceleration.at(1), values.acceleration.at(2));
91  offerValue(device, "acceleration", acceleration);
92  }
93  if (values.gyroscopeRotation.size() > 0)
94  {
95  ARMARX_CHECK_EXPRESSION(values.gyroscopeRotation.size() == 3);
96  Vector3Ptr gyroscopeRotation = new Vector3(values.gyroscopeRotation.at(0), values.gyroscopeRotation.at(1), values.gyroscopeRotation.at(2));
97  offerValue(device, "gyroscopeRotation", gyroscopeRotation);
98  }
99  if (values.magneticRotation.size() > 0)
100  {
101  ARMARX_CHECK_EXPRESSION(values.magneticRotation.size() == 3);
102  Vector3Ptr magneticRotation = new Vector3(values.magneticRotation.at(0), values.magneticRotation.at(1), values.magneticRotation.at(2));
103  offerValue(device, "magneticRotation", magneticRotation);
104  }
105  if (values.orientationQuaternion.size() > 0)
106  {
107  ARMARX_CHECK_EXPRESSION(values.orientationQuaternion.size() == 4);
108  orientationQuaternion = new Quaternion(values.orientationQuaternion.at(0), values.orientationQuaternion.at(1), values.orientationQuaternion.at(2), values.orientationQuaternion.at(3));
109  offerOrUpdateDataField(device, "orientationQuaternion", orientationQuaternion, "orientation quaternion values");
110  }
111  offerOrUpdateDataField(device, "timestamp", timestampPtr, "Timestamp");
112 
113  updateChannel(device);
114 
115 
116 
117  if (orientationQuaternion && acceleration && getProperty<bool>("EnableVisualization").getValue())
118  {
119  Eigen::Vector3f zero;
120  zero.setZero();
121 
122  DrawColor color;
123  color.r = 1;
124  color.g = 1;
125  color.b = 0;
126  color.a = 0.5;
127 
128  Eigen::Vector3f ac = acceleration->toEigen();
129  ac *= 10;
130 
131  debugDrawerPrx->setLineVisu("IMU", "acceleration", new Vector3(), new Vector3(ac), 2.0f, color);
132 
133  PosePtr posePtr = new Pose(orientationQuaternion->toEigen(), zero);
134  debugDrawerPrx->setPoseVisu("IMU", "orientation", posePtr);
135  // debugDrawerPrx->setBoxDebugLayerVisu("floor", new Pose(), new Vector3(5000, 5000, 1), DrawColor {0.7f, 0.7f, 0.7f, 1.0f});
136  }
137  }
138 
139  void InertialMeasurementUnitObserver::offerValue(const std::string& device, const std::string& fieldName, const Vector3Ptr& vec)
140  {
141  offerOrUpdateDataField(device, fieldName, vec, fieldName + " values");
142  offerOrUpdateDataField(device, fieldName + "_x", vec->x, fieldName + "_x value");
143  offerOrUpdateDataField(device, fieldName + "_y", vec->y, fieldName + "_y value");
144  offerOrUpdateDataField(device, fieldName + "_z", vec->z, fieldName + "_z value");
145  }
146 
148  {
150  }
151 }
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
armarx::navigation::core::Pose
Eigen::Isometry3f Pose
Definition: basic_types.h:31
ConditionCheckEquals.h
Pose.h
armarx::InertialMeasurementUnitObserver::onInitObserver
void onInitObserver() override
Framework hook.
Definition: InertialMeasurementUnitObserver.cpp:38
armarx::InertialMeasurementUnitObserver::createPropertyDefinitions
PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: InertialMeasurementUnitObserver.cpp:147
armarx::Observer::offerOrUpdateDataField
bool offerOrUpdateDataField(std::string channelName, std::string datafieldName, const Variant &value, const std::string &description)
Definition: Observer.cpp:222
ProsthesisInterface.values
values
Definition: ProsthesisInterface.py:190
armarx::ConditionCheckSmaller
Definition: ConditionCheckSmaller.h:40
armarx::Observer::existsChannel
bool existsChannel(const std::string &channelName) const
Definition: Observer.cpp:1433
armarx::VariantType::Quaternion
const VariantTypeId Quaternion
Definition: Pose.h:39
IceInternal::Handle< TimestampVariant >
armarx::InertialMeasurementUnitObserver::reportSensorValues
void reportSensorValues(const std::string &device, const std::string &name, const IMUData &values, const TimestampBasePtr &timestamp, const Ice::Current &c=Ice::emptyCurrent) override
Definition: InertialMeasurementUnitObserver.cpp:70
armarx::ConditionCheckUpdated
Definition: ConditionCheckUpdated.h:41
TimestampVariant.h
ExpressionException.h
armarx::InertialMeasurementUnitObserver::onExitObserver
void onExitObserver() override
Framework hook.
Definition: InertialMeasurementUnitObserver.cpp:61
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
armarx::InertialMeasurementUnitObserverPropertyDefinitions
Definition: InertialMeasurementUnitObserver.h:40
ARMARX_CHECK_EXPRESSION
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
Definition: ExpressionException.h:73
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::InertialMeasurementUnitObserver::onConnectObserver
void onConnectObserver() override
Framework hook.
Definition: InertialMeasurementUnitObserver.cpp:53
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
InertialMeasurementUnitObserver.h
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