CheckLocalizationResult.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * ArmarX is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * ArmarX is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * @package RobotSkillTemplates::ScanLocationGroup
17  * @author Markus Grotz ( markus dot grotz at kit dot edu )
18  * @date 2019
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
24 
25 
26 //#include <ArmarXCore/observers/variant/DatafieldRef.h>
27 
28 
31 
32 #include <MemoryX/interface/components/WorkingMemoryInterface.h>
33 #include <MemoryX/interface/observers/ObjectMemoryObserverInterface.h>
35 
36 
38 
39 
40 using namespace armarx;
41 using namespace ScanLocationGroup;
42 
43 // DO NOT EDIT NEXT LINE
44 CheckLocalizationResult::SubClassRegistry CheckLocalizationResult::Registry(CheckLocalizationResult::GetName(), &CheckLocalizationResult::CreateInstance);
45 
46 
47 
49 {
50 
51  TimestampVariantPtr startTime = in.getStartTime();
52 
53  memoryx::ObjectMemoryObserverInterfacePrx objectMemoryObserver = getObjectMemoryObserver();
54 
55  if (in.getObjects().empty())
56  {
57  ARMARX_WARNING << "Object list is empty.";
58  emitFailure();
59  return;
60  }
61  bool all_found = true;
62  for (std::string& objectName : in.getObjects())
63  {
64  bool found = false;
65  if (objectName.find("/") != std::string::npos)
66  {
67  // TODO: Check in ObjectPoseStorage whether object was found
68  // Check timestamp is recently
69 
70  // It's an ObjectID.
71  ObjectID id(objectName);
72  objpose::ObjectPoseSeq objectPoses = objpose::fromIce(getObjectPoseStorage()->getObjectPoses());
73  for (const auto& p : objectPoses)
74  {
75  if (p.objectID == id)
76  {
77  ARMARX_IMPORTANT << "Found object in ObjectPoseStorage: " << id;
78  // out.setObjectChannel(nullptr); // Optional
79  // Miss-use instance ID for our ObjectID.
80  found = true;
81  break;
82  }
83  }
84  if (!found)
85  {
86  ARMARX_WARNING << "Object instance ID '" << objectName << "' looks like an armarx::ObjectID, "
87  << "but no such object was found in ObjectPoseStorage (offering " << objectPoses.size() << " objects)."
88  << "Trying to interpret it as memory instance ID.";
89  }
90  }
91  else
92  {
93  std::vector<ChannelRefBasePtr> objectInstanceList = objectMemoryObserver->getObjectInstancesByClass(objectName);
94 
95  for (ChannelRefBasePtr objectInstanceChannel : objectInstanceList)
96  {
97 
98  ChannelRefPtr channelRef = ChannelRefPtr::dynamicCast(objectInstanceChannel);
99  if (!channelRef || !channelRef->hasDatafield("pose"))
100  {
101  continue;
102  }
103 
104  TimestampVariantPtr localizationTimestamp = channelRef->get<TimestampVariant>("timestamp");
105 
106  if (localizationTimestamp->toTime() > startTime->toTime())
107  {
108  found = true;
109  break;
110  }
111 
112  }
113  }
114  if (!found)
115  {
116  all_found = false;
117  emitIncomplete();
118  return;
119  }
120  }
121 
122  if (all_found)
123  {
124  emitComplete();
125  }
126  else
127  {
128  emitIncomplete();
129  }
130 }
131 
132 //void CheckLocalizationResult::run()
133 //{
134 // // put your user code for the execution-phase here
135 // // runs in seperate thread, thus can do complex operations
136 // // should check constantly whether isRunningTaskStopped() returns true
137 //
138 //// uncomment this if you need a continous run function. Make sure to use sleep or use blocking wait to reduce cpu load.
139 // while (!isRunningTaskStopped()) // stop run function if returning true
140 // {
141 // // do your calculations
142 // }
143 //}
144 
145 //void CheckLocalizationResult::onBreak()
146 //{
147 // // put your user code for the breaking point here
148 // // execution time should be short (<100ms)
149 //}
150 
152 {
153  // put your user code for the exit point here
154  // execution time should be short (<100ms)
155 }
156 
157 
158 // DO NOT EDIT NEXT FUNCTION
160 {
161  return XMLStateFactoryBasePtr(new CheckLocalizationResult(stateData));
162 }
163 
armarx::ObjectID
A known object ID of the form "Dataset/ClassName" or "Dataset/ClassName/InstanceName".
Definition: ObjectID.h:11
ARMARX_IMPORTANT
#define ARMARX_IMPORTANT
Definition: Logging.h:183
armarx::objpose::ObjectPoseSeq
std::vector< ObjectPose > ObjectPoseSeq
Definition: forward_declarations.h:20
CheckLocalizationResult.h
armarx::XMLStateConstructorParams
Definition: XMLState.h:50
armarx::objpose::fromIce
void fromIce(const Box &box, simox::OrientedBox< float > &oobb)
armarx::TimestampVariant
Definition: TimestampVariant.h:54
armarx::ScanLocationGroup::CheckLocalizationResult::onEnter
void onEnter() override
Definition: CheckLocalizationResult.cpp:48
IceInternal::Handle< TimestampVariant >
armarx::ScanLocationGroup::CheckLocalizationResult::CreateInstance
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
Definition: CheckLocalizationResult.cpp:159
armarx::ScanLocationGroup::CheckLocalizationResult::onExit
void onExit() override
Definition: CheckLocalizationResult.cpp:151
FramedPose.h
armarx::ScanLocationGroup::CheckLocalizationResult::Registry
static SubClassRegistry Registry
Definition: CheckLocalizationResult.h:45
ObjectPose.h
armarx::XMLStateFactoryBasePtr
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition: XMLState.h:65
armarx::ScanLocationGroup::CheckLocalizationResult::CheckLocalizationResult
CheckLocalizationResult(const XMLStateConstructorParams &stateData)
Definition: CheckLocalizationResult.h:32
ObjectInstance.h
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
ChannelRef.h