WaitForHandAndObjectChannel.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::PlaceObjectGroup
19 * @author David ( david dot schiebener 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
26
28
29#include <RobotAPI/interface/components/ViewSelectionInterface.h>
30
31
32using namespace armarx;
33using namespace PlaceObjectGroup;
34
35// DO NOT EDIT NEXT LINE
36WaitForHandAndObjectChannel::SubClassRegistry
37 WaitForHandAndObjectChannel::Registry(WaitForHandAndObjectChannel::GetName(),
39
41 const XMLStateConstructorParams& stateData) :
43 WaitForHandAndObjectChannelGeneratedBase<WaitForHandAndObjectChannel>(stateData)
44{
45}
46
47void
49{
50 PlaceObjectGroupStatechartContextBase* context =
51 getContext<PlaceObjectGroupStatechartContextBase>();
52
53 if (context->getObjectMemoryObserver()->getObjectInstancesByClass(in.getObjectName()).size() ==
54 0)
55 {
56 ARMARX_VERBOSE << "Requesting object " << in.getObjectName();
57 ChannelRefBasePtr objectMemoryChannel =
58 context->getObjectMemoryObserver()->requestObjectClassRepeated(
59 in.getObjectName(), 200, armarx::DEFAULT_VIEWTARGET_PRIORITY);
60
61 if (objectMemoryChannel)
62 {
63 local.setObjectMemoryChannel(ChannelRefPtr::dynamicCast(objectMemoryChannel));
64 }
65 }
66
67 if (context->getObjectMemoryObserver()
68 ->getObjectInstancesByClass(in.getHandNameInMemory())
69 .size() == 0)
70 {
71 ARMARX_VERBOSE << "Requesting hand " << in.getHandNameInMemory();
72 ChannelRefBasePtr handMemoryChannel =
73 context->getObjectMemoryObserver()->requestObjectClassRepeated(
74 in.getHandNameInMemory(), 300, armarx::DEFAULT_VIEWTARGET_PRIORITY);
75
76 if (handMemoryChannel)
77 {
78 //handMemoryChannel->validate();
79 local.setHandMemoryChannel(ChannelRefPtr::dynamicCast(handMemoryChannel));
80 }
81 }
82}
83
84void
86{
87 int waitSec = in.getWaitUntilProcessSec();
88 if (waitSec > 0)
89 {
90 TimeUtil::MSSleep(waitSec * 1000);
91 }
92 else
93 {
95 }
96
97 PlaceObjectGroupStatechartContextBase* context =
98 getContext<PlaceObjectGroupStatechartContextBase>();
99 bool bothAvailable = false;
100 memoryx::ChannelRefBaseSequence objectList;
101 armarx::ChannelRefPtr objChannel;
102 memoryx::ChannelRefBaseSequence handList;
103 armarx::ChannelRefPtr handChannel;
104
105 while (!isRunningTaskStopped() && !bothAvailable) // stop run function if returning true
106 {
107 handList =
108 context->getObjectMemoryObserver()->getObjectInstancesByClass(in.getHandNameInMemory());
109
110 if (handList.size() > 0)
111 {
112 handChannel = ChannelRefPtr::dynamicCast(handList.at(0));
113 }
114 else
115 {
116 ARMARX_VERBOSE << "Hand " << in.getHandNameInMemory() << " not yet localized";
118 }
119
120 objectList =
121 context->getObjectMemoryObserver()->getObjectInstancesByClass(in.getObjectName());
122
123 if (objectList.size() > 0)
124 {
125 objChannel = ChannelRefPtr::dynamicCast(objectList.at(0));
126 }
127 else
128 {
129 ARMARX_VERBOSE << "Object " << in.getObjectName() << " not localized";
131 }
132
133
134 if (handChannel)
135 {
136 // sometimes the object cannot be localized, so we are happy with the hand channel...
137 if (objChannel)
138 {
139 out.setObjectChannelRef(objChannel);
140 }
141
142 out.setHandChannelRef(handChannel);
143 out.setObjectClassName(in.getObjectName());
144 bothAvailable = true;
145 emitHandAndObjectLocalized();
146 }
147 }
148}
149
150void
152{
153 // put your user code for the breaking point here
154 // execution time should be short (<100ms)
155}
156
157void
159{
160 // put your user code for the exit point here
161 // execution time should be short (<100ms)
162}
163
164// DO NOT EDIT NEXT FUNCTION
WaitForHandAndObjectChannel(const XMLStateConstructorParams &stateData)
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
static void MSSleep(int durationMS)
lock the calling thread for a given duration (like usleep(...) but using Timeserver time)
Definition TimeUtil.cpp:100
Class for legacy to stay compatible with old statecharts.
Definition XMLState.h:147
#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