Preshape.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2014-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 RobotSkillTemplates::FindAndGraspObjectGroup
19  * @author Valerij Wittenbeck ( valerij dot wittenbeck at student dot kit dot edu )
20  * @date 2014
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 
25 #include "Preshape.h"
26 
27 using namespace armarx;
28 using namespace FindAndGraspObjectGroup;
29 
30 // DO NOT EDIT NEXT LINE
31 Preshape::SubClassRegistry Preshape::Registry(Preshape::GetName(), &Preshape::CreateInstance);
32 
33 
34 
36  XMLStateTemplate < Preshape > (stateData)
37 {
38 }
39 
41 {
42  ARMARX_VERBOSE << "Entering Preshape::onEnter()";
43 
44  RobotStatechartContext* rsContext = getContext<RobotStatechartContext>();
45  SingleTypeVariantListPtr jointNames = getInput<SingleTypeVariantList>("jointNames");
46  SingleTypeVariantListPtr jointAnglesPreshapeList = getInput<SingleTypeVariantList>("jointAnglesPreshape");
47  NameValueMap jointNamesAndValues;
48 
49  if (jointNames->getSize() == jointAnglesPreshapeList->getSize())
50  {
51  for (int j = 0; j < jointNames->getSize(); j++)
52  {
53  jointNamesAndValues[jointNames->getVariant(j)->getString()] = jointAnglesPreshapeList->getVariant(j)->getFloat();
54  }
55  }
56  else
57  {
58  throw LocalException("Preshape: List lengths do not match!");
59  }
60 
61  rsContext->kinematicUnitPrx->setJointAngles(jointNamesAndValues);
62 
63  ARMARX_DEBUG << "Installing preshape timeout condition";
64  float timeoutPreshape = getInput<float>("timeoutPreshape");
65 
66  bool useTorquesForGrasping = getInput<bool>("useTorquesForGrasping");
67 
68  if (useTorquesForGrasping)
69  {
70  condPreshapeTimeout = setTimeoutEvent(timeoutPreshape, createEvent<EvPreshapeTimeout_ToCloseWithTorques>());
71  }
72  else
73  {
74  condPreshapeTimeout = setTimeoutEvent(timeoutPreshape, createEvent<EvPreshapeTimeout_ToCloseWithJointAngles>());
75  }
76 
77  ARMARX_VERBOSE << "Done Preshape::onEnter()";
78 }
79 
81 {
83  ARMARX_VERBOSE << "Done Preshape::onExit()";
84 }
85 
86 // DO NOT EDIT NEXT FUNCTION
87 std::string Preshape::GetName()
88 {
89  return "Preshape";
90 }
91 
92 // DO NOT EDIT NEXT FUNCTION
94 {
95  return XMLStateFactoryBasePtr(new Preshape(stateData));
96 }
97 
ARMARX_VERBOSE
#define ARMARX_VERBOSE
Definition: Logging.h:180
armarx::FindAndGraspObjectGroup::Preshape::Preshape
Preshape(XMLStateConstructorParams stateData)
Definition: Preshape.cpp:35
armarx::FindAndGraspObjectGroup::Preshape::onEnter
void onEnter() override
Virtual function, in which the behaviour of state is defined, when it is entered. Can be overridden,...
Definition: Preshape.cpp:40
armarx::FindAndGraspObjectGroup::Preshape::Registry
static SubClassRegistry Registry
Definition: Preshape.h:49
armarx::FindAndGraspObjectGroup::Preshape::condPreshapeTimeout
ActionEventIdentifier condPreshapeTimeout
Definition: Preshape.h:54
armarx::XMLStateConstructorParams
Definition: XMLState.h:50
armarx::navigation::platform_controller::platform_global_trajectory::NameValueMap
std::map< std::string, float > NameValueMap
Definition: PlatformGlobalTrajectoryController.h:93
armarx::FindAndGraspObjectGroup::Preshape
Definition: Preshape.h:35
IceInternal::Handle< SingleTypeVariantList >
armarx::RobotStatechartContext
Definition: RobotStatechartContext.h:66
armarx::StateUtility::setTimeoutEvent
ActionEventIdentifier setTimeoutEvent(int timeoutDurationMs, const EventPtr &evt)
Utility function to start a timer on the systemObserver and register an event on the conditionHandler...
Definition: StateUtil.cpp:144
armarx::XMLStateTemplate
Class for legacy to stay compatible with old statecharts.
Definition: XMLState.h:137
ARMARX_DEBUG
#define ARMARX_DEBUG
Definition: Logging.h:177
armarx::FindAndGraspObjectGroup::Preshape::CreateInstance
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
Definition: Preshape.cpp:93
Preshape.h
armarx::FindAndGraspObjectGroup::Preshape::onExit
void onExit() override
Virtual function, in which the behaviour of state is defined, when it is exited. Can be overridden,...
Definition: Preshape.cpp:80
armarx::XMLStateFactoryBasePtr
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition: XMLState.h:65
armarx::FindAndGraspObjectGroup::Preshape::GetName
static std::string GetName()
Definition: Preshape.cpp:87
armarx::StateUtility::removeTimeoutEvent
void removeTimeoutEvent(const ActionEventIdentifier &id)
Definition: StateUtil.cpp:178
armarx::RobotStatechartContext::kinematicUnitPrx
KinematicUnitInterfacePrx kinematicUnitPrx
Definition: RobotStatechartContext.h:97
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28