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
35namespace armarx
36{
37 void
43
44 void
46 {
49 {
50 ARMARX_ERROR << "Failed to obtain kinematic unit proxy";
51 }
52 }
53
54 void
58
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
120 armarx::HandUnitSimulation::setJointAngles(const NameValueMap& jointAngles, const Ice::Current&)
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
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::HandUnitSimulation.
void setJointAngles(const NameValueMap &jointAngles, const Ice::Current &c=Ice::emptyCurrent) override
void setShape(const std::string &shapeName, const Ice::Current &c=Ice::emptyCurrent) override
Send command to the hand to form a specific shape position.
KinematicUnitInterfacePrx kinematicUnitPrx
PropertyDefinitionsPtr createPropertyDefinitions() override
VirtualRobot::EndEffectorPtr eef
Definition HandUnit.h:174
std::string kinematicUnitName
Definition HandUnit.h:171
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
Definition Logging.h:196
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:193
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.