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