GetHandPose.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 "GetHandPose.h"
26 
27 #include "VisualServoGroupStatechartContext.generated.h"
28 
30 
31 using namespace armarx;
32 using namespace VisualServoGroup;
33 
34 
35 // DO NOT EDIT NEXT LINE
37 
38 
39 
41  XMLStateTemplate < GetHandPose > (stateData),
42  GetHandPoseGeneratedBase < GetHandPose > (stateData)
43 {
44 }
45 
46 
47 
49 {
50  VisualServoGroupStatechartContext* context = getContext<VisualServoGroupStatechartContext>();
51  bool handLocalized = false;
52  bool handPoseUncertain = false;
53 
54  // get hand pose from kinematic model
55  FramedPosePtr handPoseFromKinematicModel = new FramedPose(context->getRobot()->getRobotNode(in.getTcpNameInRobotModel())->getPoseInRootFrame(),
56  context->getRobot()->getRootNode()->getName(),
57  context->getRobot()->getName());
58 
59  ARMARX_VERBOSE << "Hand pose from kinematic model: " << *handPoseFromKinematicModel;
60 
61  // get hand pose from MemoryX
62  FramedPosePtr handPoseFromMemoryX = handPoseFromKinematicModel;
63  ChannelRefPtr handMemoryChannel = in.getHandMemoryChannel();
64  memoryx::ChannelRefBaseSequence instances = context->getObjectMemoryObserver()->getObjectInstances(handMemoryChannel);
65 
66  if (instances.size() == 0)
67  {
68  ARMARX_WARNING << "No instances of the hand in the memory: " << handMemoryChannel->get<std::string>("className");
69  auto list = context->getObjectMemoryObserver()->getObjectInstancesByClass(handMemoryChannel->get<std::string>("className"));
70 
71  for (auto& entry : list)
72  {
73  ARMARX_INFO << "obj: " << ChannelRefPtr::dynamicCast(entry)->getDataField("className")->getString();
74  }
75  }
76  else
77  {
78  ARMARX_VERBOSE << "Getting hand pose from memory";
79  handLocalized = true;
80 
81  FramedPositionPtr position = ChannelRefPtr::dynamicCast(instances.front())->get<FramedPosition>("position");
82  FramedOrientationPtr orientation = ChannelRefPtr::dynamicCast(instances.front())->get<FramedOrientation>("orientation");
83  handPoseFromMemoryX = new FramedPose(orientation->toEigen(), position->toEigen(), position->getFrame(), position->agent);
84 
85  handPoseFromMemoryX->changeFrame(context->getRobot(), context->getRobot()->getRootNode()->getName());
86 
87  context->getDebugDrawerTopic()->setPoseVisu("VisualServo", in.getTcpNameInRobotModel(), handPoseFromMemoryX->toGlobal(context->getRobot()));
88 
89  float uncertainty = ChannelRefPtr::dynamicCast(instances.front())->get<float>("uncertaintyOfPosition");
90  ARMARX_VERBOSE << "Uncertainty of hand position: " << uncertainty;
91 
92  if (uncertainty > 100.0f)
93  {
94  handPoseUncertain = true;
95  }
96  }
97 
98  setOutput("HandPose", handPoseFromMemoryX);
99  setOutput("HandPoseFromKinematicModel", handPoseFromKinematicModel);
100 
101  if (handLocalized)
102  {
103  if (handPoseUncertain)
104  {
105  TimeUtil::MSSleep(100);
106  sendEvent<HandPoseUncertain>();
107  }
108  else
109  {
110  sendEvent<HandPoseAvailable>();
111  }
112  }
113  else
114  {
115  TimeUtil::MSSleep(100);
116  sendEvent<HandNotYetLocalized>();
117  }
118 }
119 
120 
121 
122 
123 
124 
126 {
127  // put your user code for the breaking point here
128  // execution time should be short (<100ms)
129 }
130 
131 
132 
134 {
135  // put your user code for the exit point here
136  // execution time should be short (<100ms)
137 
138 }
139 
140 
141 
142 // DO NOT EDIT NEXT FUNCTION
143 std::string GetHandPose::GetName()
144 {
145  return "GetHandPose";
146 }
147 
148 
149 
150 // DO NOT EDIT NEXT FUNCTION
152 {
153  return XMLStateFactoryBasePtr(new GetHandPose(stateData));
154 }
155 
ARMARX_VERBOSE
#define ARMARX_VERBOSE
Definition: Logging.h:180
armarx::VisualServoGroup::GetHandPose::onEnter
void onEnter() override
Definition: GetHandPose.cpp:48
armarx::VariantType::FramedPose
const VariantTypeId FramedPose
Definition: FramedPose.h:37
list
list(APPEND SOURCES ${QT_RESOURCES}) set(COMPONENT_LIBS ArmarXGui ArmarXCoreObservers ArmarXCoreEigen3Variants PlotterController $
Definition: CMakeLists.txt:49
armarx::TimeUtil::MSSleep
static void MSSleep(int durationMS)
lock the calling thread for a given duration (like usleep(...) but using Timeserver time)
Definition: TimeUtil.cpp:94
armarx::XMLStateConstructorParams
Definition: XMLState.h:50
GetHandPose.h
IceInternal::Handle< FramedPose >
armarx::FramedOrientation::toGlobal
FramedOrientationPtr toGlobal(const SharedRobotInterfacePrx &referenceRobot) const
Definition: FramedPose.cpp:1016
armarx::XMLStateTemplate
Class for legacy to stay compatible with old statecharts.
Definition: XMLState.h:137
armarx::FramedPosition
The FramedPosition class.
Definition: FramedPose.h:142
armarx::FramedOrientation
The FramedOrientation class.
Definition: FramedPose.h:199
armarx::VisualServoGroup::GetHandPose::Registry
static SubClassRegistry Registry
Definition: GetHandPose.h:50
armarx::VisualServoGroup::GetHandPose::CreateInstance
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
Definition: GetHandPose.cpp:151
armarx::XMLStateFactoryBasePtr
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition: XMLState.h:65
TimeUtil.h
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
armarx::VisualServoGroup::GetHandPose::onBreak
void onBreak() override
Definition: GetHandPose.cpp:125
armarx::VisualServoGroup::GetHandPose
Definition: GetHandPose.h:36
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186
armarx::VisualServoGroup::GetHandPose::onExit
void onExit() override
Definition: GetHandPose.cpp:133
armarx::VisualServoGroup::GetHandPose::GetName
static std::string GetName()
Definition: GetHandPose.cpp:143
armarx::VisualServoGroup::GetHandPose::GetHandPose
GetHandPose(XMLStateConstructorParams stateData)
Definition: GetHandPose.cpp:40
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::FramedOrientation::changeFrame
void changeFrame(const SharedRobotInterfacePrx &referenceRobot, const std::string &newFrame)
Definition: FramedPose.cpp:925