CyberGloveObserver.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * ArmarX is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * ArmarX is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * @package RobotAPI::ArmarXObjects::CyberGloveObserver
17  * @author JuliaStarke ( julia dot starke at kit dot edu )
18  * @date 2018
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 #include "CyberGloveObserver.h"
24 
26 
27 namespace armarx
28 {
29  void
31  {
32  usingTopic(getProperty<std::string>("CyberGloveTopicName").getValue());
33  }
34 
35  void
37  {
38  lastUpdate = TimeUtil::GetTime();
39  }
40 
41  //void CyberGloveObserver::onDisconnectComponent()
42  //{
43 
44  //}
45 
46 
47  void
49  {
50  }
51 
54  {
57  }
58 
59  void
60  CyberGloveObserver::reportGloveValues(const CyberGloveValues& gloveValues, const Ice::Current&)
61  {
62  std::unique_lock lock(dataMutex);
63 
65 
66  long deltaUS = (now - lastUpdate).toMicroSeconds();
67 
68  ARMARX_IMPORTANT << deltaUS << " " << gloveValues.time << " " << gloveValues.indexDIP;
69  lastUpdate = now;
70 
71  latestValues = gloveValues;
72 
73 
74  std::string name = gloveValues.name;
75  if (!existsChannel(name))
76  {
77  offerChannel(name, "CyberGlove motor data");
78  }
79 
80  offerOrUpdateDataField(name, "name", Variant(name), "Name of the prostesis");
81 
83  name, "thumbCMC", Variant(gloveValues.thumbCMC), "Value of thumbCMC");
85  name, "thumbMCP", Variant(gloveValues.thumbMCP), "Value of thumbMCP");
86  offerOrUpdateDataField(name, "thumbIP", Variant(gloveValues.thumbIP), "Value of thumbIP");
88  name, "thumbAbd", Variant(gloveValues.thumbAbd), "Value of thumbAbd");
90  name, "indexMCP", Variant(gloveValues.indexMCP), "Value of indexMCP");
92  name, "indexPIP", Variant(gloveValues.indexPIP), "Value of indexPIP");
94  name, "indexDIP", Variant(gloveValues.indexDIP), "Value of indexDIP");
96  name, "middleMCP", Variant(gloveValues.middleMCP), "Value of middleMCP");
98  name, "middlePIP", Variant(gloveValues.middlePIP), "Value of middlePIP");
100  name, "middleDIP", Variant(gloveValues.middleDIP), "Value of middleDIP");
102  name, "middleAbd", Variant(gloveValues.middleAbd), "Value of middleAbd");
103  offerOrUpdateDataField(name, "ringMCP", Variant(gloveValues.ringMCP), "Value of ringMCP");
104  offerOrUpdateDataField(name, "ringPIP", Variant(gloveValues.ringPIP), "Value of ringPIP");
105  offerOrUpdateDataField(name, "ringDIP", Variant(gloveValues.ringDIP), "Value of ringDIP");
106  offerOrUpdateDataField(name, "ringAbd", Variant(gloveValues.ringAbd), "Value of ringAbd");
108  name, "littleMCP", Variant(gloveValues.littleMCP), "Value of littleMCP");
110  name, "littlePIP", Variant(gloveValues.littlePIP), "Value of littlePIP");
112  name, "littleDIP", Variant(gloveValues.littleDIP), "Value of littleDIP");
114  name, "littleAbd", Variant(gloveValues.littleAbd), "Value of littleAbd");
116  name, "palmArch", Variant(gloveValues.palmArch), "Value of palmArch");
118  name, "wristFlex", Variant(gloveValues.wristFlex), "Value of wristFlex");
120  name, "wristAbd", Variant(gloveValues.wristAbd), "Value of wristAbd");
121 
122 
123  updateChannel(name);
124  }
125 
128  {
129  std::unique_lock lock(dataMutex);
130  return latestValues;
131  }
132 } // 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::CyberGloveValues::middleMCP
int middleMCP
Definition: CyberGloveInterface.ice:41
armarx::CyberGloveValues::name
string name
Definition: CyberGloveInterface.ice:32
armarx::Variant
The Variant class is described here: Variants.
Definition: Variant.h:223
armarx::CyberGloveValues::wristFlex
int wristFlex
Definition: CyberGloveInterface.ice:54
ARMARX_IMPORTANT
#define ARMARX_IMPORTANT
Definition: Logging.h:190
armarx::CyberGloveValues::wristAbd
int wristAbd
Definition: CyberGloveInterface.ice:55
armarx::CyberGloveObserver::getLatestValues
CyberGloveValues getLatestValues(const Ice::Current &) override
Definition: CyberGloveObserver.cpp:127
armarx::CyberGloveValues::time
string time
Definition: CyberGloveInterface.ice:33
armarx::Observer::offerOrUpdateDataField
bool offerOrUpdateDataField(std::string channelName, std::string datafieldName, const Variant &value, const std::string &description)
Definition: Observer.cpp:242
armarx::CyberGloveValues::thumbAbd
int thumbAbd
Definition: CyberGloveInterface.ice:37
armarx::CyberGloveValues::littleMCP
int littleMCP
Definition: CyberGloveInterface.ice:49
armarx::Observer::existsChannel
bool existsChannel(const std::string &channelName) const
Definition: Observer.cpp:1552
armarx::CyberGloveValues::indexDIP
int indexDIP
Definition: CyberGloveInterface.ice:40
armarx::CyberGloveObserver::onExitObserver
void onExitObserver() override
Definition: CyberGloveObserver.cpp:48
armarx::CyberGloveObserver::reportGloveValues
void reportGloveValues(const CyberGloveValues &gloveValues, const Ice::Current &) override
Definition: CyberGloveObserver.cpp:60
armarx::CyberGloveObserver::onInitObserver
void onInitObserver() override
Definition: CyberGloveObserver.cpp:30
armarx::CyberGloveObserver::onConnectObserver
void onConnectObserver() override
Definition: CyberGloveObserver.cpp:36
armarx::CyberGloveValues::middleAbd
int middleAbd
Definition: CyberGloveInterface.ice:44
armarx::CyberGloveValues::thumbIP
int thumbIP
Definition: CyberGloveInterface.ice:36
TimestampVariant.h
armarx::CyberGloveValues::indexPIP
int indexPIP
Definition: CyberGloveInterface.ice:39
CyberGloveObserver.h
armarx::CyberGloveValues
Definition: CyberGloveInterface.ice:30
armarx::CyberGloveValues::middlePIP
int middlePIP
Definition: CyberGloveInterface.ice:42
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
armarx::TimeUtil::GetTime
static IceUtil::Time GetTime(TimeMode timeMode=TimeMode::VirtualTime)
Get the current time.
Definition: TimeUtil.cpp:42
armarx::CyberGloveValues::ringPIP
int ringPIP
Definition: CyberGloveInterface.ice:46
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::CyberGloveValues::ringAbd
int ringAbd
Definition: CyberGloveInterface.ice:48
armarx::CyberGloveValues::thumbMCP
int thumbMCP
Definition: CyberGloveInterface.ice:35
armarx::CyberGloveValues::ringDIP
int ringDIP
Definition: CyberGloveInterface.ice:47
IceUtil::Handle
Definition: forward_declarations.h:30
armarx::CyberGloveValues::littleDIP
int littleDIP
Definition: CyberGloveInterface.ice:51
armarx::CyberGloveValues::indexMCP
int indexMCP
Definition: CyberGloveInterface.ice:38
armarx::CyberGloveValues::palmArch
int palmArch
Definition: CyberGloveInterface.ice:53
armarx::CyberGloveObserver::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: CyberGloveObserver.cpp:53
armarx::CyberGloveValues::thumbCMC
int thumbCMC
Definition: CyberGloveInterface.ice:34
armarx::CyberGloveValues::littlePIP
int littlePIP
Definition: CyberGloveInterface.ice:50
armarx::CyberGloveValues::littleAbd
int littleAbd
Definition: CyberGloveInterface.ice:52
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:35
armarx::CyberGloveObserverPropertyDefinitions
Definition: CyberGloveObserver.h:40
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::CyberGloveValues::middleDIP
int middleDIP
Definition: CyberGloveInterface.ice:43
armarx::CyberGloveValues::ringMCP
int ringMCP
Definition: CyberGloveInterface.ice:45
armarx::Observer::offerChannel
void offerChannel(std::string channelName, std::string description)
Offer a channel.
Definition: Observer.cpp:131