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 <vector>
29 
30 #include <VirtualRobot/EndEffector/EndEffector.h>
31 #include <VirtualRobot/VirtualRobot.h>
32 #include <VirtualRobot/VirtualRobotException.h>
33 #include <VirtualRobot/XML/RobotIO.h>
34 
36 
37 using namespace armarx;
38 using namespace VirtualRobot;
39 
40 void
42 {
43  std::string endeffectorFile = getProperty<std::string>("RobotFileName").getValue();
44  std::string endeffectorName = getProperty<std::string>("EndeffectorName").getValue();
45 
46  if (!ArmarXDataPath::getAbsolutePath(endeffectorFile, endeffectorFile))
47  {
48  throw UserException("Could not find robot file " + endeffectorFile);
49  }
50 
51 
52  try
53  {
54  robot =
55  VirtualRobot::RobotIO::loadRobot(endeffectorFile, VirtualRobot::RobotIO::eStructure);
56  }
57  catch (VirtualRobot::VirtualRobotException& e)
58  {
59  throw UserException(e.what());
60  }
61 
62  if (endeffectorName == "")
63  {
64  throw UserException("EndeffectorName not defined");
65  }
66 
67  if (!robot->hasEndEffector(endeffectorName))
68  {
69  throw UserException("Robot does not contain an endeffector with name: " + endeffectorName);
70  }
71 
72  eef = robot->getEndEffector(endeffectorName);
73  robotName = robot->getName();
74 
75  if (eef->getTcp())
76  {
77  tcpName = robot->getEndEffector(endeffectorName)->getTcp()->getName();
78  }
79  else
80  {
81  throw UserException("Endeffector without TCP: " + endeffectorName);
82  }
83 
84  // get all joints
85  std::vector<EndEffectorActorPtr> actors;
86  eef->getActors(actors);
87 
88  for (size_t i = 0; i < actors.size(); i++)
89  {
90  EndEffectorActorPtr a = actors[i];
91  std::vector<EndEffectorActor::ActorDefinition> ads; // = a->getDefinition();
92 
93  for (size_t j = 0; j < ads.size(); j++)
94  {
95  EndEffectorActor::ActorDefinition ad = ads[j];
96 
97  if (ad.robotNode)
98  {
99  handJoints[ad.robotNode->getName()] = ad.directionAndSpeed;
100  }
101  }
102  }
103 
104  const std::vector<std::string> endeffectorPreshapes =
105  robot->getEndEffector(endeffectorName)->getPreshapes();
106 
107  shapeNames = new SingleTypeVariantList(VariantType::String);
108  std::vector<std::string>::const_iterator iter = endeffectorPreshapes.begin();
109 
110  while (iter != endeffectorPreshapes.end())
111  {
112  Variant currentPreshape;
113  currentPreshape.setString(*iter);
114  shapeNames->addVariant(currentPreshape);
115  iter++;
116  }
117 
118 
119  // component dependencies
120  listenerChannelName = endeffectorName + "State";
121  offeringTopic(listenerChannelName);
122 
123  this->onInitHandUnit();
124 }
125 
126 void
128 {
129  ARMARX_INFO << "setting report topic to " << listenerChannelName << flush;
130  listenerPrx = getTopic<HandUnitListenerPrx>(listenerChannelName);
131 
132  this->onStartHandUnit();
133 }
134 
135 void
137 {
138  this->onExitHandUnit();
139 }
140 
141 void
142 HandUnit::setShape(const std::string& shapeName, const Ice::Current& c)
143 {
144 }
145 
146 void
147 HandUnit::setShapeWithObjectInstance(const std::string& shapeName,
148  const std::string& objectInstanceName,
149  const Ice::Current& c)
150 {
151  ARMARX_WARNING << "setShapeWithObjectInstance Function not implemented!";
152 }
153 
154 SingleTypeVariantListBasePtr
155 HandUnit::getShapeNames(const Ice::Current& c)
156 {
157  return shapeNames;
158 }
159 
162 {
163  return PropertyDefinitionsPtr(new HandUnitPropertyDefinitions(getConfigIdentifier()));
164 }
165 
167 HandUnit::getShapeJointValues(const std::string& shapeName, const Ice::Current&)
168 {
169  EndEffectorPtr efp =
170  robot->getEndEffector(getProperty<std::string>("EndeffectorName").getValue());
171  RobotConfigPtr rc = efp->getPreshape(shapeName);
172  return rc->getRobotNodeJointValueMap();
173 }
174 
176 HandUnit::getCurrentJointValues(const Ice::Current& c)
177 {
178  NameValueMap result;
179 
180  for (auto j : handJoints)
181  {
182  result[j.first] = 0.0f;
183  }
184 
185  return result;
186 }
187 
188 void
189 HandUnit::setObjectGrasped(const std::string& objectName, const Ice::Current&)
190 {
191  ARMARX_INFO << "Object grasped " << objectName << flush;
192  graspedObject = objectName;
193 }
194 
195 void
196 HandUnit::setObjectReleased(const std::string& objectName, const Ice::Current&)
197 {
198  ARMARX_INFO << "Object released " << objectName << flush;
199  graspedObject = "";
200 }
201 
202 std::string
203 armarx::HandUnit::getHandName(const Ice::Current&)
204 {
205  return eef->getName();
206 }
207 
208 void
209 HandUnit::setJointForces(const NameValueMap& targetJointForces, const Ice::Current&)
210 {
211 }
212 
213 void
214 HandUnit::sendJointCommands(const NameCommandMap& targetJointCommands, const Ice::Current&)
215 {
216 }
217 
218 void
220  const Ice::Current& c)
221 {
222 }
223 
224 std::string
225 HandUnit::describeHandState(const Ice::Current&)
226 {
227  return "not implemented";
228 }
229 
230 void
232 {
233  ARMARX_WARNING << "`reloadPreshapes` not implemented for this hand unit!";
234 }
235 
236 void
237 armarx::HandUnit::tare(const Ice::Current&)
238 {
239  ARMARX_WARNING << "Taring is not supported by this hand.";
240 }
241 
242 void
244 {
245  ARMARX_WARNING << "Resetting firmware is not supported by this hand.";
246 }
armarx::Variant
The Variant class is described here: Variants.
Definition: Variant.h:223
armarx::HandUnit::onConnectComponent
void onConnectComponent() override
Calls armarx::PlatformUnit::onStartPlatformUnit().
Definition: HandUnit.cpp:127
VirtualRobot
Definition: FramedPose.h:42
armarx::HandUnit::describeHandState
std::string describeHandState(const Ice::Current &) override
Definition: HandUnit.cpp:225
armarx::HandUnit::tare
void tare(const Ice::Current &) override
Definition: HandUnit.cpp:237
armarx::Variant::setString
void setString(const std::string &s, const Ice::Current &c=Ice::emptyCurrent) override
Sets the Variant's value to s.
Definition: Variant.cpp:428
armarx::HandUnit::setObjectReleased
void setObjectReleased(const std::string &objectName, const Ice::Current &) override
Definition: HandUnit.cpp:196
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:46
armarx::HandUnit::getHandName
std::string getHandName(const Ice::Current &=Ice::emptyCurrent) override
Definition: HandUnit.cpp:203
armarx::HandUnit::setObjectGrasped
void setObjectGrasped(const std::string &objectName, const Ice::Current &) override
Definition: HandUnit.cpp:189
armarx::HandUnit::onInitComponent
void onInitComponent() override
Retrieve proxy for publishing State information and call armarx::PlatformUnit::onInitPlatformUnit().
Definition: HandUnit.cpp:41
armarx::HandUnit::setJointForces
void setJointForces(const NameValueMap &targetJointForces, const Ice::Current &) override
Definition: HandUnit.cpp:209
armarx::HandUnit::getShapeNames
SingleTypeVariantListBasePtr getShapeNames(const Ice::Current &c=Ice::emptyCurrent) override
Definition: HandUnit.cpp:155
armarx::ctrlutil::a
double a(double t, double a0, double j)
Definition: CtrlUtil.h:45
armarx::HandUnit::getCurrentJointValues
NameValueMap getCurrentJointValues(const Ice::Current &c=Ice::emptyCurrent) override
Definition: HandUnit.cpp:176
HandUnit.h
armarx::HandUnit::createPropertyDefinitions
PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: HandUnit.cpp:161
armarx::HandUnit::setShape
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:142
armarx::flush
const LogSender::manipulator flush
Definition: LogSender.h:251
armarx::HandUnit::setShapeWithObjectInstance
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:147
armarx::HandUnit::getShapeJointValues
NameValueMap getShapeJointValues(const std::string &shapeName, const Ice::Current &c=Ice::emptyCurrent) override
Definition: HandUnit.cpp:167
armarx::HandUnit::reloadPreshapes
void reloadPreshapes(const Ice::Current &) override
Definition: HandUnit.cpp:231
armarx::HandUnitPropertyDefinitions
Defines all necessary properties for armarx::HandUnit.
Definition: HandUnit.h:42
armarx::control::njoint_controller::platform::platform_follower_controller::NameValueMap
std::map< std::string, float > NameValueMap
Definition: PlatformFollowerController.h:88
armarx::HandUnit::onExitComponent
void onExitComponent() override
Calls armarx::PlatformUnit::onExitPlatformUnit().
Definition: HandUnit.cpp:136
armarx::HandUnit::resetFirmware
void resetFirmware(const Ice::Current &) override
Definition: HandUnit.cpp:243
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:181
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::HandUnit::sendJointCommands
void sendJointCommands(const NameCommandMap &targetJointCommands, const Ice::Current &) override
Definition: HandUnit.cpp:214
armarx::ArmarXDataPath::getAbsolutePath
static bool getAbsolutePath(const std::string &relativeFilename, std::string &storeAbsoluteFilename, const std::vector< std::string > &additionalSearchPaths={}, bool verbose=true)
Definition: ArmarXDataPath.cpp:109
armarx::HandUnit::setJointAngles
void setJointAngles(const NameValueMap &targetJointAngles, const Ice::Current &) override
Definition: HandUnit.cpp:219
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:193
armarx::VariantType::String
const VariantTypeId String
Definition: Variant.h:921
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:35
ArmarXDataPath.h
armarx::VariantType::SingleTypeVariantList
const VariantTypeId SingleTypeVariantList
Definition: SingleTypeVariantList.h:206
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27