HandUnitSimulation.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2013-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 Peter Kaiser (peter dot kaiser at kit dot edu)
20  * @date 2017
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 
25 
26 #include "HandUnitSimulation.h"
27 
28 #include <Eigen/Geometry>
29 
30 #include <cmath>
31 
32 #include <VirtualRobot/EndEffector/EndEffector.h>
33 #include <VirtualRobot/RobotConfig.h>
34 
35 namespace armarx
36 {
38  {
39  kinematicUnitName = getProperty<std::string>("KinematicUnitName").getValue();
41  }
42 
44  {
45  kinematicUnitPrx = getProxy<KinematicUnitInterfacePrx>(kinematicUnitName);
46  if (!kinematicUnitPrx)
47  {
48  ARMARX_ERROR << "Failed to obtain kinematic unit proxy";
49  }
50  }
51 
53  {
54  }
55 
57  {
59  }
60 
61  void armarx::HandUnitSimulation::setShape(const std::string& shapeName, const Ice::Current&)
62  {
63  std::string myShapeName = shapeName;
64  ARMARX_INFO << "Setting shape " << myShapeName;
65 
66  if (!eef)
67  {
68  ARMARX_WARNING << "No EEF";
69  return;
70  }
71 
72 
73  if (!eef->hasPreshape(myShapeName))
74  {
75  ARMARX_INFO << "Shape with name " << myShapeName << " not known in eef " << eef->getName() << ". Looking for partial match";
76 
77  bool foundMatch = false;
78 
79  for (std::string name : eef->getPreshapes())
80  {
81  if (name.find(myShapeName) != std::string::npos)
82  {
83  foundMatch = true;
84  myShapeName = name;
85  ARMARX_INFO << "Using matching shape: " << name;
86  break;
87  }
88  }
89 
90  if (!foundMatch)
91  {
92  ARMARX_WARNING << "No match found for " << myShapeName << " in eef " << eef->getName() << " available shapes: " << eef->getPreshapes();
93  return;
94  }
95  }
96 
97  VirtualRobot::RobotConfigPtr config = eef->getPreshape(myShapeName);
98  std::map < std::string, float > jointAngles = config->getRobotNodeJointValueMap();
99 
100  NameControlModeMap controlModes;
101 
102  for (std::pair<std::string, float> pair : jointAngles)
103  {
104  controlModes.insert(std::make_pair(pair.first, ePositionControl));
105  }
106 
107  kinematicUnitPrx->switchControlMode(controlModes);
108  kinematicUnitPrx->setJointAngles(jointAngles);
109  }
110 
112  {
113  NameControlModeMap controlModes;
114 
115  for (std::pair<std::string, float> pair : jointAngles)
116  {
117  controlModes.insert(std::make_pair(pair.first, ePositionControl));
118  }
119 
120  kinematicUnitPrx->switchControlMode(controlModes);
121  kinematicUnitPrx->setJointAngles(jointAngles);
122  }
123 }
armarx::HandUnitSimulation::onInitHandUnit
void onInitHandUnit() override
Definition: HandUnitSimulation.cpp:37
armarx::HandUnitSimulation::kinematicUnitPrx
KinematicUnitInterfacePrx kinematicUnitPrx
Definition: HandUnitSimulation.h:88
ARMARX_ERROR
#define ARMARX_ERROR
Definition: Logging.h:189
armarx::HandUnitSimulation::onStartHandUnit
void onStartHandUnit() override
Definition: HandUnitSimulation.cpp:43
armarx::HandUnitSimulationPropertyDefinitions
Defines all necessary properties for armarx::HandUnitSimulation.
Definition: HandUnitSimulation.h:36
armarx::control::njoint_controller::platform::platform_follower_controller::NameValueMap
std::map< std::string, float > NameValueMap
Definition: PlatformFollowerController.h:91
armarx::channels::KinematicUnitObserver::jointAngles
const KinematicUnitDatafieldCreator jointAngles("jointAngles")
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:74
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::HandUnitSimulation::createPropertyDefinitions
PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: HandUnitSimulation.cpp:56
armarx::HandUnit::kinematicUnitName
std::string kinematicUnitName
Definition: HandUnit.h:160
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186
HandUnitSimulation.h
armarx::HandUnitSimulation::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: HandUnitSimulation.cpp:61
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:34
armarx::ManagedIceObject::usingProxy
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
Definition: ManagedIceObject.cpp:151
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::HandUnitSimulation::setJointAngles
void setJointAngles(const NameValueMap &jointAngles, const Ice::Current &c=Ice::emptyCurrent) override
Definition: HandUnitSimulation.cpp:111
armarx::HandUnitSimulation::onExitHandUnit
void onExitHandUnit() override
Definition: HandUnitSimulation.cpp:52