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"
27 
28 #include <RobotAPI/interface/components/ViewSelectionInterface.h>
29 
31 
33 
34 
35 using namespace armarx;
36 using namespace CoupledInteractionGroup;
37 
38 // DO NOT EDIT NEXT LINE
40 
41 
42 
44  XMLStateTemplate < LocalizeTable > (stateData), LocalizeTableGeneratedBase < LocalizeTable > (stateData)
45 {
46 }
47 
49 {
50  CoupledInteractionGroupStatechartContext* context = getContext<CoupledInteractionGroupStatechartContext>();
51 
52  ARMARX_LOG << "deactivating automatic view selection";
53  ViewSelectionInterfacePrx viewSelection = context->getViewSelection();
54  viewSelection->deactivateAutomaticViewSelection();
55 
56  memoryx::WorkingMemoryInterfacePrx workingMemory = context->getWorkingMemoryProxy();
57  memoryx::ObjectInstanceMemorySegmentBasePrx objectInstancesSegment = workingMemory->getObjectInstancesSegment();
58  memoryx::ObjectInstanceList objectInstanceList = objectInstancesSegment->getObjectInstancesByClass(in.getObjectNameTable());
59 
60  for (auto& o : objectInstanceList)
61  {
62  memoryx::ObjectInstancePtr objectInstance = memoryx::ObjectInstancePtr::dynamicCast(o);
63 
64  // objectInstance->setExistenceCertainty(0.0);
65  // objectInstancesSegment->updateEntity(objectInstance->getId(), objectInstance);
66  // ARMARX_LOG << "setting existance certainty to zero for " << in.getobjectName();
67 
68  ARMARX_LOG << "removing entity";
69  objectInstancesSegment->removeEntity(objectInstance->getId());
70  }
71 
72  ARMARX_LOG << "requesting object ";
73  memoryx::ObjectMemoryObserverInterfacePrx objectMemoryObserver = context->getObjectMemoryObserverProxy();
74  objectMemoryObserver->requestObjectClassRepeated(in.getObjectNameTable(), 2000, armarx::DEFAULT_VIEWTARGET_PRIORITY);
75 }
76 
78 {
79  CoupledInteractionGroupStatechartContext* context = getContext< CoupledInteractionGroupStatechartContext>();
80  memoryx::ObjectMemoryObserverInterfacePrx objectMemoryObserver = context->getObjectMemoryObserverProxy();
81 
82  while (!isRunningTaskStopped())
83  {
84 
85  memoryx::ChannelRefBaseSequence objectInstanceList = objectMemoryObserver->getObjectInstancesByClass(in.getObjectNameTable());
86  ARMARX_LOG << "found " << objectInstanceList.size() << " instances for object " << in.getObjectNameTable();
87 
88  for (auto& o : objectInstanceList)
89  {
90  ChannelRefPtr channelRef = ChannelRefPtr::dynamicCast(o);
91 
92  FramedPositionPtr position = channelRef->get<FramedPosition>("position");
93  FramedOrientationPtr orientation = channelRef->get<FramedOrientation>("orientation");
94 
95  ARMARX_LOG << "pos " << *position;
96  ARMARX_LOG << "orientation " << *orientation;
97  FramedPosePtr tablePose = new FramedPose(position, orientation, position->frame, position->agent);
98  Eigen::Vector3f platformPose;
99  // Eigen::Matrix3f platformOrientation = orientation->toEigen();
100  platformPose(0) = position->x;
101  platformPose(1) = position->y;
102  platformPose(2) = getYawAngle(tablePose);
103  // ARMARX_INFO << "Pose vec: " << platformPose;
104  // float anglex = acos(std::min(std::max(platformOrientation(0,1),-1.0f),1.0f));
105  // if (anglex < M_PI_2)
106  // platformPose(2) = -platformPose(2);
107  out.setTablePoseBase(tablePose);
108  ARMARX_LOG << "Before emitting Event ";
109  emitEvTableLocalized();
110  break;
111  ARMARX_LOG << "After emitting Event ";
112  }
113 
114  ARMARX_LOG << "Before sleep ";
115  TimeUtil::MSSleep(1000);
116  }
117 
118 
119 }
120 
121 
122 float LocalizeTable::getYawAngle(const armarx::PoseBasePtr& pose) const
123 {
124  Eigen::Vector3f rpy;
125  armarx::PosePtr p = armarx::PosePtr::dynamicCast(pose);
126  VirtualRobot::MathTools::eigen4f2rpy(p->toEigen(), rpy);
127  return rpy[2];
128 }
129 
131 {
132 
133  // put your user code for the exit point here
134  // execution time should be short (<100ms)
135 
136 }
137 
138 // DO NOT EDIT NEXT FUNCTION
140 {
141  return "LocalizeTable";
142 }
143 
144 // DO NOT EDIT NEXT FUNCTION
146 {
147  return XMLStateFactoryBasePtr(new LocalizeTable(stateData));
148 }
149 
armarx::CoupledInteractionGroup::CoupledInteractionGroupStatechartContext::getObjectMemoryObserverProxy
memoryx::ObjectMemoryObserverInterfacePrx getObjectMemoryObserverProxy()
Definition: CoupledInteractionGroupStatechartContext.h:129
RemoteRobot.h
armarx::CoupledInteractionGroup::LocalizeTable::Registry
static SubClassRegistry Registry
Definition: LocalizeTable.h:49
armarx::CoupledInteractionGroup::LocalizeTable::run
void run() override
Definition: LocalizeTable.cpp:77
armarx::CoupledInteractionGroup::LocalizeTable::LocalizeTable
LocalizeTable(XMLStateConstructorParams stateData)
Definition: LocalizeTable.cpp:43
armarx::VariantType::FramedPose
const VariantTypeId FramedPose
Definition: FramedPose.h:37
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:94
armarx::XMLStateConstructorParams
Definition: XMLState.h:50
armarx::CoupledInteractionGroup::LocalizeTable::CreateInstance
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
Definition: LocalizeTable.cpp:145
IceInternal::Handle< ObjectInstance >
armarx::XMLStateTemplate
Class for legacy to stay compatible with old statecharts.
Definition: XMLState.h:137
armarx::FramedPosition
The FramedPosition class.
Definition: FramedPose.h:142
armarx::FramedOrientation
The FramedOrientation class.
Definition: FramedPose.h:199
ARMARX_LOG
#define ARMARX_LOG
Definition: Logging.h:163
LocalizeTable.h
armarx::CoupledInteractionGroup::LocalizeTable::onEnter
void onEnter() override
Definition: LocalizeTable.cpp:48
armarx::XMLStateFactoryBasePtr
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition: XMLState.h:65
armarx::CoupledInteractionGroup::CoupledInteractionGroupStatechartContext::getWorkingMemoryProxy
memoryx::WorkingMemoryInterfacePrx getWorkingMemoryProxy()
Definition: CoupledInteractionGroupStatechartContext.h:125
ObjectInstance.h
armarx::channels::PlatformUnitObserver::platformPose
const PlatformUnitDatafieldCreator platformPose("platformPose")
TimeUtil.h
armarx::CoupledInteractionGroup::LocalizeTable
Definition: LocalizeTable.h:34
armarx::CoupledInteractionGroup::LocalizeTable::onExit
void onExit() override
Definition: LocalizeTable.cpp:130
armarx::CoupledInteractionGroup::CoupledInteractionGroupStatechartContext
Definition: CoupledInteractionGroupStatechartContext.h:88
armarx::CoupledInteractionGroup::CoupledInteractionGroupStatechartContext::getViewSelection
ViewSelectionInterfacePrx getViewSelection()
Definition: CoupledInteractionGroupStatechartContext.h:157
armarx::CoupledInteractionGroup::LocalizeTable::GetName
static std::string GetName()
Definition: LocalizeTable.cpp:139
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28