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
29using namespace armarx;
30using namespace FindAndGraspObjectGroup;
31
32// DO NOT EDIT NEXT LINE
33InstallTerminateConditions::SubClassRegistry
36
41
42void
44{
45 ARMARX_VERBOSE << "Entering InstallTerminateConditions::onEnter()";
46
47 ARMARX_DEBUG << "Installing timeoutGrasp condition";
48 float timeoutGrasp = getInput<float>("timeoutGrasp");
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
94void
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
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
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
138std::string
140{
141 return "InstallTerminateConditions";
142}
143
144// DO NOT EDIT NEXT FUNCTION
The DatafieldRef class is similar to the ChannelRef, but points to a specific Datafield instead of to...
DataFieldIdentifierPtr getDataFieldIdentifier() const
void onEnter() override
Virtual function, in which the behaviour of state is defined, when it is entered. Can be overridden,...
void onExit() override
Virtual function, in which the behaviour of state is defined, when it is exited. Can be overridden,...
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
Literals are part of the user front end of the ArmarX condition mechanism.
Definition Term.h:209
static VarList createParameterList()
Static helper method to create an empty parameterlist.
Definition Term.cpp:142
KinematicUnitInterfacePrx kinematicUnitPrx
HandUnitInterfacePrx getHandUnit(const std::string &handUnitName)
ContextType * getContext() const
Definition StateBase.h:71
void removeCondition(ConditionIdentifier conditionId)
Utility function to remove an installed condition on the distributed conditionhandler.
void removeTimeoutEvent(const ActionEventIdentifier &id)
ActionEventIdentifier setTimeoutEvent(int timeoutDurationMs, const EventPtr &evt)
Utility function to start a timer on the systemObserver and register an event on the conditionHandler...
EventPtr createEvent()
Utility function to create a new Event.
Definition StateUtil.h:63
ConditionIdentifier installCondition(const Term &condition, const EventPtr evt, const std::string &desc="")
Utility function to install a condition on the distributed conditionhandler.
std::enable_if_t< std::is_base_of_v< VariantDataClass, T >, IceInternal::Handle< T > > getInput(const std::string &key) const
getInput can be used to access a specific input parameter.
Definition State.h:620
Terms are part of the user front end of the ArmarX condition mechanism.
Definition Term.h:112
XMLStateTemplate(const XMLStateConstructorParams &params)
Definition XMLState.h:149
#define ARMARX_DEBUG
The logging level for output that is only interesting while debugging.
Definition Logging.h:184
#define ARMARX_VERBOSE
The logging level for verbose information.
Definition Logging.h:187
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< SingleTypeVariantList > SingleTypeVariantListPtr
const LogSender::manipulator flush
Definition LogSender.h:251
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition XMLState.h:64