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 
36 using namespace armarx;
37 using namespace CoupledInteractionGroup;
38 
39 // DO NOT EDIT NEXT LINE
40 LocalizeTable::SubClassRegistry LocalizeTable::Registry(LocalizeTable::GetName(),
42 
44  XMLStateTemplate<LocalizeTable>(stateData), LocalizeTableGeneratedBase<LocalizeTable>(stateData)
45 {
46 }
47 
48 void
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 
83 void
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 
131 float
132 LocalizeTable::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 
140 void
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
149 std::string
151 {
152  return "LocalizeTable";
153 }
154 
155 // DO NOT EDIT NEXT FUNCTION
158 {
159  return XMLStateFactoryBasePtr(new LocalizeTable(stateData));
160 }
armarx::CoupledInteractionGroup::CoupledInteractionGroupStatechartContext::getObjectMemoryObserverProxy
memoryx::ObjectMemoryObserverInterfacePrx getObjectMemoryObserverProxy()
Definition: CoupledInteractionGroupStatechartContext.h:175
RemoteRobot.h
armarx::CoupledInteractionGroup::LocalizeTable::Registry
static SubClassRegistry Registry
Definition: LocalizeTable.h:51
armarx::CoupledInteractionGroup::LocalizeTable::run
void run() override
Definition: LocalizeTable.cpp:84
armarx::CoupledInteractionGroup::LocalizeTable::LocalizeTable
LocalizeTable(XMLStateConstructorParams stateData)
Definition: LocalizeTable.cpp:43
armarx::VariantType::FramedPose
const VariantTypeId FramedPose
Definition: FramedPose.h:36
armarx::TimeUtil::MSSleep
static void MSSleep(int durationMS)
lock the calling thread for a given duration (like usleep(...) but using Timeserver time)
Definition: TimeUtil.cpp:100
armarx::XMLStateConstructorParams
Definition: XMLState.h:49
armarx::XMLStateFactoryBasePtr
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition: XMLState.h:64
armarx::CoupledInteractionGroup::LocalizeTable::CreateInstance
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
Definition: LocalizeTable.cpp:157
IceInternal::Handle< ObjectInstance >
armarx::XMLStateTemplate
Class for legacy to stay compatible with old statecharts.
Definition: XMLState.h:146
armarx::FramedPosition
The FramedPosition class.
Definition: FramedPose.h:157
armarx::FramedOrientation
The FramedOrientation class.
Definition: FramedPose.h:215
ARMARX_LOG
#define ARMARX_LOG
Definition: Logging.h:165
LocalizeTable.h
armarx::CoupledInteractionGroup::LocalizeTable::onEnter
void onEnter() override
Definition: LocalizeTable.cpp:49
armarx::CoupledInteractionGroup::CoupledInteractionGroupStatechartContext::getWorkingMemoryProxy
memoryx::WorkingMemoryInterfacePrx getWorkingMemoryProxy()
Definition: CoupledInteractionGroupStatechartContext.h:169
ObjectInstance.h
armarx::channels::PlatformUnitObserver::platformPose
const PlatformUnitDatafieldCreator platformPose("platformPose")
TimeUtil.h
armarx::CoupledInteractionGroup::LocalizeTable
Definition: LocalizeTable.h:37
armarx::CoupledInteractionGroup::LocalizeTable::onExit
void onExit() override
Definition: LocalizeTable.cpp:141
armarx::CoupledInteractionGroup::CoupledInteractionGroupStatechartContext
Definition: CoupledInteractionGroupStatechartContext.h:118
armarx::CoupledInteractionGroup::CoupledInteractionGroupStatechartContext::getViewSelection
ViewSelectionInterfacePrx getViewSelection()
Definition: CoupledInteractionGroupStatechartContext.h:215
armarx::CoupledInteractionGroup::LocalizeTable::GetName
static std::string GetName()
Definition: LocalizeTable.cpp:150
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27