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