LiftHand.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::GraspObjectGroup
19 * @author David ( david dot schiebener at 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 "LiftHand.h"
26
27#include "GraspObjectGroupStatechartContext.generated.h"
30
31
32using namespace armarx;
33using namespace GraspObjectGroup;
34
35
36// DO NOT EDIT NEXT LINE
37LiftHand::SubClassRegistry LiftHand::Registry(LiftHand::GetName(), &LiftHand::CreateInstance);
38
40 XMLStateTemplate<LiftHand>(stateData), LiftHandGeneratedBase<LiftHand>(stateData)
41{
42}
43
44void
46{
47 GraspObjectGroupStatechartContext* context = getContext<GraspObjectGroupStatechartContext>();
48
49 // request IK units
50 ARMARX_VERBOSE << "Requesting TCP control unit";
51 context->getTCPControlUnit()->request();
52 ARMARX_VERBOSE << "Requested TCP control unit";
53
54 // set motion model AttachedToOtherObject
55 if (in.isObjectInstanceChannelSet())
56 {
57 std::string objName = in.getObjectInstanceChannel()->getDataField("className")->getString();
58 auto handInstances = context->getObjectMemoryObserver()->getObjectInstancesByClass(
59 in.getHandMemoryChannel()->getDataField("className")->getString());
60 ARMARX_CHECK_EXPRESSION(handInstances.size() != 0);
61 ChannelRefBasePtr handChannel = handInstances.front();
62
64 new memoryx::MotionModelAttachedToOtherObject(context->getRobotStateComponent(),
65 ChannelRefPtr::dynamicCast(handChannel));
66 memoryx::ObjectInstancePtr object = memoryx::ObjectInstancePtr::dynamicCast(
67 context->getWorkingMemory()->getObjectInstancesSegment()->getEntityByName(objName));
68
69 context->getWorkingMemory()->getObjectInstancesSegment()->setNewMotionModel(object->getId(),
70 newMotionModel);
72 << "Attached object to "
73 << ChannelRefPtr::dynamicCast(handChannel)->getDataField("className")->getString();
74 }
75
76 // TCP visu
77 std::string chainName = in.getKinematicChainName();
78 memoryx::PersistentObjectClassSegmentBasePrx classesSegmentPrx =
79 context->getPriorKnowledge()->getObjectClassesSegment();
80 auto tcpObjectClass = classesSegmentPrx->getObjectClassByName(
81 in.getHandMemoryChannel()->getDataField("className")->getString());
82 if (tcpObjectClass)
83 {
84 context->getEntityDrawerTopic()->setObjectVisu(
85 "VisualServoHandVisu", "tcpTarget_" + chainName, tcpObjectClass, new Pose());
86 context->getEntityDrawerTopic()->updateObjectTransparency(
87 "VisualServoHandVisu", "tcpTarget_" + chainName, 0.3);
88 }
89
90 local.setStartTimeRef(
91 ChannelRefPtr::dynamicCast(context->systemObserverPrx->startTimer("LiftHandTimer")));
92}
93
94void
96{
97 // put your user code for the exit point here
98 // execution time should be short (<100ms)
99
100 GraspObjectGroupStatechartContext* context = getContext<GraspObjectGroupStatechartContext>();
101 ARMARX_VERBOSE << "Releasing TCP control unit";
102 context->getTCPControlUnit()->release();
103 ARMARX_VERBOSE << "Released TCP control unit";
104
105 context->systemObserverPrx->removeTimer(local.getStartTimeRef());
106 context->getEntityDrawerTopic()->removeLayer("VisualServoHandVisu");
107}
108
109// DO NOT EDIT NEXT FUNCTION
LiftHand(XMLStateConstructorParams stateData)
Definition LiftHand.cpp:39
static SubClassRegistry Registry
Definition LiftHand.h:42
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
Definition LiftHand.cpp:111
The Pose class.
Definition Pose.h:243
Class for legacy to stay compatible with old statecharts.
Definition XMLState.h:147
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
#define ARMARX_IMPORTANT
The logging level for always important information, but expected behaviour (in contrast to ARMARX_WAR...
Definition Logging.h:190
#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< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition XMLState.h:64
IceInternal::Handle< MotionModelAttachedToOtherObject > MotionModelAttachedToOtherObjectPtr
IceInternal::Handle< ObjectInstance > ObjectInstancePtr