GetObjectInstance.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::VisualServoGroup
19 * @author Mirko Waechter ( waechter at kit dot edu )
20 * @date 2015
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24
25#include "GetObjectInstance.h"
26
28
29#include "VisualServoGroupStatechartContext.generated.h"
30
31using namespace armarx;
32using namespace VisualServoGroup;
33
34// DO NOT EDIT NEXT LINE
35GetObjectInstance::SubClassRegistry GetObjectInstance::Registry(GetObjectInstance::GetName(),
37
40 GetObjectInstanceGeneratedBase<GetObjectInstance>(stateData)
41{
42}
43
44void
46{
47 VisualServoGroupStatechartContext* context = getContext<VisualServoGroupStatechartContext>();
48
49
50 ChannelRefPtr objectInstance;
51
52 if (in.isObjectInstanceChannelSet())
53 {
54 objectInstance = in.getObjectInstanceChannel();
55 }
56 else if (in.isObjectClassChannelSet())
57 {
58 ChannelRefPtr objectMemoryChannel = in.getObjectClassChannel();
59
60 if (!context->getObjectMemoryObserver())
61 {
62 ARMARX_WARNING << "getObjectMemoryObserver is NULL";
63 setTimeoutEvent(500, createEventObjectNotYetLocalized());
64 return;
65 }
66
67 memoryx::ChannelRefBaseSequence instances =
68 context->getObjectMemoryObserver()->getObjectInstances(objectMemoryChannel);
69
70 if (instances.size() == 0)
71 {
72 ARMARX_WARNING << "No instances of the object in the memory - obj channel: "
73 << objectMemoryChannel->output();
74 setTimeoutEvent(500, createEventObjectNotYetLocalized());
75 return;
76 }
77
78 objectInstance = ChannelRefPtr::dynamicCast(instances.front());
79 }
80 else
81 {
82 throw LocalException("Either ObjectInstanceChannel or ObjectMemoryChannel must be set in " +
83 getStateClassName());
84 }
85
86
87 ARMARX_CHECK_EXPRESSION(objectInstance);
88 out.setObjectInstanceChannel(objectInstance);
89 ARMARX_INFO << "Checking existenceCertainty: "
90 << objectInstance->getDataField("existenceCertainty")->getFloat() << " > "
91 << in.getMinimumExistenceCertainty();
92 ARMARX_INFO << "Checking positionUncertainty: "
93 << objectInstance->get<float>("uncertaintyOfPosition") << " < "
94 << in.getMaximalPositionUncertainty();
95
96 float existenceCertainty = objectInstance->getDataField("existenceCertainty")->getFloat();
97 if (existenceCertainty >= in.getMinimumExistenceCertainty())
98 {
99 float positionUncertainty = objectInstance->get<float>("uncertaintyOfPosition");
100
101 if (existenceCertainty >= in.getGoodExistenceCertainty() &&
102 positionUncertainty <= in.getMaximalPositionUncertainty())
103 {
104 if (in.getRequestTCPControlUnit())
105 {
106 getTcpControlUnit()->request();
107 }
108 emitObjectInstanceChannelFound();
109 }
110 else
111 {
112 ARMARX_VERBOSE << "Waiting for better localization. Existence certainty: "
113 << existenceCertainty << " (min: " << in.getGoodExistenceCertainty()
114 << "), position uncertainty: " << positionUncertainty
115 << " (max: " << in.getMaximalPositionUncertainty() << ")";
116 if (in.getRequestTCPControlUnit())
117 {
118 getTcpControlUnit()->release();
119 }
121 emitWaitForBetterLocalization();
122 }
123 }
124 else
125 {
126 ARMARX_WARNING << "Object was found earlier but is lost now: Existence certainty is only "
127 << existenceCertainty;
128 emitObjectNotFound();
129 }
130}
131
132void
134{
135 // put your user code for the execution-phase here
136 // runs in seperate thread, thus can do complex operations
137 // should check constantly whether isRunningTaskStopped() returns true
138
139 // uncomment this if you need a continous run function. Make sure to use sleep or use blocking wait to reduce cpu load.
140 // while (!isRunningTaskStopped()) // stop run function if returning true
141 // {
142 // // do your calculations
143 // }
144}
145
146void
148{
149 // put your user code for the breaking point here
150 // execution time should be short (<100ms)
151}
152
153void
155{
156 // put your user code for the exit point here
157 // execution time should be short (<100ms)
158}
159
160// DO NOT EDIT NEXT FUNCTION
static void MSSleep(int durationMS)
lock the calling thread for a given duration (like usleep(...) but using Timeserver time)
Definition TimeUtil.cpp:100
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
GetObjectInstance(const XMLStateConstructorParams &stateData)
Class for legacy to stay compatible with old statecharts.
Definition XMLState.h:147
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
#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< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition XMLState.h:64