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(), &ScanLocation::CreateInstance);
36 
37 
38 
40  XMLStateTemplate< ScanLocation >(stateData),
41  ScanLocationGeneratedBase< ScanLocation >(stateData)
42 {
43 }
44 
46 {
47 
48  ChannelRefPtr counterId = 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 = ChannelRefPtr::dynamicCast(memoryObserver->requestObjectClassRepeated(className, in.getCycleTimeMs(), armarx::DEFAULT_VIEWTARGET_PRIORITY));
78 
79  if (!channel)
80  {
81  continue;
82  }
83  localizationQueries.push_back(channel);
84  // classBaseChannels.push_back(channel);
85  // ChannelRefPtr classChannel = ChannelRefPtr::dynamicCast(channel);
86 
87  // if (classChannel)
88  // {
89  // Literal localizationFinished(classChannel->getDataFieldIdentifier("localizationFinished"), "equals", Literal::createParameterList(true));
90  // classesLocalized = classesLocalized && localizationFinished;
91  // }
92  }
93  local.setLocalizationQueries(localizationQueries);
94 
95 }
96 
97 
99 {
100  // put your user code for the exit point here
101  // execution time should be short (<100ms)
102  memoryx::ObjectMemoryObserverInterfacePrx memoryObserver = getObjectMemoryObserver();
103  std::vector<armarx::ChannelRefPtr> resultInstances;
104  std::vector<std::string> objectClassNames = in.getObjectclassesToLocalize();
105 
106  for (std::string const& className : objectClassNames)
107  {
108  if (className.find("/") != std::string::npos)
109  {
110  ARMARX_INFO << "Not adding ObjectInstanceChannel for ObjectPoseStorage instance: "
111  << className;
112  }
113  else
114  {
115  // TODO: only consider classes at scan locations
116  ARMARX_INFO << "Checking for instances of type " << className;
117  auto instances = memoryObserver->getObjectInstancesByClass(className);
118 
119  for (auto& channel : instances)
120  {
121  auto objectInstanceChannelRef = ChannelRefPtr::dynamicCast(channel);
122 
123  if (objectInstanceChannelRef)
124  {
125  resultInstances.push_back(objectInstanceChannelRef);
126  }
127  else
128  {
129  ARMARX_WARNING << "Channelref of instance " << className << " is null";
130  }
131  }
132  }
133  }
134 
135  ARMARX_IMPORTANT << "Found the following objectInstances object instances: " << resultInstances;
136  out.setObjectInstanceChannels(resultInstances);
137 
138  for (ChannelRefPtr channel : local.getLocalizationQueries())
139  {
140  ARMARX_INFO << "Releasing " << channel->channelName;
141  memoryObserver->releaseObjectClass(channel);
142  }
143 }
144 
145 
146 // DO NOT EDIT NEXT FUNCTION
148 {
149  ARMARX_IMPORTANT_S << "ScanLocation::CreateInstance";
150  return XMLStateFactoryBasePtr(new ScanLocation(stateData));
151 }
152 
armarx::ScanLocationGroup::ScanLocation
Definition: ScanLocation.h:31
ARMARX_IMPORTANT_S
#define ARMARX_IMPORTANT_S
Definition: Logging.h:203
ARMARX_IMPORTANT
#define ARMARX_IMPORTANT
Definition: Logging.h:183
armarx::XMLStateConstructorParams
Definition: XMLState.h:50
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:45
armarx::Term
Definition: Term.h:111
Term.h
armarx::ScanLocationGroup::ScanLocation::onExit
void onExit() override
Definition: ScanLocation.cpp:98
IceInternal::Handle< ChannelRef >
ScanLocation.h
armarx::XMLStateTemplate
Class for legacy to stay compatible with old statecharts.
Definition: XMLState.h:137
TimestampVariant.h
armarx::ScanLocationGroup::ScanLocation::ScanLocation
ScanLocation(XMLStateConstructorParams stateData)
Definition: ScanLocation.cpp:39
armarx::TimeUtil::GetTime
static IceUtil::Time GetTime(TimeMode timeMode=TimeMode::VirtualTime)
Get the current time.
Definition: TimeUtil.cpp:42
armarx::XMLStateFactoryBasePtr
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition: XMLState.h:65
TimeUtil.h
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
armarx::ScanLocationGroup::ScanLocation::Registry
static SubClassRegistry Registry
Definition: ScanLocation.h:43
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186
armarx::ScanLocationGroup::ScanLocation::CreateInstance
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
Definition: ScanLocation.cpp:147
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28