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
35namespace 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));
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
174} // namespace armarx
std::string timestamp()
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition Component.cpp:90
Property< PropertyType > getProperty(const std::string &name)
Checks if the numbers published in the relevant data fields equal a reference value.
Checks if the numbers published in the relevant data fields are larger than a reference value.
Checks if the numbers published in the relevant data fields are smaller than a reference value.
Checks if the relevant data fields have been updated since the installation of this condition.
void reportSensorValues(const std::string &device, const std::string &name, const IMUData &values, const TimestampBasePtr &timestamp, const Ice::Current &c=Ice::emptyCurrent) override
PropertyDefinitionsPtr createPropertyDefinitions() override
void offeringTopic(const std::string &name)
Registers a topic for retrival after initialization.
TopicProxyType getTopic(const std::string &name)
Returns a proxy of the specified topic.
void usingTopic(const std::string &name, bool orderedPublishing=false)
Registers a proxy for subscription after initialization.
bool existsChannel(const std::string &channelName) const
void offerChannel(std::string channelName, std::string description)
Offer a channel.
Definition Observer.cpp:131
void offerConditionCheck(std::string checkName, ConditionCheck *conditionCheck)
Offer a condition check.
Definition Observer.cpp:301
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
bool offerOrUpdateDataField(std::string channelName, std::string datafieldName, const Variant &value, const std::string &description)
Definition Observer.cpp:242
The Pose class.
Definition Pose.h:243
The Quaternion class.
Definition Pose.h:174
The Variant class is described here: Variants.
Definition Variant.h:224
The Vector3 class.
Definition Pose.h:113
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< Vector3 > Vector3Ptr
Definition Pose.h:165
IceInternal::Handle< Pose > PosePtr
Definition Pose.h:306
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
IceInternal::Handle< Quaternion > QuaternionPtr
Definition Pose.h:234
IceInternal::Handle< TimestampVariant > TimestampVariantPtr