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
29using namespace armarx;
30using namespace ScanLocationGroup;
31
32// DO NOT EDIT NEXT LINE
33DetectObjects::SubClassRegistry DetectObjects::Registry(DetectObjects::GetName(),
35
37 XMLStateTemplate<DetectObjects>(stateData), DetectObjectsGeneratedBase<DetectObjects>(stateData)
38{
39}
40
41void
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
92void
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
constexpr T c
Literals are part of the user front end of the ArmarX condition mechanism.
Definition Term.h:209
static VarList createParameterList()
Static helper method to create an empty parameterlist.
Definition Term.cpp:142
std::vector< armarx::ChannelRefBasePtr > classBaseChannels
DetectObjects(XMLStateConstructorParams stateData)
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
Terms are part of the user front end of the ArmarX condition mechanism.
Definition Term.h:112
Class for legacy to stay compatible with old statecharts.
Definition XMLState.h:147
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