GetObjectPose.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::ObjectLocalization
17 * @author Markus Grotz ( markus dot grotz at kit dot edu )
18 * @date 2016
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22
23#include "GetObjectPose.h"
24
25using namespace armarx;
26using namespace ObjectLocalization;
27
30
32
33// DO NOT EDIT NEXT LINE
34GetObjectPose::SubClassRegistry GetObjectPose::Registry(GetObjectPose::GetName(),
36
37void
39{
40 // TODO: THIS MUST BE ADAPTED TO HANDLE armarx::ObjectID in the instance channel or object name!
41 ChannelRefBasePtr objectInstanceChannel;
42
43 if (in.isObjectInstanceChannelSet() && in.getObjectInstanceChannel())
44 {
45 ARMARX_INFO << "using object instance channel";
46 objectInstanceChannel = in.getObjectInstanceChannel();
47 }
48 else if (in.isObjectNameSet())
49 {
50 std::string objectName = in.getObjectName();
51 if (objectName.find("/") != std::string::npos)
52 {
53 // It's an ObjectID.
54 ObjectID id(objectName);
55 objpose::ObjectPoseSeq objectPoses =
56 objpose::fromIce(getObjectPoseStorage()->getObjectPoses());
57 for (const objpose::ObjectPose& p : objectPoses)
58 {
59 if (p.objectID == id)
60 {
61 ARMARX_IMPORTANT << "Found object in ObjectPoseStorage: " << id;
62 // out.setObjectChannel(nullptr); // Optional
63 // Miss-use instance ID for our ObjectID.
64 FramedPosePtr pose(new FramedPose(p.objectPoseRobot, "root", ""));
65 ARMARX_INFO << "Object pose from ObjectPoseStorage is " << pose->output();
66
67 out.setObjectPose(pose);
68 out.setObjectPosition(
69 new FramedPosition(pose->toEigen(), pose->frame, pose->agent));
70 out.setObjectOrientation(
71 new FramedOrientation(pose->toEigen(), pose->frame, pose->agent));
72
73 // Do not set optional parameter to nullptr (causes NullHandleException)
74 //out.setObjectInstanceChannel(nullptr);
75
76 emitSuccess();
77 return;
78 }
79 }
80
81 ARMARX_WARNING << "Object instance ID '" << objectName
82 << "' looks like an armarx::ObjectID, "
83 << "but no such object was found in ObjectPoseStorage (offering "
84 << objectPoses.size() << " objects).";
85 emitNoPoseAvailable();
86 return;
87 }
88 else
89 {
90 memoryx::ObjectMemoryObserverInterfacePrx objectMemoryObserver =
91 getObjectMemoryObserver();
92 std::vector<ChannelRefBasePtr> objectInstanceList =
93 objectMemoryObserver->getObjectInstancesByClass(objectName);
94
95 ARMARX_INFO << "found " << objectInstanceList.size() << " instances for object "
96 << in.getObjectName();
97 if (objectInstanceList.size())
98 {
99 objectInstanceChannel = objectInstanceList.front();
100 }
101 }
102 }
103
104 if (!objectInstanceChannel)
105 {
106 emitNoPoseAvailable();
107 return;
108 }
109
110 ChannelRefPtr channelRef = ChannelRefPtr::dynamicCast(objectInstanceChannel);
111 if (!channelRef || !channelRef->hasDatafield("pose"))
112 {
113 ARMARX_WARNING << "unable to cast channel reference or datafield pose does not exists.";
114 emitNoPoseAvailable();
115 return;
116 }
117
118 FramedPosePtr pose = channelRef->get<FramedPose>("pose");
119 ARMARX_INFO << "object pose is " << pose->output();
120
121 out.setObjectPose(pose);
122 out.setObjectPosition(new FramedPosition(pose->toEigen(), pose->frame, pose->agent));
123 out.setObjectOrientation(new FramedOrientation(pose->toEigen(), pose->frame, pose->agent));
124 out.setObjectInstanceChannel(channelRef);
125
126 emitSuccess();
127}
128
129//void GetObjectPose::run()
130//{
131// // put your user code for the execution-phase here
132// // runs in seperate thread, thus can do complex operations
133// // should check constantly whether isRunningTaskStopped() returns true
134//
135//// uncomment this if you need a continous run function. Make sure to use sleep or use blocking wait to reduce cpu load.
136// while (!isRunningTaskStopped()) // stop run function if returning true
137// {
138// // do your calculations
139// }
140//}
141
142//void GetObjectPose::onBreak()
143//{
144// // put your user code for the breaking point here
145// // execution time should be short (<100ms)
146//}
147
148void
150{
151 // put your user code for the exit point here
152 // execution time should be short (<100ms)
153}
154
155// DO NOT EDIT NEXT FUNCTION
The FramedOrientation class.
Definition FramedPose.h:216
The FramedPose class.
Definition FramedPose.h:281
The FramedPosition class.
Definition FramedPose.h:158
A known object ID of the form "Dataset/ClassName" or "Dataset/ClassName/InstanceName".
Definition ObjectID.h:11
GetObjectPose(const XMLStateConstructorParams &stateData)
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
#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_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< FramedPose > FramedPosePtr
Definition FramedPose.h:272
An object pose as stored by the ObjectPoseStorage.
Definition ObjectPose.h:34