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 <cmath>
29 
30 #include <Eigen/Geometry>
31 
32 #include <VirtualRobot/EndEffector/EndEffector.h>
33 #include <VirtualRobot/RobotConfig.h>
34 
35 namespace armarx
36 {
37  void
39  {
40  kinematicUnitName = getProperty<std::string>("KinematicUnitName").getValue();
42  }
43 
44  void
46  {
47  kinematicUnitPrx = getProxy<KinematicUnitInterfacePrx>(kinematicUnitName);
48  if (!kinematicUnitPrx)
49  {
50  ARMARX_ERROR << "Failed to obtain kinematic unit proxy";
51  }
52  }
53 
54  void
56  {
57  }
58 
61  {
64  }
65 
66  void
67  armarx::HandUnitSimulation::setShape(const std::string& shapeName, const Ice::Current&)
68  {
69  std::string myShapeName = shapeName;
70  ARMARX_INFO << "Setting shape " << myShapeName;
71 
72  if (!eef)
73  {
74  ARMARX_WARNING << "No EEF";
75  return;
76  }
77 
78 
79  if (!eef->hasPreshape(myShapeName))
80  {
81  ARMARX_INFO << "Shape with name " << myShapeName << " not known in eef "
82  << eef->getName() << ". Looking for partial match";
83 
84  bool foundMatch = false;
85 
86  for (std::string name : eef->getPreshapes())
87  {
88  if (name.find(myShapeName) != std::string::npos)
89  {
90  foundMatch = true;
91  myShapeName = name;
92  ARMARX_INFO << "Using matching shape: " << name;
93  break;
94  }
95  }
96 
97  if (!foundMatch)
98  {
99  ARMARX_WARNING << "No match found for " << myShapeName << " in eef "
100  << eef->getName() << " available shapes: " << eef->getPreshapes();
101  return;
102  }
103  }
104 
105  VirtualRobot::RobotConfigPtr config = eef->getPreshape(myShapeName);
106  std::map<std::string, float> jointAngles = config->getRobotNodeJointValueMap();
107 
108  NameControlModeMap controlModes;
109 
110  for (std::pair<std::string, float> pair : jointAngles)
111  {
112  controlModes.insert(std::make_pair(pair.first, ePositionControl));
113  }
114 
115  kinematicUnitPrx->switchControlMode(controlModes);
116  kinematicUnitPrx->setJointAngles(jointAngles);
117  }
118 
119  void
121  {
122  NameControlModeMap controlModes;
123 
124  for (std::pair<std::string, float> pair : jointAngles)
125  {
126  controlModes.insert(std::make_pair(pair.first, ePositionControl));
127  }
128 
129  kinematicUnitPrx->switchControlMode(controlModes);
130  kinematicUnitPrx->setJointAngles(jointAngles);
131  }
132 } // namespace armarx
armarx::HandUnitSimulation::onInitHandUnit
void onInitHandUnit() override
Definition: HandUnitSimulation.cpp:38
armarx::HandUnitSimulation::kinematicUnitPrx
KinematicUnitInterfacePrx kinematicUnitPrx
Definition: HandUnitSimulation.h:89
ARMARX_ERROR
#define ARMARX_ERROR
Definition: Logging.h:196
armarx::HandUnitSimulation::onStartHandUnit
void onStartHandUnit() override
Definition: HandUnitSimulation.cpp:45
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:88
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:79
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:181
IceUtil::Handle
Definition: forward_declarations.h:30
armarx::HandUnitSimulation::createPropertyDefinitions
PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: HandUnitSimulation.cpp:60
armarx::HandUnit::kinematicUnitName
std::string kinematicUnitName
Definition: HandUnit.h:169
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:193
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:67
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:35
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:154
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::HandUnitSimulation::setJointAngles
void setJointAngles(const NameValueMap &jointAngles, const Ice::Current &c=Ice::emptyCurrent) override
Definition: HandUnitSimulation.cpp:120
armarx::HandUnitSimulation::onExitHandUnit
void onExitHandUnit() override
Definition: HandUnitSimulation.cpp:55