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 namespace armarx
36 {
37  void
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 
53  void
55  {
56  if (getProperty<bool>("EnableVisualization").getValue())
57  {
58  debugDrawerPrx = getTopic<DebugDrawerInterfacePrx>(
59  getProperty<std::string>("DebugDrawerTopic").getValue());
60  }
61  }
62 
63  void
65  {
66  if (getProperty<bool>("EnableVisualization").getValue())
67  {
68  debugDrawerPrx->removePoseVisu("IMU", "orientation");
69  debugDrawerPrx->removeLineVisu("IMU", "acceleration");
70  }
71  }
72 
73  void
75  const std::string& name,
76  const IMUData& values,
77  const TimestampBasePtr& timestamp,
78  const Ice::Current&)
79  {
80  std::unique_lock lock(dataMutex);
81 
82  TimestampVariantPtr timestampPtr = TimestampVariantPtr::dynamicCast(timestamp);
83 
84 
85  if (!existsChannel(device))
86  {
87  offerChannel(device, "IMU data");
88  }
89 
90  offerOrUpdateDataField(device, "name", Variant(name), "Name of the IMU sensor");
91  Vector3Ptr acceleration;
92  QuaternionPtr orientationQuaternion;
93  if (values.acceleration.size() > 0)
94  {
95  ARMARX_CHECK_EXPRESSION(values.acceleration.size() == 3);
96  acceleration = new Vector3(
97  values.acceleration.at(0), values.acceleration.at(1), values.acceleration.at(2));
98  offerValue(device, "acceleration", acceleration);
99  }
100  if (values.gyroscopeRotation.size() > 0)
101  {
102  ARMARX_CHECK_EXPRESSION(values.gyroscopeRotation.size() == 3);
103  Vector3Ptr gyroscopeRotation = new Vector3(values.gyroscopeRotation.at(0),
104  values.gyroscopeRotation.at(1),
105  values.gyroscopeRotation.at(2));
106  offerValue(device, "gyroscopeRotation", gyroscopeRotation);
107  }
108  if (values.magneticRotation.size() > 0)
109  {
110  ARMARX_CHECK_EXPRESSION(values.magneticRotation.size() == 3);
111  Vector3Ptr magneticRotation = new Vector3(values.magneticRotation.at(0),
112  values.magneticRotation.at(1),
113  values.magneticRotation.at(2));
114  offerValue(device, "magneticRotation", magneticRotation);
115  }
116  if (values.orientationQuaternion.size() > 0)
117  {
118  ARMARX_CHECK_EXPRESSION(values.orientationQuaternion.size() == 4);
119  orientationQuaternion = new Quaternion(values.orientationQuaternion.at(0),
120  values.orientationQuaternion.at(1),
121  values.orientationQuaternion.at(2),
122  values.orientationQuaternion.at(3));
123  offerOrUpdateDataField(device,
124  "orientationQuaternion",
125  orientationQuaternion,
126  "orientation quaternion values");
127  }
128  offerOrUpdateDataField(device, "timestamp", timestampPtr, "Timestamp");
129 
130  updateChannel(device);
131 
132 
133  if (orientationQuaternion && acceleration &&
134  getProperty<bool>("EnableVisualization").getValue())
135  {
136  Eigen::Vector3f zero;
137  zero.setZero();
138 
139  DrawColor color;
140  color.r = 1;
141  color.g = 1;
142  color.b = 0;
143  color.a = 0.5;
144 
145  Eigen::Vector3f ac = acceleration->toEigen();
146  ac *= 10;
147 
148  debugDrawerPrx->setLineVisu(
149  "IMU", "acceleration", new Vector3(), new Vector3(ac), 2.0f, color);
150 
151  PosePtr posePtr = new Pose(orientationQuaternion->toEigen(), zero);
152  debugDrawerPrx->setPoseVisu("IMU", "orientation", posePtr);
153  // debugDrawerPrx->setBoxDebugLayerVisu("floor", new Pose(), new Vector3(5000, 5000, 1), DrawColor {0.7f, 0.7f, 0.7f, 1.0f});
154  }
155  }
156 
157  void
158  InertialMeasurementUnitObserver::offerValue(const std::string& device,
159  const std::string& fieldName,
160  const Vector3Ptr& vec)
161  {
162  offerOrUpdateDataField(device, fieldName, vec, fieldName + " values");
163  offerOrUpdateDataField(device, fieldName + "_x", vec->x, fieldName + "_x value");
164  offerOrUpdateDataField(device, fieldName + "_y", vec->y, fieldName + "_y value");
165  offerOrUpdateDataField(device, fieldName + "_z", vec->z, fieldName + "_z value");
166  }
167 
170  {
171  return PropertyDefinitionsPtr(
173  }
174 } // 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
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:169
armarx::Observer::offerOrUpdateDataField
bool offerOrUpdateDataField(std::string channelName, std::string datafieldName, const Variant &value, const std::string &description)
Definition: Observer.cpp:242
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:1552
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:74
armarx::ConditionCheckUpdated
Definition: ConditionCheckUpdated.h:41
TimestampVariant.h
ExpressionException.h
armarx::InertialMeasurementUnitObserver::onExitObserver
void onExitObserver() override
Framework hook.
Definition: InertialMeasurementUnitObserver.cpp:64
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
armarx::InertialMeasurementUnitObserverPropertyDefinitions
Definition: InertialMeasurementUnitObserver.h:41
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:300
memoryx::KBM::Vector3
Eigen::Vector3d Vector3
Definition: kbm.h:43
armarx::InertialMeasurementUnitObserver::onConnectObserver
void onConnectObserver() override
Framework hook.
Definition: InertialMeasurementUnitObserver.cpp:54
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
InertialMeasurementUnitObserver.h
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