RobotUnitComponentPlugin.cpp
Go to the documentation of this file.
2 
3 #include <thread>
4 
7 
8 namespace armarx::plugins
9 {
11  RobotUnitComponentPlugin::startDataStreaming(const RobotUnitDataStreaming::Config& cfg)
12  {
13  //ok to create smart ptr from parent, since ice handels this
14  return make_shared<RobotUnitDataStreamingReceiver>(&parent(), getRobotUnit(), cfg);
15  }
16 
17  void
19  {
20  if (!_ctrls.empty())
21  {
22  ARMARX_CHECK_NOT_NULL(_robotUnit);
23  std::vector<std::string> cs(_ctrls.begin(), _ctrls.end());
24  _robotUnit->deactivateAndDeleteNJointControllers(cs);
25  }
26  _robotUnit = nullptr;
27  }
28 
29  NJointControllerInterfacePrx
31  const std::string& className,
32  const std::string& instanceName,
33  const armarx::NJointControllerConfigPtr& config,
34  bool doManageController)
35  {
36  ARMARX_CHECK_NOT_NULL(_robotUnit);
38  {
39  out << "creating ";
40  if (doManageController)
41  {
42  out << "and managing ";
43  }
44  out << " controller '" << instanceName << "' of class '" << instanceName << "'";
45  };
46  const auto prx =
47  _robotUnit->createOrReplaceNJointController(className, instanceName, config);
49  if (doManageController)
50  {
51  manageController(instanceName);
52  }
53  return prx;
54  }
55 
56  void
57  RobotUnitComponentPlugin::manageController(const armarx::NJointControllerInterfacePrx& ctrl)
58  {
60  manageController(ctrl->getInstanceName());
61  }
62 
63  void
65  {
66  _ctrls.emplace(ctrl);
67  }
68 
69  void
71  {
72  if (_robotUnitName.empty())
73  {
74  parent<Component>().getProperty(_robotUnitName, PROPERTY_NAME);
75  }
76 
77  if (not _isRobotUnitOptionalDependency)
78  {
79  parent<Component>().usingProxy(_robotUnitName);
80  }
81  }
82 
83  void
85  {
86  if (not _robotUnitName.empty())
87  {
88  parent<Component>().getProxy(_robotUnit, _robotUnitName);
89  }
90  }
91 
92  void
95  {
96  if (!properties->hasDefinition(PROPERTY_NAME))
97  {
98  if (_isRobotUnitOptionalDependency)
99  {
100  properties->defineOptionalProperty<std::string>(
101  PROPERTY_NAME, "", "Name of the RobotUnit");
102  }
103  else
104  {
105  properties->defineRequiredProperty<std::string>(PROPERTY_NAME,
106  "Name of the RobotUnit");
107  }
108  }
109  }
110 
113  {
114  return _robotUnit;
115  }
116 
117  void
119  {
120  ARMARX_CHECK_EMPTY(_robotUnitName);
121  _robotUnitName = name;
122  }
123 
124  const std::string&
126  {
127  return _robotUnitName;
128  }
129 
130  bool
132  {
133  return not _robotUnitName.empty();
134  }
135 
136  void
138  {
139  _isRobotUnitOptionalDependency = isOptional;
140  }
141 
142  void
143  RobotUnitComponentPlugin::waitUntilRobotUnitIsRunning(const std::function<bool()>& termCond)
144  {
145  ARMARX_INFO << "Waiting until robot unit is running ...";
146 
147  if (not hasRobotUnitName())
148  {
149  ARMARX_ERROR << "Could not wait for a robotUnit without a name!";
150  return;
151  }
152 
153  parent<Component>().usingProxy(_robotUnitName);
154  while (not termCond() and not robotUnitIsRunning())
155  {
156  ARMARX_INFO << deactivateSpam() << "Still waiting for robot unit to start...";
157  std::this_thread::sleep_for(std::chrono::milliseconds(100));
158  }
159 
160  ARMARX_INFO << "Robot unit is up and running.";
161  }
162 
163  bool
165  {
166  if (not hasRobotUnitName())
167  {
168  // An empty robotUnit can never run
169  return false;
170  }
171  return not isNullptr(getRobotUnit()) and getRobotUnit()->isRunning();
172  }
173 
174 
175 } // namespace armarx::plugins
176 
177 namespace armarx
178 {
180  {
181  addPlugin(plugin);
182  }
183 
186  {
187  return plugin->getRobotUnit();
188  }
189 
192  {
193  return *plugin;
194  }
195 
196  void
198  const std::function<bool()>& termCond) const
199  {
200  ARMARX_INFO << "Waiting until robot unit is running ...";
201 
202  while ((not termCond()) and
203  ((isNullptr(getRobotUnit()) or (not getRobotUnit()->isRunning()))))
204  {
205  std::this_thread::sleep_for(std::chrono::milliseconds(100));
206  }
207 
208  ARMARX_INFO << "Robot unit is up and running.";
209  }
210 } // namespace armarx
Pointer.h
armarx::isNullptr
bool isNullptr(const T &p)
Definition: Pointer.h:49
armarx::plugins::RobotUnitComponentPlugin::createNJointController
PrxT createNJointController(const std::string &className, const std::string &instanceName, const NJointControllerConfigPtr &config, bool doManageController=true)
Definition: RobotUnitComponentPlugin.h:49
armarx::plugins::RobotUnitComponentPlugin::setRobotUnitName
void setRobotUnitName(const std::string &name)
Definition: RobotUnitComponentPlugin.cpp:118
armarx::plugins::RobotUnitComponentPlugin::postOnDisconnectComponent
void postOnDisconnectComponent() override
Definition: RobotUnitComponentPlugin.cpp:18
armarx::RobotUnitDataStreamingReceiverPtr
std::shared_ptr< class RobotUnitDataStreamingReceiver > RobotUnitDataStreamingReceiverPtr
Definition: RobotUnitReader.h:30
armarx::ManagedIceObjectPlugin::parent
ManagedIceObject & parent()
Definition: ManagedIceObjectPlugin.cpp:69
ARMARX_CHECK_EMPTY
#define ARMARX_CHECK_EMPTY(c)
Definition: ExpressionException.h:218
armarx::plugins::RobotUnitComponentPlugin::getRobotUnitName
const std::string & getRobotUnitName() const
Definition: RobotUnitComponentPlugin.cpp:125
ARMARX_CHECK_NOT_NULL
#define ARMARX_CHECK_NOT_NULL(ptr)
This macro evaluates whether ptr is not null and if it turns out to be false it will throw an Express...
Definition: ExpressionException.h:206
armarx::plugins::RobotUnitComponentPlugin::robotUnitIsRunning
bool robotUnitIsRunning() const
Definition: RobotUnitComponentPlugin.cpp:164
armarx::plugins::RobotUnitComponentPlugin::manageController
void manageController(const NJointControllerInterfacePrx &ctrl)
armarx::ManagedIceObject::addPlugin
PluginT * addPlugin(const std::string prefix="", ParamsT &&...params)
Definition: ManagedIceObject.h:182
armarx::plugins::RobotUnitComponentPlugin::hasRobotUnitName
bool hasRobotUnitName() const
Definition: RobotUnitComponentPlugin.cpp:131
deactivateSpam
SpamFilterDataPtr deactivateSpam(SpamFilterDataPtr const &spamFilter, float deactivationDurationSec, const std::string &identifier, bool deactivate)
Definition: Logging.cpp:72
armarx::plugins
This file is part of ArmarX.
Definition: DebugObserverComponentPlugin.cpp:28
armarx::TaskStatus::isRunning
bool isRunning(Status status)
Returns whether the given task status describes a state where a path is planned.
Definition: PlanningUtil.cpp:67
armarx::RobotUnitComponentPluginUser::RobotUnitComponentPluginUser
RobotUnitComponentPluginUser()
Definition: RobotUnitComponentPlugin.cpp:179
ARMARX_ERROR
#define ARMARX_ERROR
Definition: Logging.h:189
armarx::plugins::RobotUnitComponentPlugin
Definition: RobotUnitComponentPlugin.h:11
armarx::plugins::RobotUnitComponentPlugin::startDataStreaming
RobotUnitDataStreamingReceiverPtr startDataStreaming(const RobotUnitDataStreaming::Config &cfg)
Definition: RobotUnitComponentPlugin.cpp:11
armarx::RobotUnitComponentPluginUser::waitUntilRobotUnitIsRunning
void waitUntilRobotUnitIsRunning(const std::function< bool()> &termCond=[] { return false;}) const
Waits until the robot unit is running.
Definition: RobotUnitComponentPlugin.cpp:197
Component.h
armarx::plugins::RobotUnitComponentPlugin::postCreatePropertyDefinitions
void postCreatePropertyDefinitions(PropertyDefinitionsPtr &properties) override
Definition: RobotUnitComponentPlugin.cpp:93
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
armarx::plugins::RobotUnitComponentPlugin::preOnConnectComponent
void preOnConnectComponent() override
Definition: RobotUnitComponentPlugin.cpp:84
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::plugins::RobotUnitComponentPlugin::preOnInitComponent
void preOnInitComponent() override
Definition: RobotUnitComponentPlugin.cpp:70
armarx::plugins::RobotUnitComponentPlugin::setRobotUnitAsOptionalDependency
void setRobotUnitAsOptionalDependency(bool isOptional=true)
Definition: RobotUnitComponentPlugin.cpp:137
IceInternal::ProxyHandle<::IceProxy::armarx::RobotUnitInterface >
armarx::RobotUnitComponentPluginUser::getRobotUnitComponentPlugin
plugins::RobotUnitComponentPlugin & getRobotUnitComponentPlugin()
Definition: RobotUnitComponentPlugin.cpp:191
armarx::RobotUnitComponentPluginUser::getRobotUnit
RobotUnitInterfacePrx getRobotUnit() const
Definition: RobotUnitComponentPlugin.cpp:185
armarx::plugins::RobotUnitComponentPlugin::waitUntilRobotUnitIsRunning
void waitUntilRobotUnitIsRunning(const std::function< bool()> &termCond=[] { return false;})
Waits until the robot unit is running.
Definition: RobotUnitComponentPlugin.cpp:143
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
RobotUnitComponentPlugin.h
armarx::plugins::RobotUnitComponentPlugin::getRobotUnit
RobotUnitInterfacePrx getRobotUnit() const
Definition: RobotUnitComponentPlugin.cpp:112
ARMARX_STREAM_PRINTER
#define ARMARX_STREAM_PRINTER
use this macro to write output code that is executed when printed and thus not executed if the debug ...
Definition: Logging.h:304