DetectObjects.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::ScanLocationGroup
19  * @author Manfred Kroehnert ( Manfred dot Kroehnert 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 "DetectObjects.h"
26 
27 #include <RobotAPI/interface/components/ViewSelectionInterface.h>
28 
29 using namespace armarx;
30 using namespace ScanLocationGroup;
31 
32 // DO NOT EDIT NEXT LINE
33 DetectObjects::SubClassRegistry DetectObjects::Registry(DetectObjects::GetName(),
35 
37  XMLStateTemplate<DetectObjects>(stateData), DetectObjectsGeneratedBase<DetectObjects>(stateData)
38 {
39 }
40 
41 void
43 {
44  classBaseChannels.clear();
45 
46  std::vector<std::string> objectClasses = in.getObjectclassesToLocalize();
47 
48  if (objectClasses.empty())
49  {
50  emitFinished();
51  return;
52  }
53 
54  memoryx::ObjectMemoryObserverInterfacePrx memoryObserver = getObjectMemoryObserver();
55 
56  Term classesLocalized;
57 
58  for (std::string className : objectClasses)
59  {
60  ChannelRefBasePtr channel =
61  memoryObserver->requestObjectClassOnce(className, armarx::DEFAULT_VIEWTARGET_PRIORITY);
62 
63  if (!channel)
64  {
65  continue;
66  }
67 
68  classBaseChannels.push_back(channel);
69  ChannelRefPtr classChannel = ChannelRefPtr::dynamicCast(channel);
70 
71  if (classChannel)
72  {
73  Literal localizationFinished(
74  classChannel->getDataFieldIdentifier("localizationFinished"),
75  "equals",
77  classesLocalized = classesLocalized && localizationFinished;
78  }
79  }
80 
81  if (classBaseChannels.empty())
82  {
83  emitFinished();
84  }
85  else
86  {
87  installCondition(classesLocalized, createEventFinished());
88  setTimeoutEvent(in.getLocationTimeout() * 1000.0, createEventFinished());
89  }
90 }
91 
92 void
94 {
95  // put your user code for the exit point here
96  // execution time should be short (<100ms)
97  memoryx::ObjectMemoryObserverInterfacePrx memoryObserver = getObjectMemoryObserver();
98 
99  for (auto& c : classBaseChannels)
100  {
101  memoryObserver->releaseObjectClass(c);
102  }
103 
104  classBaseChannels.clear();
105 }
106 
107 // DO NOT EDIT NEXT FUNCTION
110 {
111  return XMLStateFactoryBasePtr(new DetectObjects(stateData));
112 }
armarx::ScanLocationGroup::DetectObjects
Definition: DetectObjects.h:33
armarx::ScanLocationGroup::DetectObjects::Registry
static SubClassRegistry Registry
Definition: DetectObjects.h:44
armarx::XMLStateConstructorParams
Definition: XMLState.h:49
armarx::ScanLocationGroup::DetectObjects::onEnter
void onEnter() override
Definition: DetectObjects.cpp:42
armarx::Literal::createParameterList
static VarList createParameterList()
Static helper method to create an empty parameterlist.
Definition: Term.cpp:142
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:46
armarx::Term
Definition: Term.h:111
armarx::XMLStateFactoryBasePtr
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition: XMLState.h:64
IceInternal::Handle< ChannelRef >
armarx::ScanLocationGroup::DetectObjects::onExit
void onExit() override
Definition: DetectObjects.cpp:93
armarx::XMLStateTemplate
Class for legacy to stay compatible with old statecharts.
Definition: XMLState.h:146
armarx::ScanLocationGroup::DetectObjects::classBaseChannels
std::vector< armarx::ChannelRefBasePtr > classBaseChannels
Definition: DetectObjects.h:49
armarx::Literal
Definition: Term.h:208
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::ScanLocationGroup::DetectObjects::CreateInstance
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
Definition: DetectObjects.cpp:109
DetectObjects.h
armarx::ScanLocationGroup::DetectObjects::DetectObjects
DetectObjects(XMLStateConstructorParams stateData)
Definition: DetectObjects.cpp:36