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"
25 
26 namespace armarx
27 {
29  {
30  usingTopic(getProperty<std::string>("CyberGloveTopicName").getValue());
31  }
32 
33 
35  {
36  lastUpdate = TimeUtil::GetTime();
37  }
38 
39 
40  //void CyberGloveObserver::onDisconnectComponent()
41  //{
42 
43  //}
44 
45 
47  {
48 
49  }
50 
52  {
55  }
56 
57  void CyberGloveObserver::reportGloveValues(const CyberGloveValues& gloveValues, const Ice::Current&)
58  {
59  std::unique_lock lock(dataMutex);
60 
62 
63  long deltaUS = (now - lastUpdate).toMicroSeconds();
64 
65  ARMARX_IMPORTANT << deltaUS << " " << gloveValues.time << " " << gloveValues.indexDIP;
66  lastUpdate = now;
67 
68  latestValues = gloveValues;
69 
70 
71  std::string name = gloveValues.name;
72  if (!existsChannel(name))
73  {
74  offerChannel(name, "CyberGlove motor data");
75  }
76 
77  offerOrUpdateDataField(name, "name", Variant(name), "Name of the prostesis");
78 
79  offerOrUpdateDataField(name, "thumbCMC", Variant(gloveValues.thumbCMC), "Value of thumbCMC");
80  offerOrUpdateDataField(name, "thumbMCP", Variant(gloveValues.thumbMCP), "Value of thumbMCP");
81  offerOrUpdateDataField(name, "thumbIP", Variant(gloveValues.thumbIP), "Value of thumbIP");
82  offerOrUpdateDataField(name, "thumbAbd", Variant(gloveValues.thumbAbd), "Value of thumbAbd");
83  offerOrUpdateDataField(name, "indexMCP", Variant(gloveValues.indexMCP), "Value of indexMCP");
84  offerOrUpdateDataField(name, "indexPIP", Variant(gloveValues.indexPIP), "Value of indexPIP");
85  offerOrUpdateDataField(name, "indexDIP", Variant(gloveValues.indexDIP), "Value of indexDIP");
86  offerOrUpdateDataField(name, "middleMCP", Variant(gloveValues.middleMCP), "Value of middleMCP");
87  offerOrUpdateDataField(name, "middlePIP", Variant(gloveValues.middlePIP), "Value of middlePIP");
88  offerOrUpdateDataField(name, "middleDIP", Variant(gloveValues.middleDIP), "Value of middleDIP");
89  offerOrUpdateDataField(name, "middleAbd", Variant(gloveValues.middleAbd), "Value of middleAbd");
90  offerOrUpdateDataField(name, "ringMCP", Variant(gloveValues.ringMCP), "Value of ringMCP");
91  offerOrUpdateDataField(name, "ringPIP", Variant(gloveValues.ringPIP), "Value of ringPIP");
92  offerOrUpdateDataField(name, "ringDIP", Variant(gloveValues.ringDIP), "Value of ringDIP");
93  offerOrUpdateDataField(name, "ringAbd", Variant(gloveValues.ringAbd), "Value of ringAbd");
94  offerOrUpdateDataField(name, "littleMCP", Variant(gloveValues.littleMCP), "Value of littleMCP");
95  offerOrUpdateDataField(name, "littlePIP", Variant(gloveValues.littlePIP), "Value of littlePIP");
96  offerOrUpdateDataField(name, "littleDIP", Variant(gloveValues.littleDIP), "Value of littleDIP");
97  offerOrUpdateDataField(name, "littleAbd", Variant(gloveValues.littleAbd), "Value of littleAbd");
98  offerOrUpdateDataField(name, "palmArch", Variant(gloveValues.palmArch), "Value of palmArch");
99  offerOrUpdateDataField(name, "wristFlex", Variant(gloveValues.wristFlex), "Value of wristFlex");
100  offerOrUpdateDataField(name, "wristAbd", Variant(gloveValues.wristAbd), "Value of wristAbd");
101 
102 
103  updateChannel(name);
104  }
105 
106 
107 
109  {
110  std::unique_lock lock(dataMutex);
111  return latestValues;
112  }
113 }
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:715
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:224
armarx::CyberGloveValues::wristFlex
int wristFlex
Definition: CyberGloveInterface.ice:54
ARMARX_IMPORTANT
#define ARMARX_IMPORTANT
Definition: Logging.h:183
armarx::CyberGloveValues::wristAbd
int wristAbd
Definition: CyberGloveInterface.ice:55
armarx::CyberGloveObserver::getLatestValues
CyberGloveValues getLatestValues(const Ice::Current &) override
Definition: CyberGloveObserver.cpp:108
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:222
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:1433
armarx::CyberGloveValues::indexDIP
int indexDIP
Definition: CyberGloveInterface.ice:40
armarx::CyberGloveObserver::onExitObserver
void onExitObserver() override
Definition: CyberGloveObserver.cpp:46
armarx::CyberGloveObserver::reportGloveValues
void reportGloveValues(const CyberGloveValues &gloveValues, const Ice::Current &) override
Definition: CyberGloveObserver.cpp:57
armarx::CyberGloveObserver::onInitObserver
void onInitObserver() override
Definition: CyberGloveObserver.cpp:28
armarx::CyberGloveObserver::onConnectObserver
void onConnectObserver() override
Definition: CyberGloveObserver.cpp:34
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:248
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:74
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< class PropertyDefinitionContainer >
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:51
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:34
armarx::CyberGloveObserverPropertyDefinitions
Definition: CyberGloveObserver.h:39
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
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:126