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
31using namespace armarx;
32using namespace VisualServoGroup;
33
34
35// DO NOT EDIT NEXT LINE
36GetHandPose::SubClassRegistry GetHandPose::Registry(GetHandPose::GetName(),
38
40 XMLStateTemplate<GetHandPose>(stateData), GetHandPoseGeneratedBase<GetHandPose>(stateData)
41{
42}
43
44void
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 {
117 sendEvent<HandPoseUncertain>();
118 }
119 else
120 {
121 sendEvent<HandPoseAvailable>();
122 }
123 }
124 else
125 {
127 sendEvent<HandNotYetLocalized>();
128 }
129}
130
131void
133{
134 // put your user code for the breaking point here
135 // execution time should be short (<100ms)
136}
137
138void
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
146std::string
148{
149 return "GetHandPose";
150}
151
152// DO NOT EDIT NEXT FUNCTION
The FramedOrientation class.
Definition FramedPose.h:216
FramedOrientationPtr toGlobal(const SharedRobotInterfacePrx &referenceRobot) const
void changeFrame(const SharedRobotInterfacePrx &referenceRobot, const std::string &newFrame)
The FramedPose class.
Definition FramedPose.h:281
The FramedPosition class.
Definition FramedPose.h:158
static void MSSleep(int durationMS)
lock the calling thread for a given duration (like usleep(...) but using Timeserver time)
Definition TimeUtil.cpp:100
static SubClassRegistry Registry
Definition GetHandPose.h:50
GetHandPose(XMLStateConstructorParams stateData)
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
Class for legacy to stay compatible with old statecharts.
Definition XMLState.h:147
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:193
#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< ChannelRef > ChannelRefPtr
Definition ChannelRef.h:40
IceInternal::Handle< FramedPosition > FramedPositionPtr
Definition FramedPose.h:149
IceInternal::Handle< FramedOrientation > FramedOrientationPtr
Definition FramedPose.h:207
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition XMLState.h:64
IceInternal::Handle< FramedPose > FramedPosePtr
Definition FramedPose.h:272