CalculateTarget.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 "CalculateTarget.h"
26 
27 #include "GraspObjectGroupStatechartContext.generated.h"
28 
29 using namespace armarx;
30 using namespace GraspObjectGroup;
31 
32 // DO NOT EDIT NEXT LINE
33 CalculateTarget::SubClassRegistry CalculateTarget::Registry(CalculateTarget::GetName(), &CalculateTarget::CreateInstance);
34 
35 
36 
38  XMLStateTemplate<CalculateTarget>(stateData), CalculateTargetGeneratedBase<CalculateTarget>(stateData)
39 {
40 }
41 
42 
43 
45 {
46  // get hand pose from MemoryX
47  GraspObjectGroupStatechartContext* context = getContext<GraspObjectGroupStatechartContext>();
48  FramedPose handPoseFromMemoryX;
49  ChannelRefPtr handMemoryChannel = getInput<ChannelRef>("HandMemoryChannel");
50  memoryx::ChannelRefBaseSequence instances = context->getObjectMemoryObserver()->getObjectInstances(handMemoryChannel);
51 
52  if (instances.size() == 0)
53  {
54  ARMARX_ERROR << "No instances of the hand in the memory";
55  return;
56  }
57  else
58  {
59  ARMARX_VERBOSE << "Getting hand pose from memory";
60 
61  FramedPositionPtr position = ChannelRefPtr::dynamicCast(instances.front())->get<FramedPosition>("position");
62  FramedOrientationPtr orientation = ChannelRefPtr::dynamicCast(instances.front())->get<FramedOrientation>("orientation");
63  handPoseFromMemoryX = FramedPose(orientation->toEigen(), position->toEigen(), position->getFrame(), position->agent);
64 
65  if (position->getFrame().empty())
66  {
67  ARMARX_WARNING << "Empty frame name!";
68  }
69  }
70 
71  ARMARX_IMPORTANT << "Hand pose from MemoryX: " << handPoseFromMemoryX;
72 
73  Eigen::Vector3f liftTranslation = in.getLiftTranslation()->toEigen();
74  Eigen::Matrix4f targetEigen1 = handPoseFromMemoryX.toRootEigen(getRobot());
75  targetEigen1(2, 3) += 0.7f * liftTranslation(2);
76  FramedPose target1(targetEigen1, getRobot()->getRootNode()->getName(), handPoseFromMemoryX.agent);
77  out.setTcpTargetPose1(target1);
78  Eigen::Matrix4f targetEigen2 = handPoseFromMemoryX.toRootEigen(getRobot());
79  targetEigen2.block<3, 1>(0, 3) += liftTranslation;
80  FramedPose target2(targetEigen1, getRobot()->getRootNode()->getName(), handPoseFromMemoryX.agent);
81  out.setTcpTargetPose2(target2);
82 
83  emitTargetCalculated();
84 }
85 
86 
87 
88 
89 
90 
92 {
93  // put your user code for the breaking point here
94  // execution time should be short (<100ms)
95 }
96 
97 
98 
100 {
101  // put your user code for the exit point here
102  // execution time should be short (<100ms)
103 }
104 
105 
106 
107 // DO NOT EDIT NEXT FUNCTION
109 {
110  return XMLStateFactoryBasePtr(new CalculateTarget(stateData));
111 }
112 
armarx::GraspObjectGroup::CalculateTarget::Registry
static SubClassRegistry Registry
Definition: CalculateTarget.h:44
ARMARX_VERBOSE
#define ARMARX_VERBOSE
Definition: Logging.h:180
armarx::GraspObjectGroup::CalculateTarget
Definition: CalculateTarget.h:31
ARMARX_IMPORTANT
#define ARMARX_IMPORTANT
Definition: Logging.h:183
armarx::FramedPose
The FramedPose class.
Definition: FramedPose.h:258
armarx::VariantType::FramedPose
const VariantTypeId FramedPose
Definition: FramedPose.h:37
armarx::GraspObjectGroup::CalculateTarget::onExit
void onExit() override
Definition: CalculateTarget.cpp:99
armarx::XMLStateConstructorParams
Definition: XMLState.h:50
armarx::GraspObjectGroup::CalculateTarget::onBreak
void onBreak() override
Definition: CalculateTarget.cpp:91
armarx::GraspObjectGroup::CalculateTarget::CalculateTarget
CalculateTarget(XMLStateConstructorParams stateData)
Definition: CalculateTarget.cpp:37
CalculateTarget.h
IceInternal::Handle< ChannelRef >
armarx::XMLStateTemplate
Class for legacy to stay compatible with old statecharts.
Definition: XMLState.h:137
armarx::GraspObjectGroup::CalculateTarget::onEnter
void onEnter() override
Definition: CalculateTarget.cpp:44
armarx::FramedPosition
The FramedPosition class.
Definition: FramedPose.h:142
armarx::Pose::toEigen
virtual Eigen::Matrix4f toEigen() const
Definition: Pose.cpp:334
ARMARX_ERROR
#define ARMARX_ERROR
Definition: Logging.h:189
armarx::FramedOrientation
The FramedOrientation class.
Definition: FramedPose.h:199
armarx::XMLStateFactoryBasePtr
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition: XMLState.h:65
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:601
armarx::GraspObjectGroup::CalculateTarget::CreateInstance
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
Definition: CalculateTarget.cpp:108
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28