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(), &DetectObjects::CreateInstance);
34 
35 
36 
38  XMLStateTemplate<DetectObjects>(stateData), DetectObjectsGeneratedBase<DetectObjects>(stateData)
39 {
40 }
41 
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 = memoryObserver->requestObjectClassOnce(className, armarx::DEFAULT_VIEWTARGET_PRIORITY);
61 
62  if (!channel)
63  {
64  continue;
65  }
66 
67  classBaseChannels.push_back(channel);
68  ChannelRefPtr classChannel = ChannelRefPtr::dynamicCast(channel);
69 
70  if (classChannel)
71  {
72  Literal localizationFinished(classChannel->getDataFieldIdentifier("localizationFinished"), "equals", Literal::createParameterList(true));
73  classesLocalized = classesLocalized && localizationFinished;
74  }
75  }
76 
77  if (classBaseChannels.empty())
78  {
79  emitFinished();
80  }
81  else
82  {
83  installCondition(classesLocalized, createEventFinished());
84  setTimeoutEvent(in.getLocationTimeout() * 1000.0, createEventFinished());
85  }
86 }
87 
89 {
90  // put your user code for the exit point here
91  // execution time should be short (<100ms)
92  memoryx::ObjectMemoryObserverInterfacePrx memoryObserver = getObjectMemoryObserver();
93 
94  for (auto& c : classBaseChannels)
95  {
96  memoryObserver->releaseObjectClass(c);
97  }
98 
99  classBaseChannels.clear();
100 }
101 
102 
103 // DO NOT EDIT NEXT FUNCTION
105 {
106  return XMLStateFactoryBasePtr(new DetectObjects(stateData));
107 }
108 
armarx::ScanLocationGroup::DetectObjects
Definition: DetectObjects.h:33
armarx::ScanLocationGroup::DetectObjects::Registry
static SubClassRegistry Registry
Definition: DetectObjects.h:45
armarx::XMLStateConstructorParams
Definition: XMLState.h:50
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:129
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
armarx::Term
Definition: Term.h:111
IceInternal::Handle< ChannelRef >
armarx::ScanLocationGroup::DetectObjects::onExit
void onExit() override
Definition: DetectObjects.cpp:88
armarx::XMLStateTemplate
Class for legacy to stay compatible with old statecharts.
Definition: XMLState.h:137
armarx::ScanLocationGroup::DetectObjects::classBaseChannels
std::vector< armarx::ChannelRefBasePtr > classBaseChannels
Definition: DetectObjects.h:50
armarx::XMLStateFactoryBasePtr
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition: XMLState.h:65
armarx::Literal
Definition: Term.h:208
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::ScanLocationGroup::DetectObjects::CreateInstance
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
Definition: DetectObjects.cpp:104
DetectObjects.h
armarx::ScanLocationGroup::DetectObjects::DetectObjects
DetectObjects(XMLStateConstructorParams stateData)
Definition: DetectObjects.cpp:37