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
24
25#include <SimoxUtility/algorithm/string/string_tools.h>
26
30
32
33namespace 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();
82 std::string kinUnitName = getProperty<std::string>("KinematicUnitName").getValue();
85 getProxy<KinematicUnitObserverInterfacePrx>(kinematicUnitObserverName);
86
87 ARMARX_INFO << "Fetched proxies " << kinUnitName << ":" << kinematicUnitPrx << ", "
88 << rbStateName << ": " << robotStateComponent << flush;
89
90 if (!headIKUnitName.empty())
91 {
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
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
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition Component.cpp:90
Property< PropertyType > getProperty(const std::string &name)
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
Mimics the behaviour of the VirtualRobot::Robot class while redirecting everything to an Ice proxy.
RobotStateComponentInterfacePrx robotStateComponent
Prx for the RobotState.
KinematicUnitObserverInterfacePrx kinematicUnitObserverPrx
KinematicUnitInterfacePrx kinematicUnitPrx
void onInitStatechartContext() override
onInitStatechartonInitStatechartContext can be implemented by subclasses
HandUnitInterfacePrx getHandUnit(const std::string &handUnitName)
std::map< std::string, HandUnitInterfacePrx > handUnits
PropertyDefinitionsPtr createPropertyDefinitions() override
void onConnectStatechartContext() override
onConnectStatechartContext can be implemented by subclasses
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
const LogSender::manipulator flush
Definition LogSender.h:251