RobotStatechartContext.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 Armar4::api
17 * @author Nikolaus Vahrenkamp
18 * @date 2012 Nikolaus Vahrenkamp
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22 
23 #include "RobotStatechartContext.h"
24 
26 
30 
31 #include <SimoxUtility/algorithm/string/string_tools.h>
32 
33 namespace armarx
34 {
35  // ****************************************************************
36  // Implementation of Component
37  // ****************************************************************
39  {
40  // StatechartContext::onInitStatechart();
41  ARMARX_INFO << "Init RobotStatechartContext" << flush;
42 
43  kinematicUnitObserverName = getProperty<std::string>("KinematicUnitObserverName").getValue();
44 
45  usingProxy(getProperty<std::string>("KinematicUnitName").getValue());
46  usingProxy(getProperty<std::string>("RobotStateComponentName").getValue());
47  usingProxy(kinematicUnitObserverName);
48 
49  if (!getProperty<std::string>("HandUnits").getValue().empty())
50  {
51  std::string handUnitsProp = getProperty<std::string>("HandUnits").getValue();
52  std::vector<std::string> handUnitList = simox::alg::split(handUnitsProp, ",");
53 
54  for (size_t i = 0; i < handUnitList.size(); i++)
55  {
56  simox::alg::trim(handUnitList.at(i));
57  usingProxy(handUnitList.at(i));
58  }
59  }
60 
61  // headIKUnit
62  headIKUnitName = getProperty<std::string>("HeadIKUnitName").getValue();
63  headIKKinematicChainName = getProperty<std::string>("HeadIKKinematicChainName").getValue();
64 
65  if (!headIKUnitName.empty())
66  {
67  usingProxy(headIKUnitName);
68  }
69  }
70 
71 
73  {
74  // StatechartContext::onConnectStatechart();
75  ARMARX_INFO << "Starting RobotStatechartContext" << flush;
76 
77  // retrieve proxies
78  std::string rbStateName = getProperty<std::string>("RobotStateComponentName").getValue();
79  robotStateComponent = getProxy<RobotStateComponentInterfacePrx>(rbStateName);
80  std::string kinUnitName = getProperty<std::string>("KinematicUnitName").getValue();
81  kinematicUnitPrx = getProxy<KinematicUnitInterfacePrx>(kinUnitName);
82  kinematicUnitObserverPrx = getProxy<KinematicUnitObserverInterfacePrx>(kinematicUnitObserverName);
83 
84  ARMARX_INFO << "Fetched proxies " << kinUnitName << ":" << kinematicUnitPrx << ", " << rbStateName << ": " << robotStateComponent << flush;
85 
86  if (!headIKUnitName.empty())
87  {
88  headIKUnitPrx = getProxy<HeadIKUnitInterfacePrx>(headIKUnitName);
89  ARMARX_INFO << "Fetched headIK proxy " << headIKUnitName << ":" << headIKUnitPrx << ", head IK kin chain:" << headIKKinematicChainName << flush;
90  }
91 
92 
93  if (!getProperty<std::string>("HandUnits").getValue().empty())
94  {
95  std::string handUnitsProp = getProperty<std::string>("HandUnits").getValue();
96  std::vector<std::string> handUnitList = simox::alg::split(handUnitsProp, ",");
97 
98  for (size_t i = 0; i < handUnitList.size(); i++)
99  {
100  simox::alg::trim(handUnitList.at(i));
101  HandUnitInterfacePrx handPrx = getProxy<HandUnitInterfacePrx>(handUnitList.at(i));
102  handUnits[handUnitList.at(i)] = handPrx;
103  ARMARX_INFO << "Fetched handUnit proxy " << handUnitList.at(i) << ": " << handPrx << flush;
104  }
105  }
106 
107  // initialize remote robot
108  remoteRobot.reset(new RemoteRobot(robotStateComponent->getSynchronizedRobot()));
109  ARMARX_INFO << "Created remote robot" << flush;
110  }
111 
113  {
116  }
117 
118  HandUnitInterfacePrx RobotStatechartContext::getHandUnit(const std::string& handUnitName)
119  {
120  if (handUnits.find(handUnitName) != handUnits.end())
121  {
122  ARMARX_INFO << "Found proxy of hand unit with name " << handUnitName << flush;
123  return handUnits[handUnitName];
124  }
125 
126  ARMARX_INFO << "Do not know proxy of hand unit with name " << handUnitName << flush;
127  std::map<std::string, HandUnitInterfacePrx>::iterator it = handUnits.begin();
128 
129  while (it != handUnits.end())
130  {
131  ARMARX_INFO << "************ Known hand units: " << it->first << ":" << it->second << flush;
132  it++;
133  }
134 
135  return HandUnitInterfacePrx();
136  }
137 
138  /* const VirtualRobot::RobotPtr armarx::Armar4Context::getRobot()
139  {
140  return remoteRobot;
141  }*/
142 
143 }
144 
armarx::RobotStatechartContext::getHandUnit
HandUnitInterfacePrx getHandUnit(const std::string &handUnitName)
Definition: RobotStatechartContext.cpp:118
armarx::RobotStatechartContext::headIKKinematicChainName
std::string headIKKinematicChainName
Definition: RobotStatechartContext.h:104
RemoteRobot.h
armarx::RobotStatechartContext::kinematicUnitObserverPrx
KinematicUnitObserverInterfacePrx kinematicUnitObserverPrx
Definition: RobotStatechartContext.h:98
armarx::RobotStatechartContext::onConnectStatechartContext
void onConnectStatechartContext() override
onConnectStatechartContext can be implemented by subclasses
Definition: RobotStatechartContext.cpp:72
armarx::RobotStatechartContext::onInitStatechartContext
void onInitStatechartContext() override
onInitStatechartonInitStatechartContext can be implemented by subclasses
Definition: RobotStatechartContext.cpp:38
Statechart.h
cxxopts::empty
bool empty(const std::string &s)
Definition: cxxopts.hpp:255
armarx::RobotStatechartContext::headIKUnitPrx
HeadIKUnitInterfacePrx headIKUnitPrx
Definition: RobotStatechartContext.h:103
armarx::flush
const LogSender::manipulator flush
Definition: LogSender.h:251
Component.h
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:74
armarx::RemoteRobot
Mimics the behaviour of the VirtualRobot::Robot class while redirecting everything to an Ice proxy.
Definition: RemoteRobot.h:139
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::RobotStatechartContext::robotStateComponent
RobotStateComponentInterfacePrx robotStateComponent
Prx for the RobotState.
Definition: RobotStatechartContext.h:96
armarx::RobotStatechartContext::handUnits
std::map< std::string, HandUnitInterfacePrx > handUnits
Definition: RobotStatechartContext.h:101
armarx::RobotStatechartContextProperties
Definition: RobotStatechartContext.h:46
armarx::RobotStatechartContext::remoteRobot
VirtualRobot::RobotPtr remoteRobot
Definition: RobotStatechartContext.h:100
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:34
armarx::ManagedIceObject::usingProxy
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
Definition: ManagedIceObject.cpp:151
armarx::RobotStatechartContext::kinematicUnitPrx
KinematicUnitInterfacePrx kinematicUnitPrx
Definition: RobotStatechartContext.h:97
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::RobotStatechartContext::createPropertyDefinitions
PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: RobotStatechartContext.cpp:112
RobotStatechartContext.h
armarx::split
std::vector< std::string > split(const std::string &source, const std::string &splitBy, bool trimElements=false, bool removeEmptyElements=false)
Definition: StringHelpers.cpp:36
ImportExportComponent.h