LocalizeTable.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::LocalizeTableGroup
19 * @author [Author Name] ( [Author Email] )
20 * @date 2014
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24
25#include "LocalizeTable.h"
26#include <VirtualRobot/MathTools.h>
27
29
30#include <RobotAPI/interface/components/ViewSelectionInterface.h>
32
34
35
36using namespace armarx;
37using namespace CoupledInteractionGroup;
38
39// DO NOT EDIT NEXT LINE
40LocalizeTable::SubClassRegistry LocalizeTable::Registry(LocalizeTable::GetName(),
42
44 XMLStateTemplate<LocalizeTable>(stateData), LocalizeTableGeneratedBase<LocalizeTable>(stateData)
45{
46}
47
48void
50{
52 getContext<CoupledInteractionGroupStatechartContext>();
53
54 ARMARX_LOG << "deactivating automatic view selection";
55 ViewSelectionInterfacePrx viewSelection = context->getViewSelection();
56 viewSelection->deactivateAutomaticViewSelection();
57
58 memoryx::WorkingMemoryInterfacePrx workingMemory = context->getWorkingMemoryProxy();
59 memoryx::ObjectInstanceMemorySegmentBasePrx objectInstancesSegment =
60 workingMemory->getObjectInstancesSegment();
61 memoryx::ObjectInstanceList objectInstanceList =
62 objectInstancesSegment->getObjectInstancesByClass(in.getObjectNameTable());
63
64 for (auto& o : objectInstanceList)
65 {
66 memoryx::ObjectInstancePtr objectInstance = memoryx::ObjectInstancePtr::dynamicCast(o);
67
68 // objectInstance->setExistenceCertainty(0.0);
69 // objectInstancesSegment->updateEntity(objectInstance->getId(), objectInstance);
70 // ARMARX_LOG << "setting existance certainty to zero for " << in.getobjectName();
71
72 ARMARX_LOG << "removing entity";
73 objectInstancesSegment->removeEntity(objectInstance->getId());
74 }
75
76 ARMARX_LOG << "requesting object ";
77 memoryx::ObjectMemoryObserverInterfacePrx objectMemoryObserver =
79 objectMemoryObserver->requestObjectClassRepeated(
80 in.getObjectNameTable(), 2000, armarx::DEFAULT_VIEWTARGET_PRIORITY);
81}
82
83void
85{
87 getContext<CoupledInteractionGroupStatechartContext>();
88 memoryx::ObjectMemoryObserverInterfacePrx objectMemoryObserver =
90
91 while (!isRunningTaskStopped())
92 {
93
94 memoryx::ChannelRefBaseSequence objectInstanceList =
95 objectMemoryObserver->getObjectInstancesByClass(in.getObjectNameTable());
96 ARMARX_LOG << "found " << objectInstanceList.size() << " instances for object "
97 << in.getObjectNameTable();
98
99 for (auto& o : objectInstanceList)
100 {
101 ChannelRefPtr channelRef = ChannelRefPtr::dynamicCast(o);
102
103 FramedPositionPtr position = channelRef->get<FramedPosition>("position");
104 FramedOrientationPtr orientation = channelRef->get<FramedOrientation>("orientation");
105
106 ARMARX_LOG << "pos " << *position;
107 ARMARX_LOG << "orientation " << *orientation;
108 FramedPosePtr tablePose =
109 new FramedPose(position, orientation, position->frame, position->agent);
110 Eigen::Vector3f platformPose;
111 // Eigen::Matrix3f platformOrientation = orientation->toEigen();
112 platformPose(0) = position->x;
113 platformPose(1) = position->y;
114 platformPose(2) = getYawAngle(tablePose);
115 // ARMARX_INFO << "Pose vec: " << platformPose;
116 // float anglex = acos(std::min(std::max(platformOrientation(0,1),-1.0f),1.0f));
117 // if (anglex < M_PI_2)
118 // platformPose(2) = -platformPose(2);
119 out.setTablePoseBase(tablePose);
120 ARMARX_LOG << "Before emitting Event ";
121 emitEvTableLocalized();
122 break;
123 ARMARX_LOG << "After emitting Event ";
124 }
125
126 ARMARX_LOG << "Before sleep ";
127 TimeUtil::MSSleep(1000);
128 }
129}
130
131float
132LocalizeTable::getYawAngle(const armarx::PoseBasePtr& pose) const
133{
134 Eigen::Vector3f rpy;
135 armarx::PosePtr p = armarx::PosePtr::dynamicCast(pose);
136 VirtualRobot::MathTools::eigen4f2rpy(p->toEigen(), rpy);
137 return rpy[2];
138}
139
140void
142{
143
144 // put your user code for the exit point here
145 // execution time should be short (<100ms)
146}
147
148// DO NOT EDIT NEXT FUNCTION
149std::string
151{
152 return "LocalizeTable";
153}
154
155// DO NOT EDIT NEXT FUNCTION
LocalizeTable(XMLStateConstructorParams stateData)
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
The FramedOrientation class.
Definition FramedPose.h:216
The FramedPose class.
Definition FramedPose.h:281
The FramedPosition class.
Definition FramedPose.h:158
static void MSSleep(int durationMS)
lock the calling thread for a given duration (like usleep(...) but using Timeserver time)
Definition TimeUtil.cpp:100
Class for legacy to stay compatible with old statecharts.
Definition XMLState.h:147
#define ARMARX_LOG
Definition Logging.h:165
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< Pose > PosePtr
Definition Pose.h:306
IceInternal::Handle< ChannelRef > ChannelRefPtr
Definition ChannelRef.h:40
IceInternal::Handle< FramedPosition > FramedPositionPtr
Definition FramedPose.h:149
IceInternal::Handle< FramedOrientation > FramedOrientationPtr
Definition FramedPose.h:207
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition XMLState.h:64
IceInternal::Handle< FramedPose > FramedPosePtr
Definition FramedPose.h:272
IceInternal::Handle< ObjectInstance > ObjectInstancePtr