MetaWearIMUObserver.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 "MetaWearIMUObserver.h"
25
31
33
34namespace armarx
35{
36 void
38 {
39 usingTopic(getProperty<std::string>("MetaWearTopicName").getValue());
40
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
60
61 void
63 const MetaWearIMUData& data,
64 const TimestampBasePtr& timestamp,
65 const Ice::Current&)
66 {
67 std::unique_lock lock(dataMutex);
68
69 if (!existsChannel(name))
70 {
71 offerChannel(name, "MetaWear IMU data");
72 }
73 offerVector3(name, "acceleration", data.acceleration);
74 offerVector3(name, "gyro", data.gyro);
75 offerVector3(name, "magnetic", data.magnetic);
76 offerQuaternion(name, "orientationQuaternion", data.orientationQuaternion);
77
78 updateChannel(name);
79 }
80
87
88 void
89 MetaWearIMUObserver::offerVector3(const std::string& channelName,
90 const std::string& dfName,
91 const std::vector<float>& data)
92 {
93 if (data.size() == 3)
94 {
95 Vector3Ptr vec3 = new Vector3(data.at(0), data.at(1), data.at(2));
96 offerOrUpdateDataField(channelName, dfName, vec3, dfName);
97 }
98 else if (data.size() != 0)
99 {
100 ARMARX_WARNING << "data." << dfName << ".size() != 3 && data." << dfName
101 << ".size() != 0";
102 }
103 }
104
105 void
106 MetaWearIMUObserver::offerQuaternion(const std::string& channelName,
107 const std::string& dfName,
108 const std::vector<float>& data)
109 {
110 if (data.size() == 4)
111 {
112 QuaternionPtr quat = new Quaternion(data.at(0), data.at(1), data.at(2), data.at(3));
113 offerOrUpdateDataField(channelName, dfName, quat, dfName);
114 }
115 else if (data.size() != 0)
116 {
117 ARMARX_WARNING << "data." << dfName << ".size() != 4 && data." << dfName
118 << ".size() != 0";
119 }
120 }
121} // namespace armarx
std::string timestamp()
uint8_t data[1]
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 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.
void onConnectObserver() override
Framework hook.
void onExitObserver() override
Framework hook.
void reportIMUValues(const std::string &name, const MetaWearIMUData &data, const TimestampBasePtr &timestamp, const Ice::Current &) override
PropertyDefinitionsPtr createPropertyDefinitions() override
void onInitObserver() override
Framework hook.
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 Vector3 class.
Definition Pose.h:113
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:193
const VariantTypeId Quaternion
Definition Pose.h:39
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< Vector3 > Vector3Ptr
Definition Pose.h:165
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
IceInternal::Handle< Quaternion > QuaternionPtr
Definition Pose.h:234