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 
34 namespace 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
58  {
59  }
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 
83  {
86  }
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
armarx::MetaWearIMUObserver::createPropertyDefinitions
PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: MetaWearIMUObserver.cpp:82
armarx::MetaWearIMUObserver::onConnectObserver
void onConnectObserver() override
Framework hook.
Definition: MetaWearIMUObserver.cpp:50
GfxTL::vec3
VectorXD< 3, float > vec3
Definition: VectorXD.h:725
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:242
armarx::ConditionCheckSmaller
Definition: ConditionCheckSmaller.h:40
armarx::VariantType::Quaternion
const VariantTypeId Quaternion
Definition: Pose.h:39
IceInternal::Handle< Vector3 >
armarx::MetaWearIMUObserver::onExitObserver
void onExitObserver() override
Framework hook.
Definition: MetaWearIMUObserver.cpp:57
armarx::ConditionCheckUpdated
Definition: ConditionCheckUpdated.h:41
armarx::MetaWearIMUObserver::onInitObserver
void onInitObserver() override
Framework hook.
Definition: MetaWearIMUObserver.cpp:37
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
armarx::QuaternionPtr
IceInternal::Handle< Quaternion > QuaternionPtr
Definition: Pose.h:234
TimestampVariant.h
armarx::MetaWearIMUObserverPropertyDefinitions
Definition: MetaWearIMUObserver.h:41
timestamp
std::string timestamp()
Definition: CartographerAdapter.cpp:85
MetaWearIMUObserver.h
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::MetaWearIMUObserver::reportIMUValues
void reportIMUValues(const std::string &name, const MetaWearIMUData &data, const TimestampBasePtr &timestamp, const Ice::Current &) override
Definition: MetaWearIMUObserver.cpp:62
ConditionCheckSmaller.h
armarx::ManagedIceObject::offeringTopic
void offeringTopic(const std::string &name)
Registers a topic for retrival after initialization.
Definition: ManagedIceObject.cpp:300
IceUtil::Handle
Definition: forward_declarations.h:30
memoryx::KBM::Vector3
Eigen::Vector3d Vector3
Definition: kbm.h:43
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_WARNING
#define ARMARX_WARNING
Definition: Logging.h:193
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:35
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
ConditionCheckUpdated.h