InstallTerminateConditions.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 
26 
28 
29 using namespace armarx;
30 using namespace FindAndGraspObjectGroup;
31 
32 // DO NOT EDIT NEXT LINE
34 
35 
36 
39 {
40 }
41 
43 {
44  ARMARX_VERBOSE << "Entering InstallTerminateConditions::onEnter()";
45 
46  ARMARX_DEBUG << "Installing timeoutGrasp condition";
47  float timeoutGrasp = getInput<float>("timeoutGrasp");
48  condGraspTimeout = setTimeoutEvent(timeoutGrasp, createEvent<EvMinExecutionTimeout>());
49 
50  float thresholdVelocity = getInput<float>("thresholdVelocity");
51  ARMARX_DEBUG << "Installing allJointVelocitiesLow condition, threshold: " << thresholdVelocity << flush;
52 
53  //=======
54  //first try ... (with ChannelRef)
55  //=======
56 
57  /*
58  Term allJointVelocitiesLow;
59  SingleTypeVariantListPtr jointNamesList = getInput<SingleTypeVariantList>("jointNames");
60  for (int i=0; i<jointNamesList->getSize(); i++)
61  {
62  allJointVelocitiesLow = allJointVelocitiesLow && Literal(getInput<ChannelRef>("jointVelocityChannel")
63  ->getDataFieldIdentifier(jointNamesList->getVariant(i)->getString()), "smaller", Literal::createParameterList(thresholdVelocity));
64  }
65  condAllJointVelocitiesLow = installCondition(allJointVelocitiesLow, createEvent<EvAllJointVelocitiesLow>());
66  */
67 
68  //=======
69  //second try ... (with DatafieldRef)
70  //=======
71  Term allJointVelocitiesLow_NEW;
72  //SingleTypeVariantListPtr jointNamesList = getInput<SingleTypeVariantList>("jointNames");
73  SingleTypeVariantListPtr dataFieldsList = getInput<SingleTypeVariantList>("jointVelocitiesDatafields");
74 
75  //for (int i=0; i<jointNamesList->getSize(); i++)
76  for (int i = 0; i < dataFieldsList->getSize(); i++)
77  {
78  allJointVelocitiesLow_NEW = allJointVelocitiesLow_NEW &&
79  Literal(dataFieldsList->getVariant(i)->get<DatafieldRef>()->getDataFieldIdentifier(),
80  "inrange", Literal::createParameterList(-thresholdVelocity, thresholdVelocity));
81  }
82 
83  condAllJointVelocitiesLow = installCondition(allJointVelocitiesLow_NEW, createEvent<EvAllJointVelocitiesLow>());
84 
85  ARMARX_VERBOSE << "Done InstallTerminateConditions::onEnter()";
86 }
87 
89 {
90  ARMARX_VERBOSE << "Entering InstallTerminateConditions::onExit()";
93 
94  //---------
95  //set joint velocities manually to zero (DEBUG)
96  //---------
97 
98  std::string handUnitName = getInput<std::string>("handUnitName");
99  ARMARX_DEBUG << "xx..................SENDING OBJECTGRASPED TO hand unit name " << handUnitName << "...................";
100 
101  RobotStatechartContext* rsContext = getContext<RobotStatechartContext>();
102 
103  if (rsContext->getHandUnit(handUnitName))
104  {
105  ARMARX_DEBUG << "xx..................SENDING OBJECTGRASPED TO hand unit name " << handUnitName << ".......OK: sending Vitalis............";
106  rsContext->getHandUnit(handUnitName)->setObjectGrasped("Vitalis");
107  }
108 
109  SingleTypeVariantListPtr jointNames = getInput<SingleTypeVariantList>("jointNames");
110  //SingleTypeVariantListPtr jointTorquesGraspList = getInput<SingleTypeVariantList>("jointTorquesGrasp");
111  NameValueMap jointNamesAndValues;
112  NameControlModeMap controlModes;
113 
114  for (int j = 0; j < jointNames->getSize(); j++)
115  {
116  // no, now we set it to zero.... we want to ensure that the object stayes grasped -> apply a small velocity (todo: find a better solution!)
117  jointNamesAndValues[jointNames->getVariant(j)->getString()] = 0.0;//1f; //set everything to zero
118  controlModes[jointNames->getVariant(j)->getString()] = eVelocityControl;
119  }
120 
121  rsContext->kinematicUnitPrx->switchControlMode(controlModes);
122  // rsContext->kinematicUnitPrx->setJointTorques(jointNamesAndValues);
123  rsContext->kinematicUnitPrx->setJointVelocities(jointNamesAndValues);
124  ARMARX_VERBOSE << "Done InstallTerminateConditions::onExit()";
125 }
126 
127 // DO NOT EDIT NEXT FUNCTION
129 {
130  return "InstallTerminateConditions";
131 }
132 
133 // DO NOT EDIT NEXT FUNCTION
135 {
136  return XMLStateFactoryBasePtr(new InstallTerminateConditions(stateData));
137 }
138 
armarx::RobotStatechartContext::getHandUnit
HandUnitInterfacePrx getHandUnit(const std::string &handUnitName)
Definition: RobotStatechartContext.cpp:118
armarx::StateUtility::removeCondition
void removeCondition(ConditionIdentifier conditionId)
Utility function to remove an installed condition on the distributed conditionhandler.
Definition: StateUtil.cpp:131
ARMARX_VERBOSE
#define ARMARX_VERBOSE
Definition: Logging.h:180
armarx::FindAndGraspObjectGroup::InstallTerminateConditions::Registry
static SubClassRegistry Registry
Definition: InstallTerminateConditions.h:50
armarx::XMLStateConstructorParams
Definition: XMLState.h:50
armarx::Literal::createParameterList
static VarList createParameterList()
Static helper method to create an empty parameterlist.
Definition: Term.cpp:129
armarx::FindAndGraspObjectGroup::InstallTerminateConditions::condGraspTimeout
ActionEventIdentifier condGraspTimeout
Definition: InstallTerminateConditions.h:56
armarx::FindAndGraspObjectGroup::InstallTerminateConditions::GetName
static std::string GetName()
Definition: InstallTerminateConditions.cpp:128
armarx::FindAndGraspObjectGroup::InstallTerminateConditions::condAllJointVelocitiesLow
ConditionIdentifier condAllJointVelocitiesLow
Definition: InstallTerminateConditions.h:55
armarx::navigation::platform_controller::platform_global_trajectory::NameValueMap
std::map< std::string, float > NameValueMap
Definition: PlatformGlobalTrajectoryController.h:93
armarx::Term
Definition: Term.h:111
armarx::FindAndGraspObjectGroup::InstallTerminateConditions::CreateInstance
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
Definition: InstallTerminateConditions.cpp:134
armarx::FindAndGraspObjectGroup::InstallTerminateConditions
Definition: InstallTerminateConditions.h:36
armarx::FindAndGraspObjectGroup::InstallTerminateConditions::onEnter
void onEnter() override
Virtual function, in which the behaviour of state is defined, when it is entered. Can be overridden,...
Definition: InstallTerminateConditions.cpp:42
IceInternal::Handle< SingleTypeVariantList >
DatafieldRef.h
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::DatafieldRef::getDataFieldIdentifier
DataFieldIdentifierPtr getDataFieldIdentifier() const
Definition: DatafieldRef.cpp:100
armarx::flush
const LogSender::manipulator flush
Definition: LogSender.h:251
ARMARX_DEBUG
#define ARMARX_DEBUG
Definition: Logging.h:177
armarx::StateUtility::installCondition
ConditionIdentifier installCondition(const Term &condition, const EventPtr evt, const std::string &desc="")
Utility function to install a condition on the distributed conditionhandler.
Definition: StateUtil.cpp:97
armarx::FindAndGraspObjectGroup::InstallTerminateConditions::InstallTerminateConditions
InstallTerminateConditions(XMLStateConstructorParams stateData)
Definition: InstallTerminateConditions.cpp:37
armarx::DatafieldRef
The DatafieldRef class is similar to the ChannelRef, but points to a specific Datafield instead of to...
Definition: DatafieldRef.h:51
armarx::XMLStateFactoryBasePtr
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition: XMLState.h:65
armarx::Literal
Definition: Term.h:208
InstallTerminateConditions.h
armarx::FindAndGraspObjectGroup::InstallTerminateConditions::onExit
void onExit() override
Virtual function, in which the behaviour of state is defined, when it is exited. Can be overridden,...
Definition: InstallTerminateConditions.cpp:88
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