CoupledInteractionGroupStatechartContext.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::CoupledInteractionGroup
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 
26 
27 //#include <RobotAPI/libraries/core/remoterobot/RemoteRobot.h>
28 //#include <RobotAPI/libraries/core/Pose.h>
29 
33 
34 #define DEFAULT_SETTINGS_AGENT_INSTANCES_SEGMENT_NAME "agentInstances"
35 
36 using namespace memoryx;
37 
39 {
40  void
41  CoupledInteractionGroupStatechartContext::onInitStatechartContext()
42  {
43  // Register dependencies
44  // usingProxy(getProperty<std::string>("KinematicUnitName").getValue());
45  // usingProxy(getProperty<std::string>("KinematicUnitObserverName").getValue());
46  // usingProxy(getProperty<std::string>("RobotStateComponentName").getValue());
47  // usingProxy(getProperty<std::string>("TCPControlUnitName").getValue());
48  usingProxy(getProperty<std::string>("KinematicUnitName").getValue());
49  usingProxy(getProperty<std::string>("KinematicUnitObserverName").getValue());
50  usingProxy(getProperty<std::string>("RobotStateComponentName").getValue());
51  usingProxy(getProperty<std::string>("TCPControlUnitName").getValue());
52  usingProxy(getProperty<std::string>("TCPControlUnitObserverName").getValue());
53  usingProxy(getProperty<std::string>("WorkingMemoryName").getValue());
54  usingProxy(getProperty<std::string>("ObjectMemoryObserverName").getValue());
55  usingProxy(getProperty<std::string>("PriorKnowledgeName").getValue());
56  usingProxy(getProperty<std::string>("ViewSelectionName").getValue());
57  usingProxy(getProperty<std::string>("ForceTorqueObserverName").getValue());
58  platformUnitObserverName = getProperty<std::string>("PlatformUnitObserverName").getValue();
59  platformUnitName = getProperty<std::string>("PlatformUnitName").getValue();
60  ARMARX_INFO << "Using platform unit:" << platformUnitName
61  << ", platform observer:" << platformUnitObserverName;
62 
63  usingProxy(platformUnitName);
64  usingProxy(platformUnitObserverName);
65 
66  offeringTopic("DebugDrawerUpdates");
67  }
68 
69  void
70  CoupledInteractionGroupStatechartContext::onConnectStatechartContext()
71  {
72 
73  // retrieve proxies
74  // robotStateComponent = getProxy<RobotStateComponentInterfacePrx>(getProperty<std::string>("RobotStateComponentName").getValue());
75  // kinematicUnitPrx = getProxy<KinematicUnitInterfacePrx>(getProperty<std::string>("KinematicUnitName").getValue());
76  // kinematicUnitObserverPrx = getProxy<KinematicUnitObserverInterfacePrx>(getProperty<std::string>("KinematicUnitObserverName").getValue());
77  // tcpControlPrx = getProxy<TCPControlUnitInterfacePrx>(getProperty<std::string>("TCPControlUnitName").getValue());
78 
79  // // initialize remote robot
80  // remoteRobot.reset(new RemoteRobot(robotStateComponent->getSynchronizedRobot()));
81  // retrieve proxies
82  robotStateComponent = getProxy<RobotStateComponentInterfacePrx>(
83  getProperty<std::string>("RobotStateComponentName").getValue());
84  kinematicUnitPrx = getProxy<KinematicUnitInterfacePrx>(
85  getProperty<std::string>("KinematicUnitName").getValue());
86  kinematicUnitObserverPrx = getProxy<KinematicUnitObserverInterfacePrx>(
87  getProperty<std::string>("KinematicUnitObserverName").getValue());
88  tcpControlPrx = getProxy<TCPControlUnitInterfacePrx>(
89  getProperty<std::string>("TCPControlUnitName").getValue());
90  tcpControlUnitObserverPrx = getProxy<TCPControlUnitObserverInterfacePrx>(
91  getProperty<std::string>("TCPControlUnitObserverName").getValue());
92  workingMemoryProxy = getProxy<memoryx::WorkingMemoryInterfacePrx>(
93  getProperty<std::string>("WorkingMemoryName").getValue());
94  objectMemoryObserverProxy = getProxy<memoryx::ObjectMemoryObserverInterfacePrx>(
95  getProperty<std::string>("ObjectMemoryObserverName").getValue());
96  priorKnowledgeProxy = getProxy<memoryx::PriorKnowledgeInterfacePrx>(
97  getProperty<std::string>("PriorKnowledgeName").getValue());
98 
99  // retrieve proxies
100  platformUnitPrx = getProxy<PlatformUnitInterfacePrx>(platformUnitName);
101  platformUnitObserverPrx =
102  getProxy<PlatformUnitObserverInterfacePrx>(platformUnitObserverName);
103  viewSelectionProxy = getProxy<ViewSelectionInterfacePrx>(
104  getProperty<std::string>("ViewSelectionName").getValue());
105  ftUnitObserverPrx = getProxy<ForceTorqueUnitObserverInterfacePrx>(
106  getProperty<std::string>("ForceTorqueObserverName").getValue());
107 
108  // initialize remote robot
109  remoteRobot.reset(new RemoteRobot(robotStateComponent->getSynchronizedRobot()));
110 
111  debugDrawerTopicProxy = getTopic<armarx::DebugDrawerInterfacePrx>("DebugDrawerUpdates");
112  /*if (this->getIceManager()->isObjectReachable("Simulator"))
113  {
114  simulatorPrx = getProxy<SimulatorInterfacePrx>("Simulator");
115  }
116  else
117  {
118  simulatorPrx = NULL;
119  }*/
120 
121 
122  AgentInstancesSegmentBasePrx agentInstancesProxy =
123  AgentInstancesSegmentBasePrx::uncheckedCast(
124  workingMemoryProxy->getSegment(DEFAULT_SETTINGS_AGENT_INSTANCES_SEGMENT_NAME));
125 
126  if (agentInstancesProxy)
127  {
128  agent = AgentInstancePtr::dynamicCast(
129  agentInstancesProxy->getAgentInstanceByName("Armar3"));
130  }
131  else
132  {
133  agent = nullptr;
134  }
135  }
136 
138  CoupledInteractionGroupStatechartContext::getRobotPose()
139  {
141 
142  if (!agent)
143  {
144  ARMARX_ERROR << deactivateSpam() << "no agent with name Armar3";
145  }
146  else
147  {
148 
149  FramedPositionPtr agentPosition = agent->getPosition();
150 
151  if (agentPosition)
152  {
153  robotPose.block<3,1>(0, 3) = agentPosition->toEigen();
154  }
155 
156  FramedOrientationPtr agentOrientation = agent->getOrientation();
157 
158  if (agentOrientation)
159  {
160  robotPose.block<3, 3>(0, 0) = agentOrientation->toEigen();
161  }
162  }
163 
164  return robotPose;
165  }
166 
168  CoupledInteractionGroupStatechartContext::createPropertyDefinitions()
169  {
170  return PropertyDefinitionsPtr(
171  new CoupledInteractionGroupStatechartContextProperties(getConfigIdentifier()));
172  }
173 } // namespace armarx::CoupledInteractionGroup
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:650
memoryx
VirtualRobot headers.
Definition: CommonPlacesTester.cpp:48
CoupledInteractionGroupStatechartContext.h
Statechart.h
IceInternal::Handle< FramedPosition >
deactivateSpam
SpamFilterDataPtr deactivateSpam(SpamFilterDataPtr const &spamFilter, float deactivationDurationSec, const std::string &identifier, bool deactivate)
Definition: Logging.cpp:75
GfxTL::Identity
void Identity(MatrixXX< N, N, T > *a)
Definition: MatrixXX.h:570
DEFAULT_SETTINGS_AGENT_INSTANCES_SEGMENT_NAME
#define DEFAULT_SETTINGS_AGENT_INSTANCES_SEGMENT_NAME
Definition: CoupledInteractionGroupStatechartContext.cpp:34
armarx::CoupledInteractionGroup::CoupledInteractionGroupStatechartContextProperties
Definition: CoupledInteractionGroupStatechartContext.h:60
ARMARX_ERROR
#define ARMARX_ERROR
Definition: Logging.h:196
Component.h
armarx::RemoteRobot
Mimics the behaviour of the VirtualRobot::Robot class while redirecting everything to an Ice proxy.
Definition: RemoteRobot.h:144
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:181
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::CoupledInteractionGroup
Definition: CalculateApproachTablePose.h:35
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:35
ImportExportComponent.h