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
33 InstallTerminateConditions::SubClassRegistry
36 
39 {
40 }
41 
42 void
44 {
45  ARMARX_VERBOSE << "Entering InstallTerminateConditions::onEnter()";
46 
47  ARMARX_DEBUG << "Installing timeoutGrasp condition";
48  float timeoutGrasp = getInput<float>("timeoutGrasp");
49  condGraspTimeout = setTimeoutEvent(timeoutGrasp, createEvent<EvMinExecutionTimeout>());
50 
51  float thresholdVelocity = getInput<float>("thresholdVelocity");
52  ARMARX_DEBUG << "Installing allJointVelocitiesLow condition, threshold: " << thresholdVelocity
53  << flush;
54 
55  //=======
56  //first try ... (with ChannelRef)
57  //=======
58 
59  /*
60  Term allJointVelocitiesLow;
61  SingleTypeVariantListPtr jointNamesList = getInput<SingleTypeVariantList>("jointNames");
62  for (int i=0; i<jointNamesList->getSize(); i++)
63  {
64  allJointVelocitiesLow = allJointVelocitiesLow && Literal(getInput<ChannelRef>("jointVelocityChannel")
65  ->getDataFieldIdentifier(jointNamesList->getVariant(i)->getString()), "smaller", Literal::createParameterList(thresholdVelocity));
66  }
67  condAllJointVelocitiesLow = installCondition(allJointVelocitiesLow, createEvent<EvAllJointVelocitiesLow>());
68  */
69 
70  //=======
71  //second try ... (with DatafieldRef)
72  //=======
73  Term allJointVelocitiesLow_NEW;
74  //SingleTypeVariantListPtr jointNamesList = getInput<SingleTypeVariantList>("jointNames");
75  SingleTypeVariantListPtr dataFieldsList =
76  getInput<SingleTypeVariantList>("jointVelocitiesDatafields");
77 
78  //for (int i=0; i<jointNamesList->getSize(); i++)
79  for (int i = 0; i < dataFieldsList->getSize(); i++)
80  {
81  allJointVelocitiesLow_NEW =
82  allJointVelocitiesLow_NEW &&
83  Literal(dataFieldsList->getVariant(i)->get<DatafieldRef>()->getDataFieldIdentifier(),
84  "inrange",
85  Literal::createParameterList(-thresholdVelocity, thresholdVelocity));
86  }
87 
89  installCondition(allJointVelocitiesLow_NEW, createEvent<EvAllJointVelocitiesLow>());
90 
91  ARMARX_VERBOSE << "Done InstallTerminateConditions::onEnter()";
92 }
93 
94 void
96 {
97  ARMARX_VERBOSE << "Entering InstallTerminateConditions::onExit()";
100 
101  //---------
102  //set joint velocities manually to zero (DEBUG)
103  //---------
104 
105  std::string handUnitName = getInput<std::string>("handUnitName");
106  ARMARX_DEBUG << "xx..................SENDING OBJECTGRASPED TO hand unit name " << handUnitName
107  << "...................";
108 
109  RobotStatechartContext* rsContext = getContext<RobotStatechartContext>();
110 
111  if (rsContext->getHandUnit(handUnitName))
112  {
113  ARMARX_DEBUG << "xx..................SENDING OBJECTGRASPED TO hand unit name "
114  << handUnitName << ".......OK: sending Vitalis............";
115  rsContext->getHandUnit(handUnitName)->setObjectGrasped("Vitalis");
116  }
117 
118  SingleTypeVariantListPtr jointNames = getInput<SingleTypeVariantList>("jointNames");
119  //SingleTypeVariantListPtr jointTorquesGraspList = getInput<SingleTypeVariantList>("jointTorquesGrasp");
120  NameValueMap jointNamesAndValues;
121  NameControlModeMap controlModes;
122 
123  for (int j = 0; j < jointNames->getSize(); j++)
124  {
125  // 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!)
126  jointNamesAndValues[jointNames->getVariant(j)->getString()] =
127  0.0; //1f; //set everything to zero
128  controlModes[jointNames->getVariant(j)->getString()] = eVelocityControl;
129  }
130 
131  rsContext->kinematicUnitPrx->switchControlMode(controlModes);
132  // rsContext->kinematicUnitPrx->setJointTorques(jointNamesAndValues);
133  rsContext->kinematicUnitPrx->setJointVelocities(jointNamesAndValues);
134  ARMARX_VERBOSE << "Done InstallTerminateConditions::onExit()";
135 }
136 
137 // DO NOT EDIT NEXT FUNCTION
138 std::string
140 {
141  return "InstallTerminateConditions";
142 }
143 
144 // DO NOT EDIT NEXT FUNCTION
147 {
148  return XMLStateFactoryBasePtr(new InstallTerminateConditions(stateData));
149 }
armarx::RobotStatechartContext::getHandUnit
HandUnitInterfacePrx getHandUnit(const std::string &handUnitName)
Definition: RobotStatechartContext.cpp:125
armarx::StateUtility::removeCondition
void removeCondition(ConditionIdentifier conditionId)
Utility function to remove an installed condition on the distributed conditionhandler.
Definition: StateUtil.cpp:148
ARMARX_VERBOSE
#define ARMARX_VERBOSE
Definition: Logging.h:187
armarx::FindAndGraspObjectGroup::InstallTerminateConditions::Registry
static SubClassRegistry Registry
Definition: InstallTerminateConditions.h:51
armarx::XMLStateConstructorParams
Definition: XMLState.h:49
armarx::Literal::createParameterList
static VarList createParameterList()
Static helper method to create an empty parameterlist.
Definition: Term.cpp:142
armarx::FindAndGraspObjectGroup::InstallTerminateConditions::condGraspTimeout
ActionEventIdentifier condGraspTimeout
Definition: InstallTerminateConditions.h:57
armarx::FindAndGraspObjectGroup::InstallTerminateConditions::GetName
static std::string GetName()
Definition: InstallTerminateConditions.cpp:139
armarx::FindAndGraspObjectGroup::InstallTerminateConditions::condAllJointVelocitiesLow
ConditionIdentifier condAllJointVelocitiesLow
Definition: InstallTerminateConditions.h:56
armarx::Term
Definition: Term.h:111
armarx::FindAndGraspObjectGroup::InstallTerminateConditions::CreateInstance
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
Definition: InstallTerminateConditions.cpp:146
armarx::FindAndGraspObjectGroup::InstallTerminateConditions
Definition: InstallTerminateConditions.h:37
armarx::XMLStateFactoryBasePtr
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition: XMLState.h:64
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:43
IceInternal::Handle< SingleTypeVariantList >
DatafieldRef.h
armarx::RobotStatechartContext
Definition: RobotStatechartContext.h:79
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:162
armarx::XMLStateTemplate
Class for legacy to stay compatible with old statecharts.
Definition: XMLState.h:146
armarx::DatafieldRef::getDataFieldIdentifier
DataFieldIdentifierPtr getDataFieldIdentifier() const
Definition: DatafieldRef.cpp:112
armarx::flush
const LogSender::manipulator flush
Definition: LogSender.h:251
ARMARX_DEBUG
#define ARMARX_DEBUG
Definition: Logging.h:184
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:102
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::control::njoint_controller::platform::platform_follower_controller::NameValueMap
std::map< std::string, float > NameValueMap
Definition: PlatformFollowerController.h:88
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:95
armarx::StateUtility::removeTimeoutEvent
void removeTimeoutEvent(const ActionEventIdentifier &id)
Definition: StateUtil.cpp:203
armarx::RobotStatechartContext::kinematicUnitPrx
KinematicUnitInterfacePrx kinematicUnitPrx
Definition: RobotStatechartContext.h:112
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27