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
30
33
34#include <MemoryX/interface/components/WorkingMemoryInterface.h>
35#include <MemoryX/interface/observers/ObjectMemoryObserverInterface.h>
37
38
39using namespace armarx;
40using namespace ScanLocationGroup;
41
42// DO NOT EDIT NEXT LINE
43CheckLocalizationResult::SubClassRegistry
44 CheckLocalizationResult::Registry(CheckLocalizationResult::GetName(),
46
47void
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 =
73 objpose::fromIce(getObjectPoseStorage()->getObjectPoses());
74 for (const auto& p : objectPoses)
75 {
76 if (p.objectID == id)
77 {
78 ARMARX_IMPORTANT << "Found object in ObjectPoseStorage: " << id;
79 // out.setObjectChannel(nullptr); // Optional
80 // Miss-use instance ID for our ObjectID.
81 found = true;
82 break;
83 }
84 }
85 if (!found)
86 {
87 ARMARX_WARNING << "Object instance ID '" << objectName
88 << "' looks like an armarx::ObjectID, "
89 << "but no such object was found in ObjectPoseStorage (offering "
90 << objectPoses.size() << " objects)."
91 << "Trying to interpret it as memory instance ID.";
92 }
93 }
94 else
95 {
96 std::vector<ChannelRefBasePtr> objectInstanceList =
97 objectMemoryObserver->getObjectInstancesByClass(objectName);
98
99 for (ChannelRefBasePtr objectInstanceChannel : objectInstanceList)
100 {
101
102 ChannelRefPtr channelRef = ChannelRefPtr::dynamicCast(objectInstanceChannel);
103 if (!channelRef || !channelRef->hasDatafield("pose"))
104 {
105 continue;
106 }
107
108 TimestampVariantPtr localizationTimestamp =
109 channelRef->get<TimestampVariant>("timestamp");
110
111 if (localizationTimestamp->toTime() > startTime->toTime())
112 {
113 found = true;
114 break;
115 }
116 }
117 }
118 if (!found)
119 {
120 all_found = false;
121 emitIncomplete();
122 return;
123 }
124 }
125
126 if (all_found)
127 {
128 emitComplete();
129 }
130 else
131 {
132 emitIncomplete();
133 }
134}
135
136//void CheckLocalizationResult::run()
137//{
138// // put your user code for the execution-phase here
139// // runs in seperate thread, thus can do complex operations
140// // should check constantly whether isRunningTaskStopped() returns true
141//
142//// uncomment this if you need a continous run function. Make sure to use sleep or use blocking wait to reduce cpu load.
143// while (!isRunningTaskStopped()) // stop run function if returning true
144// {
145// // do your calculations
146// }
147//}
148
149//void CheckLocalizationResult::onBreak()
150//{
151// // put your user code for the breaking point here
152// // execution time should be short (<100ms)
153//}
154
155void
157{
158 // put your user code for the exit point here
159 // execution time should be short (<100ms)
160}
161
162// DO NOT EDIT NEXT FUNCTION
A known object ID of the form "Dataset/ClassName" or "Dataset/ClassName/InstanceName".
Definition ObjectID.h:11
CheckLocalizationResult(const XMLStateConstructorParams &stateData)
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
Implements a Variant type for timestamps.
#define ARMARX_IMPORTANT
The logging level for always important information, but expected behaviour (in contrast to ARMARX_WAR...
Definition Logging.h:190
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:193
std::vector< ObjectPose > ObjectPoseSeq
void fromIce(const Box &box, simox::OrientedBox< float > &oobb)
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
IceInternal::Handle< TimestampVariant > TimestampVariantPtr