ScanLocation.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 2014
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24
25#include "ScanLocation.h"
26
30
31using namespace armarx;
32using namespace ScanLocationGroup;
33
34// DO NOT EDIT NEXT LINE
35ScanLocation::SubClassRegistry ScanLocation::Registry(ScanLocation::GetName(),
37
39 XMLStateTemplate<ScanLocation>(stateData), ScanLocationGeneratedBase<ScanLocation>(stateData)
40{
41}
42
43void
45{
46
47 ChannelRefPtr counterId =
48 ChannelRefPtr::dynamicCast(getSystemObserver()->startCounter(0, "ScanLocationCounter"));
49 local.setLocationCounterId(counterId);
50 local.setStartTime(new armarx::TimestampVariant(TimeUtil::GetTime()));
51
52 auto display = in.getDisplay_Text();
53 if (display.size() == 2)
54 {
55 getMessageDisplay()->setMessage(display.at(0), display.at(1));
56 }
57 else
58 {
59 ARMARX_WARNING << "Display text not set (wrong size): " << display.size();
60 }
61
62 std::vector<std::string> objectClasses = in.getObjectclassesToLocalize();
63
64 if (objectClasses.empty())
65 {
66 emitSuccess();
67 return;
68 }
69
70 memoryx::ObjectMemoryObserverInterfacePrx memoryObserver = getObjectMemoryObserver();
71
72 Term classesLocalized;
73 std::vector<ChannelRefPtr> localizationQueries;
74
75 for (std::string className : objectClasses)
76 {
77 ChannelRefPtr channel =
78 ChannelRefPtr::dynamicCast(memoryObserver->requestObjectClassRepeated(
79 className, in.getCycleTimeMs(), armarx::DEFAULT_VIEWTARGET_PRIORITY));
80
81 if (!channel)
82 {
83 continue;
84 }
85 localizationQueries.push_back(channel);
86 // classBaseChannels.push_back(channel);
87 // ChannelRefPtr classChannel = ChannelRefPtr::dynamicCast(channel);
88
89 // if (classChannel)
90 // {
91 // Literal localizationFinished(classChannel->getDataFieldIdentifier("localizationFinished"), "equals", Literal::createParameterList(true));
92 // classesLocalized = classesLocalized && localizationFinished;
93 // }
94 }
95 local.setLocalizationQueries(localizationQueries);
96}
97
98void
100{
101 // put your user code for the exit point here
102 // execution time should be short (<100ms)
103 memoryx::ObjectMemoryObserverInterfacePrx memoryObserver = getObjectMemoryObserver();
104 std::vector<armarx::ChannelRefPtr> resultInstances;
105 std::vector<std::string> objectClassNames = in.getObjectclassesToLocalize();
106
107 for (std::string const& className : objectClassNames)
108 {
109 if (className.find("/") != std::string::npos)
110 {
111 ARMARX_INFO << "Not adding ObjectInstanceChannel for ObjectPoseStorage instance: "
112 << className;
113 }
114 else
115 {
116 // TODO: only consider classes at scan locations
117 ARMARX_INFO << "Checking for instances of type " << className;
118 auto instances = memoryObserver->getObjectInstancesByClass(className);
119
120 for (auto& channel : instances)
121 {
122 auto objectInstanceChannelRef = ChannelRefPtr::dynamicCast(channel);
123
124 if (objectInstanceChannelRef)
125 {
126 resultInstances.push_back(objectInstanceChannelRef);
127 }
128 else
129 {
130 ARMARX_WARNING << "Channelref of instance " << className << " is null";
131 }
132 }
133 }
134 }
135
136 ARMARX_IMPORTANT << "Found the following objectInstances object instances: " << resultInstances;
137 out.setObjectInstanceChannels(resultInstances);
138
139 for (ChannelRefPtr channel : local.getLocalizationQueries())
140 {
141 ARMARX_INFO << "Releasing " << channel->channelName;
142 memoryObserver->releaseObjectClass(channel);
143 }
144}
145
146// DO NOT EDIT NEXT FUNCTION
149{
150 ARMARX_IMPORTANT_S << "ScanLocation::CreateInstance";
151 return XMLStateFactoryBasePtr(new ScanLocation(stateData));
152}
ScanLocation(XMLStateConstructorParams stateData)
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
Terms are part of the user front end of the ArmarX condition mechanism.
Definition Term.h:112
static IceUtil::Time GetTime(TimeMode timeMode=TimeMode::VirtualTime)
Get the current time.
Definition TimeUtil.cpp:42
Implements a Variant type for timestamps.
Class for legacy to stay compatible with old statecharts.
Definition XMLState.h:147
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
#define ARMARX_IMPORTANT
The logging level for always important information, but expected behaviour (in contrast to ARMARX_WAR...
Definition Logging.h:190
#define ARMARX_IMPORTANT_S
The logging level for always important information, but expected behaviour (in contrast to ARMARX_WAR...
Definition Logging.h:210
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:193
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