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 
31 using namespace armarx;
32 using namespace ScanLocationGroup;
33 
34 // DO NOT EDIT NEXT LINE
35 ScanLocation::SubClassRegistry ScanLocation::Registry(ScanLocation::GetName(),
37 
39  XMLStateTemplate<ScanLocation>(stateData), ScanLocationGeneratedBase<ScanLocation>(stateData)
40 {
41 }
42 
43 void
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 
98 void
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 }
armarx::ScanLocationGroup::ScanLocation
Definition: ScanLocation.h:31
ARMARX_IMPORTANT_S
#define ARMARX_IMPORTANT_S
Definition: Logging.h:210
ARMARX_IMPORTANT
#define ARMARX_IMPORTANT
Definition: Logging.h:190
armarx::XMLStateConstructorParams
Definition: XMLState.h:49
armarx::TimestampVariant
Definition: TimestampVariant.h:54
display
Use of this software is granted under one of the following two to be chosen freely by the user Boost Software License Version Marcin Kalicinski Permission is hereby free of to any person or organization obtaining a copy of the software and accompanying documentation covered by this display
Definition: license.txt:11
armarx::ScanLocationGroup::ScanLocation::onEnter
void onEnter() override
Definition: ScanLocation.cpp:44
armarx::Term
Definition: Term.h:111
Term.h
armarx::XMLStateFactoryBasePtr
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition: XMLState.h:64
armarx::ScanLocationGroup::ScanLocation::onExit
void onExit() override
Definition: ScanLocation.cpp:99
IceInternal::Handle< ChannelRef >
ScanLocation.h
armarx::XMLStateTemplate
Class for legacy to stay compatible with old statecharts.
Definition: XMLState.h:146
TimestampVariant.h
armarx::ScanLocationGroup::ScanLocation::ScanLocation
ScanLocation(XMLStateConstructorParams stateData)
Definition: ScanLocation.cpp:38
armarx::TimeUtil::GetTime
static IceUtil::Time GetTime(TimeMode timeMode=TimeMode::VirtualTime)
Get the current time.
Definition: TimeUtil.cpp:42
TimeUtil.h
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:181
armarx::ScanLocationGroup::ScanLocation::Registry
static SubClassRegistry Registry
Definition: ScanLocation.h:42
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:193
armarx::ScanLocationGroup::ScanLocation::CreateInstance
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
Definition: ScanLocation.cpp:148
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27