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 
25 #include <SimoxUtility/algorithm/string/string_tools.h>
26 
30 
32 
33 namespace armarx
34 {
35  // ****************************************************************
36  // Implementation of Component
37  // ****************************************************************
38  void
40  {
41  // StatechartContext::onInitStatechart();
42  ARMARX_INFO << "Init RobotStatechartContext" << flush;
43 
44  kinematicUnitObserverName =
45  getProperty<std::string>("KinematicUnitObserverName").getValue();
46 
47  usingProxy(getProperty<std::string>("KinematicUnitName").getValue());
48  usingProxy(getProperty<std::string>("RobotStateComponentName").getValue());
49  usingProxy(kinematicUnitObserverName);
50 
51  if (!getProperty<std::string>("HandUnits").getValue().empty())
52  {
53  std::string handUnitsProp = getProperty<std::string>("HandUnits").getValue();
54  std::vector<std::string> handUnitList = simox::alg::split(handUnitsProp, ",");
55 
56  for (size_t i = 0; i < handUnitList.size(); i++)
57  {
58  simox::alg::trim(handUnitList.at(i));
59  usingProxy(handUnitList.at(i));
60  }
61  }
62 
63  // headIKUnit
64  headIKUnitName = getProperty<std::string>("HeadIKUnitName").getValue();
65  headIKKinematicChainName = getProperty<std::string>("HeadIKKinematicChainName").getValue();
66 
67  if (!headIKUnitName.empty())
68  {
69  usingProxy(headIKUnitName);
70  }
71  }
72 
73  void
75  {
76  // StatechartContext::onConnectStatechart();
77  ARMARX_INFO << "Starting RobotStatechartContext" << flush;
78 
79  // retrieve proxies
80  std::string rbStateName = getProperty<std::string>("RobotStateComponentName").getValue();
81  robotStateComponent = getProxy<RobotStateComponentInterfacePrx>(rbStateName);
82  std::string kinUnitName = getProperty<std::string>("KinematicUnitName").getValue();
83  kinematicUnitPrx = getProxy<KinematicUnitInterfacePrx>(kinUnitName);
85  getProxy<KinematicUnitObserverInterfacePrx>(kinematicUnitObserverName);
86 
87  ARMARX_INFO << "Fetched proxies " << kinUnitName << ":" << kinematicUnitPrx << ", "
88  << rbStateName << ": " << robotStateComponent << flush;
89 
90  if (!headIKUnitName.empty())
91  {
92  headIKUnitPrx = getProxy<HeadIKUnitInterfacePrx>(headIKUnitName);
93  ARMARX_INFO << "Fetched headIK proxy " << headIKUnitName << ":" << headIKUnitPrx
94  << ", head IK kin chain:" << headIKKinematicChainName << flush;
95  }
96 
97 
98  if (!getProperty<std::string>("HandUnits").getValue().empty())
99  {
100  std::string handUnitsProp = getProperty<std::string>("HandUnits").getValue();
101  std::vector<std::string> handUnitList = simox::alg::split(handUnitsProp, ",");
102 
103  for (size_t i = 0; i < handUnitList.size(); i++)
104  {
105  simox::alg::trim(handUnitList.at(i));
106  HandUnitInterfacePrx handPrx = getProxy<HandUnitInterfacePrx>(handUnitList.at(i));
107  handUnits[handUnitList.at(i)] = handPrx;
108  ARMARX_INFO << "Fetched handUnit proxy " << handUnitList.at(i) << ": " << handPrx
109  << flush;
110  }
111  }
112 
113  // initialize remote robot
114  remoteRobot.reset(new RemoteRobot(robotStateComponent->getSynchronizedRobot()));
115  ARMARX_INFO << "Created remote robot" << flush;
116  }
117 
120  {
122  }
123 
124  HandUnitInterfacePrx
125  RobotStatechartContext::getHandUnit(const std::string& handUnitName)
126  {
127  if (handUnits.find(handUnitName) != handUnits.end())
128  {
129  ARMARX_INFO << "Found proxy of hand unit with name " << handUnitName << flush;
130  return handUnits[handUnitName];
131  }
132 
133  ARMARX_INFO << "Do not know proxy of hand unit with name " << handUnitName << flush;
134  std::map<std::string, HandUnitInterfacePrx>::iterator it = handUnits.begin();
135 
136  while (it != handUnits.end())
137  {
138  ARMARX_INFO << "************ Known hand units: " << it->first << ":" << it->second
139  << flush;
140  it++;
141  }
142 
143  return HandUnitInterfacePrx();
144  }
145 
146  /* const VirtualRobot::RobotPtr armarx::Armar4Context::getRobot()
147  {
148  return remoteRobot;
149  }*/
150 
151 } // namespace armarx
armarx::RobotStatechartContext::getHandUnit
HandUnitInterfacePrx getHandUnit(const std::string &handUnitName)
Definition: RobotStatechartContext.cpp:125
armarx::RobotStatechartContext::headIKKinematicChainName
std::string headIKKinematicChainName
Definition: RobotStatechartContext.h:119
RemoteRobot.h
armarx::RobotStatechartContext::kinematicUnitObserverPrx
KinematicUnitObserverInterfacePrx kinematicUnitObserverPrx
Definition: RobotStatechartContext.h:113
armarx::RobotStatechartContext::onConnectStatechartContext
void onConnectStatechartContext() override
onConnectStatechartContext can be implemented by subclasses
Definition: RobotStatechartContext.cpp:74
armarx::RobotStatechartContext::onInitStatechartContext
void onInitStatechartContext() override
onInitStatechartonInitStatechartContext can be implemented by subclasses
Definition: RobotStatechartContext.cpp:39
Statechart.h
cxxopts::empty
bool empty(const std::string &s)
Definition: cxxopts.hpp:234
armarx::RobotStatechartContext::headIKUnitPrx
HeadIKUnitInterfacePrx headIKUnitPrx
Definition: RobotStatechartContext.h:118
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:79
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
Definition: forward_declarations.h:30
armarx::RobotStatechartContext::robotStateComponent
RobotStateComponentInterfacePrx robotStateComponent
Prx for the RobotState.
Definition: RobotStatechartContext.h:111
armarx::RobotStatechartContext::handUnits
std::map< std::string, HandUnitInterfacePrx > handUnits
Definition: RobotStatechartContext.h:116
httplib::detail::trim
std::pair< size_t, size_t > trim(const char *b, const char *e, size_t left, size_t right)
Definition: httplib.h:2787
armarx::RobotStatechartContextProperties
Definition: RobotStatechartContext.h:46
armarx::RobotStatechartContext::remoteRobot
VirtualRobot::RobotPtr remoteRobot
Definition: RobotStatechartContext.h:115
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:35
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:154
armarx::RobotStatechartContext::kinematicUnitPrx
KinematicUnitInterfacePrx kinematicUnitPrx
Definition: RobotStatechartContext.h:112
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::RobotStatechartContext::createPropertyDefinitions
PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: RobotStatechartContext.cpp:119
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:38
ImportExportComponent.h