HandUnit.cpp
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2012-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 ArmarXCore::units
19 * @author Manfred Kroehnert (Manfred dot Kroehnert at kit dot edu)
20 * @date 2013
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24
25
26#include "HandUnit.h"
27
28#include <cstddef>
29#include <string>
30#include <vector>
31
32#include <Ice/Current.h>
33
34#include <VirtualRobot/EndEffector/EndEffector.h>
35#include <VirtualRobot/VirtualRobot.h>
36#include <VirtualRobot/VirtualRobotException.h>
37#include <VirtualRobot/XML/RobotIO.h>
38
43#include <ArmarXCore/interface/core/UserException.h>
44#include <ArmarXCore/interface/observers/VariantContainers.h>
47
48#include <RobotAPI/interface/core/NameValueMap.h>
49#include <RobotAPI/interface/units/HandUnitInterface.h>
50
51using namespace armarx;
52using namespace VirtualRobot;
53
54void
56{
57 std::string endeffectorFile = getProperty<std::string>("RobotFileName").getValue();
58 std::string endeffectorName = getProperty<std::string>("EndeffectorName").getValue();
59
60 if (!ArmarXDataPath::getAbsolutePath(endeffectorFile, endeffectorFile))
61 {
62 throw UserException("Could not find robot file " + endeffectorFile);
63 }
64
65 try
66 {
67 robot =
68 VirtualRobot::RobotIO::loadRobot(endeffectorFile, VirtualRobot::RobotIO::eStructure);
69 }
70 catch (VirtualRobot::VirtualRobotException& e)
71 {
72 throw UserException(e.what());
73 }
74
75 if (endeffectorName == "")
76 {
77 throw UserException("EndeffectorName not defined");
78 }
79
80 if (!robot->hasEndEffector(endeffectorName))
81 {
82 throw UserException("Robot does not contain an endeffector with name: " + endeffectorName);
83 }
84
85 eef = robot->getEndEffector(endeffectorName);
86 robotName = robot->getName();
87
88 if (eef->getTcp())
89 {
90 tcpName = robot->getEndEffector(endeffectorName)->getTcp()->getName();
91 }
92 else
93 {
94 throw UserException("Endeffector without TCP: " + endeffectorName);
95 }
96
97 // get all joints
98 std::vector<EndEffectorActorPtr> actors;
99 eef->getActors(actors);
100
101 for (size_t i = 0; i < actors.size(); i++)
102 {
103 EndEffectorActorPtr a = actors[i];
104 std::vector<EndEffectorActor::ActorDefinition> ads; // = a->getDefinition();
105
106 for (size_t j = 0; j < ads.size(); j++)
107 {
108 EndEffectorActor::ActorDefinition ad = ads[j];
109
110 if (ad.robotNode)
111 {
112 handJoints[ad.robotNode->getName()] = ad.directionAndSpeed;
113 }
114 }
115 }
116
117 const std::vector<std::string> endeffectorPreshapes =
118 robot->getEndEffector(endeffectorName)->getPreshapes();
119
121 std::vector<std::string>::const_iterator iter = endeffectorPreshapes.begin();
122
123 while (iter != endeffectorPreshapes.end())
124 {
125 Variant currentPreshape;
126 currentPreshape.setString(*iter);
127 shapeNames->addVariant(currentPreshape);
128 iter++;
129 }
130
131 // component dependencies
132 listenerChannelName = endeffectorName + "State";
134
135 this->onInitHandUnit();
136}
137
138void
146
147void
152
153void
154HandUnit::setShape(const std::string& shapeName, const Ice::Current& c)
155{
156}
157
158void
159HandUnit::setShapeWithObjectInstance(const std::string& shapeName,
160 const std::string& objectInstanceName,
161 const Ice::Current& c)
162{
163 ARMARX_WARNING << "setShapeWithObjectInstance Function not implemented!";
164}
165
166SingleTypeVariantListBasePtr
167HandUnit::getShapeNames(const Ice::Current& c)
168{
169 return shapeNames;
170}
171
177
178NameValueMap
179HandUnit::getShapeJointValues(const std::string& shapeName, const Ice::Current&)
180{
181 EndEffectorPtr efp =
182 robot->getEndEffector(getProperty<std::string>("EndeffectorName").getValue());
183 RobotConfigPtr rc = efp->getPreshape(shapeName);
184 return rc->getRobotNodeJointValueMap();
185}
186
187NameValueMap
189{
190 NameValueMap result;
191
192 for (auto j : handJoints)
193 {
194 result[j.first] = 0.0f;
195 }
196
197 return result;
198}
199
200void
201HandUnit::setObjectGrasped(const std::string& objectName, const Ice::Current&)
202{
203 ARMARX_INFO << "Object grasped " << objectName << flush;
204 graspedObject = objectName;
205}
206
207void
208HandUnit::setObjectReleased(const std::string& objectName, const Ice::Current&)
209{
210 ARMARX_INFO << "Object released " << objectName << flush;
211 graspedObject = "";
212}
213
214std::string
216{
217 return eef->getName();
218}
219
220void
221HandUnit::setJointForces(const NameValueMap& targetJointForces, const Ice::Current&)
222{
223}
224
225void
226HandUnit::sendJointCommands(const NameCommandMap& targetJointCommands, const Ice::Current&)
227{
228}
229
230void
231armarx::HandUnit::setJointAngles(const armarx::NameValueMap& targetJointAngles,
232 const Ice::Current& c)
233{
234}
235
236std::string
237HandUnit::describeHandState(const Ice::Current&)
238{
239 return "not implemented";
240}
241
242void
244{
245 ARMARX_WARNING << "`reloadPreshapes` not implemented for this hand unit!";
246}
247
248void
249armarx::HandUnit::startTare(const Ice::Current&)
250{
251 ARMARX_WARNING << "Taring is not supported by this hand.";
252}
253
254void
255armarx::HandUnit::tare(const Ice::Current&)
256{
257 ARMARX_WARNING << "Taring is not supported by this hand.";
258}
259
260void
262{
263 ARMARX_WARNING << "Resetting firmware is not supported by this hand.";
264}
constexpr T c
static bool getAbsolutePath(const std::string &relativeFilename, std::string &storeAbsoluteFilename, const std::vector< std::string > &additionalSearchPaths={}, bool verbose=true)
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition Component.cpp:90
Property< PropertyType > getProperty(const std::string &name)
Defines all necessary properties for armarx::HandUnit.
Definition HandUnit.h:43
virtual void onExitHandUnit()=0
void onInitComponent() override
Retrieve proxy for publishing State information and call armarx::PlatformUnit::onInitPlatformUnit().
Definition HandUnit.cpp:55
std::string getHandName(const Ice::Current &=Ice::emptyCurrent) override
Definition HandUnit.cpp:215
HandUnitListenerPrx listenerPrx
HandUnitListener proxy for publishing state updates.
Definition HandUnit.h:161
SingleTypeVariantListPtr shapeNames
List containing the names of all valid shapes.
Definition HandUnit.h:169
std::string describeHandState(const Ice::Current &) override
Definition HandUnit.cpp:237
VirtualRobot::RobotPtr robot
Definition HandUnit.h:173
VirtualRobot::EndEffectorPtr eef
Definition HandUnit.h:174
void setShape(const std::string &shapeName, const Ice::Current &c=Ice::emptyCurrent) override
Send command to the hand to form a specific shape position.
Definition HandUnit.cpp:154
void setObjectReleased(const std::string &objectName, const Ice::Current &) override
Definition HandUnit.cpp:208
void setJointForces(const NameValueMap &targetJointForces, const Ice::Current &) override
Definition HandUnit.cpp:221
virtual void onInitHandUnit()=0
void sendJointCommands(const NameCommandMap &targetJointCommands, const Ice::Current &) override
Definition HandUnit.cpp:226
std::map< std::string, float > handJoints
Definition HandUnit.h:179
SingleTypeVariantListBasePtr getShapeNames(const Ice::Current &c=Ice::emptyCurrent) override
Definition HandUnit.cpp:167
std::string graspedObject
Definition HandUnit.h:181
std::string tcpName
Definition HandUnit.h:177
void setObjectGrasped(const std::string &objectName, const Ice::Current &) override
Definition HandUnit.cpp:201
void onConnectComponent() override
Calls armarx::PlatformUnit::onStartPlatformUnit().
Definition HandUnit.cpp:139
void setJointAngles(const NameValueMap &targetJointAngles, const Ice::Current &) override
Definition HandUnit.cpp:231
NameValueMap getCurrentJointValues(const Ice::Current &c=Ice::emptyCurrent) override
Definition HandUnit.cpp:188
void tare(const Ice::Current &) override
Definition HandUnit.cpp:255
PropertyDefinitionsPtr createPropertyDefinitions() override
Definition HandUnit.cpp:173
void reloadPreshapes(const Ice::Current &) override
Definition HandUnit.cpp:243
std::string listenerChannelName
Ice Topic name on which armarx::HandUnit::listenerPrx publishes information.
Definition HandUnit.h:165
void startTare(const Ice::Current &) override
Definition HandUnit.cpp:249
void onExitComponent() override
Calls armarx::PlatformUnit::onExitPlatformUnit().
Definition HandUnit.cpp:148
void rebootEmbeddedSystem(const Ice::Current &) override
Definition HandUnit.cpp:261
std::string robotName
Definition HandUnit.h:176
void setShapeWithObjectInstance(const std::string &shapeName, const std::string &objectInstanceName, const Ice::Current &c=Ice::emptyCurrent) override
setShapeWithObjectInstance Send command to the hand to form a specific shape position.
Definition HandUnit.cpp:159
virtual void onStartHandUnit()=0
NameValueMap getShapeJointValues(const std::string &shapeName, const Ice::Current &c=Ice::emptyCurrent) override
Definition HandUnit.cpp:179
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.
The SingleTypeVariantList class is a subclass of VariantContainer and is comparable to a std::vector<...
The Variant class is described here: Variants.
Definition Variant.h:224
void setString(const std::string &s, const Ice::Current &c=Ice::emptyCurrent) override
Sets the Variant's value to s.
Definition Variant.cpp:428
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:193
const VariantTypeId String
Definition Variant.h:921
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
const LogSender::manipulator flush
Definition LogSender.h:251