RobotUnitModuleBase.h
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 RobotAPI::ArmarXObjects::RobotUnit
17  * @author Raphael Grimm ( raphael dot grimm at kit dot edu )
18  * @date 2018
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 #pragma once
24 
25 #include <atomic>
26 #include <chrono>
27 #include <mutex>
28 
29 #include <boost/current_function.hpp>
30 #include <boost/preprocessor/seq/for_each.hpp>
31 #include <boost/preprocessor/variadic/to_seq.hpp>
32 
33 #include <VirtualRobot/Robot.h>
34 
37 
38 #include <RobotAPI/interface/units/RobotUnit/RobotUnitInterface.h>
39 
40 #include "../JointControllers/JointController.h"
41 #include "../util.h"
42 #include "../util/JointAndNJointControllers.h"
43 
44 /**
45  * @defgroup Library-RobotUnit-Modules RobotUnitModules
46  * @ingroup Library-RobotUnit
47  */
48 
49 namespace armarx
50 {
51  TYPEDEF_PTRS_HANDLE(RobotUnit);
52  TYPEDEF_PTRS_HANDLE(NJointControllerBase);
53 
54  template <class Targ, class Src>
55  Targ&
57  {
58  Targ* ptr = dynamic_cast<Targ*>(src);
59  if (!ptr)
60  {
61  if (!src)
62  {
63  throw std::invalid_argument{"Ptr passed to CheckedCastAndDeref is NULL"};
64  }
65  throw std::invalid_argument{
66  "Ptr of type '" + GetTypeString<Src>() +
67  "' passed to CheckedCastAndDeref is is not related to target type '" +
68  GetTypeString<Targ>()};
69  }
70  return *ptr;
71  }
72 
73  /// @brief The current state of the multi step initialization of a RobotUnit
74  enum class RobotUnitState : std::size_t
75  {
78  //ok to use devices/create controllers
81  Running,
82  Exiting
83  };
84 
85  std::string to_string(armarx::RobotUnitState s);
86 
87  inline std::ostream&
88  operator<<(std::ostream& o, RobotUnitState s)
89  {
90  return o << to_string(s);
91  }
92 } // namespace armarx
93 
95 {
97  {
98  public:
100  {
101  }
102  };
103 } // namespace armarx::RobotUnitModule::detail
104 
105 namespace armarx::RobotUnitModule
106 {
109  {
110  public:
112  {
113  setDescription(prefix + " properties");
114  setPrefix(prefix + ".");
115  }
116  };
117 
118 #define forward_declare(r, data, Mod) TYPEDEF_PTRS_HANDLE(Mod);
119  BOOST_PP_SEQ_FOR_EACH(forward_declare, , BOOST_PP_VARIADIC_TO_SEQ(RobotUnitModules))
120 #undef forward_declare
121 
122  /**
123  * @ingroup Library-RobotUnit-Modules
124  * @brief Base class for all RobotUnitModules
125  *
126  * Since the robot unit is a complex class, it is split into several modules.
127  * One reason behind this is stopping developers from accidently using datastructures in the wrong way (e.g. causing racing conditions)
128  * For a \ref RobotUnit to work, ALL modules are required (A class has to derive all of them)
129  *
130  * \section Modules
131  * The list of Modules is:
132  * - \ref ControllerManagement
133  * - \ref ControlThread
134  * - \ref ControlThreadDataBuffer
135  * - \ref Devices
136  * - \ref Logging
137  * - \ref Management
138  * - \ref Publisher
139  * - \ref RobotData
140  * - \ref SelfCollisionChecker
141  * - \ref Units
142  *
143  * \section LifeCycle Life cycle
144  * The RobotUnit has multiple Phases (see \ref RobotUnitState) as well as the life cycle of a \ref ManagedIceObject.
145  *
146  * \subsection LifeCycleMIO ManagedIceObject Life cycle
147  * The hooks (\ref onInitComponent, \ref onConnectComponent, \ref onDisconnectComponent, \ref onExitComponent)
148  * for state transitions provided by \ref ManagedIceObject have a final overrider.
149  * Deriving classes have to use the replacement hooks:
150  *
151  <table>
152  <tr><th> Hook <th> Replacement \th
153  <tr><td> \ref onInitComponent <td> \ref onInitRobotUnit
154  <tr><td> \ref onConnectComponent <td> \ref onConnectRobotUnit
155  <tr><td> \ref onDisconnectComponent <td> \ref onDisconnectRobotUnit
156  <tr><td> \ref onExitComponent <td> \ref onExitRobotUnit
157  </table>
158 
159  * \subsection LifeCycleRU RobotUnit Life cycle
160  *
161  * The initial phase is \ref RobotUnitState::InitializingComponent.
162  * The following table shows all Phase transitions and the functions causing it:
163  *
164  <table>
165  <tr><th> From <th> To <th> Transition function <th> Note \th
166  <tr><td> \ref RobotUnitState::InitializingComponent <td> \ref RobotUnitState::InitializingDevices <td> \ref finishComponentInitialization <td> Called in \ref onInitComponent
167  <tr><td> \ref RobotUnitState::InitializingDevices <td> \ref RobotUnitState::InitializingUnits <td> \ref finishDeviceInitialization <td>
168  <tr><td> \ref RobotUnitState::InitializingUnits <td> \ref RobotUnitState::InitializingControlThread <td> \ref finishUnitInitialization <td>
169  <tr><td> \ref RobotUnitState::InitializingControlThread <td> \ref RobotUnitState::Running <td> \ref finishControlThreadInitialization <td> Has to be called in the control thread
170  <tr><td> \ref RobotUnitState::Running <td> \ref RobotUnitState::Exiting <td> \ref finishRunning <td> Called in \ref onExitComponent
171  </table>
172  *
173  *
174  *
175  * \subsection RUMLifeCycleHooks RobotUnitModule Hooks for Life Cycle transition functions
176  *
177  * Each RobotUnitModule has two hooks each transition function ().
178  * - The '_pre<TRANSITION_FUNCTION_NAME>' hook is called in the transition function before the state has changed.
179  * - The '_post<TRANSITION_FUNCTION_NAME>' hook is called in the transition function after the state has changed.
180  *
181  * \warning The same hook of different modules (e.g.: \ref _preFinishDeviceInitialization, \ref _postOnInitRobotUnit) must not depend on each other.
182  */
183  class ModuleBase : virtual public Component
184  {
185  /// @brief The singleton instance
186  static std::atomic<ModuleBase*> Instance_;
187 
188  public:
189  /**
190  * @brief Returns the singleton instance of this class
191  * @return The singleton instance of this class
192  */
193  static ModuleBase&
195  {
196  ARMARX_CHECK_NOT_NULL(Instance_);
197  return *Instance_;
198  }
199 
200  /**
201  * @brief Returns the singleton instance of the given class
202  * @return The singleton instance of the given class
203  */
204  template <class T>
205  static T&
207  {
209  "The type has to derive ModuleBase");
210  ARMARX_CHECK_NOT_NULL(Instance_);
211  return dynamic_cast<T&>(*Instance_);
212  }
213 
214  protected:
215  /// @brief Ctor
216  ModuleBase();
217  // //////////////////////////////////////////////////////////////////////////////////////// //
218  // //////////////////////////////////////// types ///////////////////////////////////////// //
219  // //////////////////////////////////////////////////////////////////////////////////////// //
220  protected:
221  /**
222  * @brief The type of recursive_mutex used in this class.
223  * This typedef is used to quickly replace the mutex type with a logging mutex type for debugging.
224  */
225  using MutexType = std::recursive_timed_mutex;
226  using GuardType = std::unique_lock<MutexType>;
227  using ClockType = std::chrono::high_resolution_clock;
228  using TimePointType = std::chrono::high_resolution_clock::time_point;
229 
230 #define using_module_types(...) using_module_types_impl(__VA_ARGS__)
231 #define using_module_types_impl(r, data, Mod) using Module##Mod = Mod;
232  BOOST_PP_SEQ_FOR_EACH(using_module_types, , BOOST_PP_VARIADIC_TO_SEQ(RobotUnitModules))
233 #undef using_module_types
234 #undef using_module_types_impl
235  // //////////////////////////////////////////////////////////////////////////////////////// //
236  // ////////////////////////////////// access to modules /////////////////////////////////// //
237  // //////////////////////////////////////////////////////////////////////////////////////// //
238  protected:
239  /// @brief Checks whether the implementing class derives all modules.
240  void checkDerivedClasses() const;
241 
242  public:
243  /**
244  * @brief Returns this as ref to the given type.
245  * @return This as ref to the given type.
246  */
247  template <class T>
248  T&
250  {
251  return dynamic_cast<T&>(*this);
252  }
253 
254  /**
255  * @brief Returns this as ref to the given type.
256  * @return This as ref to the given type.
257  */
258  template <class T>
259  const T&
260  _module() const
261  {
262  return dynamic_cast<const T&>(*this);
263  }
264 
265  /**
266  * @brief Returns this as ptr to the given type.
267  * @return This as ptr to the given type.
268  */
269  template <class T>
270  T*
272  {
273  return &_module<T>();
274  }
275 
276  /**
277  * @brief Returns this as ptr to the given type.
278  * @return This as ptr to the given type.
279  */
280  template <class T>
281  const T*
282  _modulePtr() const
283  {
284  return &_module<const T>();
285  }
286 
287  // //////////////////////////////////////////////////////////////////////////////////////// //
288  // ////////////////////////////// ManagedIceObject life cycle ///////////////////////////// //
289  // //////////////////////////////////////////////////////////////////////////////////////// //
290  protected:
291  //ManagedIceObject life cycle
292  /**
293  * @brief \note This function is protected with \ref getGuard()
294  * @see \ref ManagedIceObject::onInitComponent
295  */
296  void onInitComponent() final override;
297  /**
298  * @brief \warning This function is not protected with \ref getGuard()
299  * @see \ref ManagedIceObject::onConnectComponent
300  */
301  void onConnectComponent() final override;
302  /**
303  * @brief \warning This function is not protected with \ref getGuard()
304  * @see \ref ManagedIceObject::onDisconnectComponent
305  */
306  void onDisconnectComponent() final override;
307  /**
308  * @brief \note This function is protected with \ref getGuard()
309  * @see \ref ManagedIceObject::onExitComponent
310  */
311  void onExitComponent() final override;
312 
313  //ManagedIceObject life cycle module hooks
314  /**
315  * @brief Hook for deriving RobotUnitModules called in \ref onInitComponent (called before \ref onInitRobotUnit was called)
316  * \note This function is protected with \ref getGuard()
317  * @see onInitComponent
318  */
319  void
321  {
322  }
323 
324  /**
325  * @brief Hook for deriving RobotUnitModules called in \ref onInitComponent (called after \ref onInitRobotUnit was called)
326  * \note This function is protected with \ref getGuard()
327  * @see onInitComponent
328  */
329  void
331  {
332  }
333 
334  /**
335  * @brief Hook for deriving RobotUnitModules called in \ref onConnectComponent (called before \ref onConnectRobotUnit was called)
336  * \warning This function is not protected with \ref getGuard()
337  * @see onConnectComponent
338  */
339  void
341  {
342  }
343 
344  /**
345  * @brief Hook for deriving RobotUnitModules called in \ref onConnectComponent (called after \ref onConnectRobotUnit was called)
346  * \warning This function is not protected with \ref getGuard()
347  * @see onConnectComponent
348  */
349  void
351  {
352  }
353 
354  /**
355  * @brief Hook for deriving RobotUnitModules called in \ref onDisconnectComponent (called before \ref onDisconnectRobotUnit was called)
356  * \warning This function is not protected with \ref getGuard()
357  * @see onDisconnectComponent
358  */
359  void
361  {
362  }
363 
364  /**
365  * @brief Hook for deriving RobotUnitModules called in \ref onDisconnectComponent (called after \ref onDisconnectRobotUnit was called)
366  * \warning This function is not protected with \ref getGuard()
367  * @see onDisconnectComponent
368  */
369  void
371  {
372  }
373 
374  /**
375  * @brief Hook for deriving RobotUnitModules called in \ref onExitComponent (called before \ref onExitRobotUnit was called)
376  * \note This function is protected with \ref getGuard()
377  * @see onExitComponent
378  */
379  void
381  {
382  }
383 
384  /**
385  * @brief Hook for deriving RobotUnitModules called in \ref onExitComponent (called after \ref onExitRobotUnit was called)
386  * \note This function is protected with \ref getGuard()
387  * @see onExitComponent
388  */
389  void
391  {
392  }
393 
394  // //////////////////////////////////////////////////////////////////////////////////////// //
395  // ////////////////////// other ManagedIceObject / Component methods ////////////////////// //
396  // //////////////////////////////////////////////////////////////////////////////////////// //
397  protected:
398  /// @see \ref ManagedIceObject::componentPropertiesUpdated
399  void componentPropertiesUpdated(const std::set<std::string>& changedProperties) override;
400  /// @see \ref ManagedIceObject::icePropertiesInitialized
401  void icePropertiesInitialized() override;
402 
403  /// @see \ref ManagedIceObject::getDefaultName
404  std::string
405  getDefaultName() const override
406  {
407  return "RobotUnit";
408  }
409 
410  //module hooks
411  /// @brief Hook for deriving RobotUnitModules called in \ref componentPropertiesUpdated
412  void
413  _componentPropertiesUpdated(const std::set<std::string>& /*changedProperties*/)
414  {
415  }
416 
417  /// @brief Hook for deriving RobotUnitModules called in \ref icePropertiesInitialized
418  void
420  {
421  }
422 
423  // //////////////////////////////////////////////////////////////////////////////////////// //
424  // ////////////////////////////// state and state transition ////////////////////////////// //
425  // //////////////////////////////////////////////////////////////////////////////////////// //
426  private:
427  /**
428  * @brief Sets the \ref RobotUnit's state to \param s
429  * @param s The state to set
430  */
431  void setRobotUnitState(RobotUnitState s);
432 
433  protected:
434  //state transitions
435  /**
436  * @brief Transition \ref RobotUnitState::InitializingComponent -> \ref RobotUnitState::InitializingDevices
437  * \note This function is protected with \ref getGuard()
438  * @see _preFinishComponentInitialization
439  * @see _postFinishComponentInitialization
440  */
441  virtual void finishComponentInitialization();
442  /**
443  * @brief Transition \ref RobotUnitState::InitializingDevices -> \ref RobotUnitState::InitializingUnits
444  * \note This function is protected with \ref getGuard()
445  * @see _preFinishDeviceInitialization
446  * @see _postFinishDeviceInitialization
447  */
448  virtual void finishDeviceInitialization();
449  /**
450  * @brief Transition \ref RobotUnitState::InitializingUnits -> \ref RobotUnitState::WaitingForRTThreadInitialization
451  * \note This function is protected with \ref getGuard()
452  * @see _preFinishUnitInitialization
453  * @see _postFinishUnitInitialization
454  */
455  virtual void finishUnitInitialization();
456  /**
457  * @brief Transition \ref RobotUnitState::InitializingControlThread -> \ref RobotUnitState::Running
458  * \note This function is protected with \ref getGuard()
459  * @see _preFinishControlThreadInitialization
460  * @see _postFinishControlThreadInitialization
461  */
462  virtual void finishControlThreadInitialization();
463  /**
464  * @brief Transition \ref RobotUnitState::Running -> \ref RobotUnitState::Exiting
465  * \note This function is protected with \ref getGuard()
466  * @see _preFinishRunning
467  * @see _postFinishRunning
468  */
469  virtual void finishRunning();
470 
471  //state transition module hooks
472  /**
473  * @brief Hook for deriving RobotUnitModules called in \ref finishComponentInitialization (called before the state has changed)
474  * \note This function is protected with \ref getGuard()
475  * @see finishComponentInitialization
476  */
477  void
479  {
480  }
481 
482  /**
483  * @brief Hook for deriving RobotUnitModules called in \ref finishComponentInitialization (called after the state has changed)
484  * \note This function is protected with \ref getGuard()
485  * @see finishComponentInitialization
486  */
487  void
489  {
490  }
491 
492  /**
493  * @brief Hook for deriving RobotUnitModules called in \ref finishDeviceInitialization (called before the state has changed)
494  * \note This function is protected with \ref getGuard()
495  * @see finishDeviceInitialization
496  */
497  void
499  {
500  }
501 
502  /**
503  * @brief Hook for deriving RobotUnitModules called in \ref finishDeviceInitialization (called after the state has changed)
504  * \note This function is protected with \ref getGuard()
505  * @see finishDeviceInitialization
506  */
507  void
509  {
510  }
511 
512  /**
513  * @brief Hook for deriving RobotUnitModules called in \ref finishUnitInitialization (called before the state has changed)
514  * \note This function is protected with \ref getGuard()
515  * @see finishUnitInitialization
516  */
517  void
519  {
520  }
521 
522  /**
523  * @brief Hook for deriving RobotUnitModules called in \ref finishUnitInitialization (called after the state has changed)
524  * \note This function is protected with \ref getGuard()
525  * @see finishUnitInitialization
526  */
527  void
529  {
530  }
531 
532  /**
533  * @brief Hook for deriving RobotUnitModules called in \ref finishControlThreadInitialization (called before the state has changed)
534  * \note This function is protected with \ref getGuard()
535  * @see finishControlThreadInitialization
536  */
537  void
539  {
540  }
541 
542  /**
543  * @brief Hook for deriving RobotUnitModules called in \ref finishControlThreadInitialization (called after the state has changed)
544  * \note This function is protected with \ref getGuard()
545  * @see finishControlThreadInitialization
546  */
547  void
549  {
550  }
551 
552  /**
553  * @brief Hook for deriving RobotUnitModules called in \ref finishRunning (called before the state has changed)
554  * \note This function is protected with \ref getGuard()
555  * @see finishRunning
556  */
557  void
559  {
560  }
561 
562  /**
563  * @brief Hook for deriving RobotUnitModules called in \ref finishRunning (called after the state has changed)
564  * \note This function is protected with \ref getGuard()
565  * @see finishRunning
566  */
567  void
569  {
570  }
571 
572  // //////////////////////////////////////////////////////////////////////////////////////// //
573  // /////////////////////////////////////// utility //////////////////////////////////////// //
574  // //////////////////////////////////////////////////////////////////////////////////////// //
575  public:
576  /**
577  * @brief Returns the \ref RobotUnit's State
578  * @return The \ref RobotUnit's State
579  */
581 
582  /**
583  * @brief Throws an exception if the current state is not in \param stateSet
584  * @param stateSet The set of acceptable \ref RobotUnitState "RobotUnitStates"
585  * @param fnc The callers function name.
586  * @param onlyWarn Only print a warning instead of throwing an exception.
587  */
588  void throwIfStateIsNot(const std::set<RobotUnitState>& stateSet,
589  const std::string& fnc,
590  bool onlyWarn = false) const;
591  /**
592  * @brief Throws an exception if the current state is not \param state
593  * @param state The acceptable \ref RobotUnitState
594  * @param fnc The callers function name.
595  * @param onlyWarn Only print a warning instead of throwing an exception.
596  */
597  void
598  throwIfStateIsNot(RobotUnitState s, const std::string& fnc, bool onlyWarn = false) const;
599  /**
600  * @brief Throws an exception if the current state is in \param stateSet
601  * @param stateSet The set of forbidden \ref RobotUnitState "RobotUnitStates"
602  * @param fnc The callers function name.
603  * @param onlyWarn Only print a warning instead of throwing an exception.
604  */
605  void throwIfStateIs(const std::set<RobotUnitState>& stateSet,
606  const std::string& fnc,
607  bool onlyWarn = false) const;
608  /**
609  * @brief Throws an exception if the current state is \param state
610  * @param state The forbidden \ref RobotUnitState
611  * @param fnc The callers function name.
612  * @param onlyWarn Only print a warning instead of throwing an exception.
613  */
614  void throwIfStateIs(RobotUnitState s, const std::string& fnc, bool onlyWarn = false) const;
615  /**
616  * @brief Throws if the \ref Device "Devices" are not ready.
617  * @param fnc The callers function name.
618  * @see areDevicesReady
619  */
620  void throwIfDevicesNotReady(const std::string& fnc) const;
621 
622  /**
623  * @brief Returns whether \ref Device "Devices" are ready
624  * @return Whether \ref Device "Devices" are ready
625  * @see \ref DevicesReadyStates
626  */
627  bool areDevicesReady() const;
628 
629  /**
630  * @brief Returns whether the current thread is the \ref ControlThread.
631  * @return Whether the current thread is the \ref ControlThread.
632  */
633  bool inControlThread() const;
634 
635  /**
636  * @brief Throws if the current thread is the \ref ControlThread.
637  * @param fnc The callers function name.
638  */
639  void throwIfInControlThread(const std::string& fnc) const;
640 
641  /**
642  * @brief Returns whether the \ref RobotUnit is shutting down
643  * @return Whether the \ref RobotUnit is shutting down
644  * @see shutDown
645  */
646  bool
647  isShuttingDown() const ///TODO use this function in implementations
648  {
649  return isShuttingDown_.load();
650  }
651 
652  /**
653  * @brief Requests the \ref RobotUnit to shut down.
654  * @see isShuttingDown
655  */
656  void
657  shutDown() ///TODO use this function in implementations
658  {
659  isShuttingDown_.store(true);
660  }
661 
662  // //////////////////////////////////////////////////////////////////////////// //
663  // /////////////////////////// robot unit impl hooks ////////////////////////// //
664  // //////////////////////////////////////////////////////////////////////////// //
665  /**
666  * @brief called in onInitComponent
667  * \note This function is protected with \ref getGuard()
668  * @see onInitComponent
669  */
670  virtual void
672  {
673  }
674 
675  /**
676  * @brief called in onConnectComponent
677  * \warning This function is not protected with \ref getGuard()
678  * @see onConnectComponent
679  */
680  virtual void
682  {
683  }
684 
685  /**
686  * @brief called in onDisconnecComponent
687  * \warning This function is not protected with \ref getGuard()
688  * @see onDisconnecComponent
689  */
690  virtual void
692  {
693  }
694 
695  /**
696  * @brief called in onExitComponent before calling finishRunning
697  * \note This function is protected with \ref getGuard()
698  * @see finishRunning
699  * @see onExitComponent
700  */
701  virtual void
703  {
704  }
705 
706  /// @brief Implementations have to join their \ref ControlThread in this hook. (used by RobotUnit::finishRunning())
707  virtual void joinControlThread() = 0;
708 
709  /// @brief The \ref ControlThread's period
710  virtual IceUtil::Time getControlThreadTargetPeriod() const = 0;
711  // //////////////////////////////////////////////////////////////////////////// //
712  // ////////////////////////////////// other /////////////////////////////////// //
713  // //////////////////////////////////////////////////////////////////////////// //
714  protected:
715  /**
716  * @brief Returns a sentinel value for an index (std::numeric_limits<std::size_t>::max())
717  * @return A sentinel value for an index (std::numeric_limits<std::size_t>::max())
718  */
719  static constexpr std::size_t
721  {
723  }
724 
725  /**
726  * @brief Returns a guard to the \ref RobotUnits mutex.
727  * @return A guard to the \ref RobotUnits mutex.
728  * @throw throws If called in the \ref ControlThread or on shutdown.
729  */
730  GuardType getGuard() const;
731  // //////////////////////////////////////////////////////////////////////////////////////// //
732  // ///////////////////////////////////////// Data ///////////////////////////////////////// //
733  // //////////////////////////////////////////////////////////////////////////////////////// //
734  private:
735  /// @brief The \ref RobotUnits mutex.
736  mutable MutexType dataMutex;
737  /// @brief Set of \ref RobotUnitState "RobotUnitStates" where \ref Device "Devices" are usable
738  static const std::set<RobotUnitState> DevicesReadyStates;
739  /// @brief The \ref RobotUnit's current state
740  std::atomic<RobotUnitState> state{RobotUnitState::InitializingComponent};
741  /// @brief Whether the \ref RobotUnit is shutting down
742  std::atomic_bool isShuttingDown_{false};
743  };
744 } // namespace armarx::RobotUnitModule
745 
746 #include "RobotUnitModuleBase.ipp"
armarx::RobotUnitModule::ModuleBase::TimePointType
std::chrono::high_resolution_clock::time_point TimePointType
Definition: RobotUnitModuleBase.h:228
armarx::RobotUnitModule::ModuleBase::isShuttingDown
bool isShuttingDown() const
Returns whether the RobotUnit is shutting down.
Definition: RobotUnitModuleBase.h:647
armarx::PropertyDefinitionContainer::setPrefix
void setPrefix(std::string prefix)
Definition: PropertyDefinitionContainer.cpp:202
Pointer.h
forward_declare
#define forward_declare(r, data, Mod)
Definition: RobotUnitModuleBase.h:118
armarx::RobotUnitModule::ModuleBase::_postOnDisconnectRobotUnit
void _postOnDisconnectRobotUnit()
Hook for deriving RobotUnitModules called in onDisconnectComponent (called after onDisconnectRobotUni...
Definition: RobotUnitModuleBase.h:370
armarx::RobotUnitModule::ModuleBase::onConnectRobotUnit
virtual void onConnectRobotUnit()
called in onConnectComponent
Definition: RobotUnitModuleBase.h:681
armarx::RobotUnitModule::ModuleBase::MutexType
std::recursive_timed_mutex MutexType
The type of recursive_mutex used in this class.
Definition: RobotUnitModuleBase.h:225
armarx::RobotUnitModule::ModuleBase::_preFinishRunning
void _preFinishRunning()
Hook for deriving RobotUnitModules called in finishRunning (called before the state has changed)
Definition: RobotUnitModuleBase.h:558
armarx::RobotUnitModule::ModuleBase::_postFinishComponentInitialization
void _postFinishComponentInitialization()
Hook for deriving RobotUnitModules called in finishComponentInitialization (called after the state ha...
Definition: RobotUnitModuleBase.h:488
armarx::RobotUnitModule::ModuleBase::onExitComponent
void onExitComponent() final override
Definition: RobotUnitModuleBase.cpp:181
armarx::RobotUnitModule::ModuleBasePropertyDefinitions::ModuleBasePropertyDefinitions
ModuleBasePropertyDefinitions(std::string prefix)
Definition: RobotUnitModuleBase.h:111
armarx::PropertyDefinitionContainer::setDescription
void setDescription(const std::string &description)
Sets the detailed description of the property user.
Definition: PropertyDefinitionContainer.cpp:197
armarx::RobotUnitModule::ModuleBase::_modulePtr
const T * _modulePtr() const
Returns this as ptr to the given type.
Definition: RobotUnitModuleBase.h:282
armarx::TYPEDEF_PTRS_HANDLE
TYPEDEF_PTRS_HANDLE(NJointCartesianNaturalPositionController)
armarx::RobotUnitModule::ModuleBase::_preFinishControlThreadInitialization
void _preFinishControlThreadInitialization()
Hook for deriving RobotUnitModules called in finishControlThreadInitialization (called before the sta...
Definition: RobotUnitModuleBase.h:538
armarx::RobotUnitModule::ModuleBase::_preOnDisconnectRobotUnit
void _preOnDisconnectRobotUnit()
Hook for deriving RobotUnitModules called in onDisconnectComponent (called before onDisconnectRobotUn...
Definition: RobotUnitModuleBase.h:360
armarx::RobotUnitModule::ModuleBase::getDefaultName
std::string getDefaultName() const override
Definition: RobotUnitModuleBase.h:405
armarx::RobotUnitModule::ModuleBase::_module
const T & _module() const
Returns this as ref to the given type.
Definition: RobotUnitModuleBase.h:260
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::RobotUnitModule::ModuleBase::throwIfStateIs
void throwIfStateIs(const std::set< RobotUnitState > &stateSet, const std::string &fnc, bool onlyWarn=false) const
Throws an exception if the current state is in.
Definition: RobotUnitModuleBase.cpp:493
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:333
armarx::RobotUnitModule::ModuleBase::_postFinishRunning
void _postFinishRunning()
Hook for deriving RobotUnitModules called in finishRunning (called after the state has changed)
Definition: RobotUnitModuleBase.h:568
armarx::RobotUnitModule::ModuleBase::_preFinishComponentInitialization
void _preFinishComponentInitialization()
Hook for deriving RobotUnitModules called in finishComponentInitialization (called before the state h...
Definition: RobotUnitModuleBase.h:478
armarx::RobotUnitModule::ModuleBase::_postFinishControlThreadInitialization
void _postFinishControlThreadInitialization()
Hook for deriving RobotUnitModules called in finishControlThreadInitialization (called after the stat...
Definition: RobotUnitModuleBase.h:548
armarx::RobotUnitModule::ModuleBase::getRobotUnitState
RobotUnitState getRobotUnitState() const
Returns the RobotUnit's State.
Definition: RobotUnitModuleBase.ipp:29
armarx::RobotUnitModule::ModuleBase::onInitRobotUnit
virtual void onInitRobotUnit()
called in onInitComponent
Definition: RobotUnitModuleBase.h:671
armarx::RobotUnitModule::ModuleBase::checkDerivedClasses
void checkDerivedClasses() const
Checks whether the implementing class derives all modules.
armarx::RobotUnitModule::ModuleBase::_preOnInitRobotUnit
void _preOnInitRobotUnit()
Hook for deriving RobotUnitModules called in onInitComponent (called before onInitRobotUnit was calle...
Definition: RobotUnitModuleBase.h:320
armarx::RobotUnitModule::ModuleBase::finishUnitInitialization
virtual void finishUnitInitialization()
Transition RobotUnitState::InitializingUnits -> RobotUnitState::WaitingForRTThreadInitialization.
Definition: RobotUnitModuleBase.cpp:268
armarx::RobotUnitState::InitializingUnits
@ InitializingUnits
RobotUnitModuleBase.ipp
armarx::RobotUnitModule::ModuleBase::ModuleBase
ModuleBase()
Ctor.
Definition: RobotUnitModuleBase.cpp:537
armarx::RobotUnitModule::ModuleBase::inControlThread
bool inControlThread() const
Returns whether the current thread is the ControlThread.
Definition: RobotUnitModuleBase.cpp:409
armarx::RobotUnitModule::ModuleBase::shutDown
void shutDown()
Requests the RobotUnit to shut down.
Definition: RobotUnitModuleBase.h:657
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
armarx::RobotUnitState::Running
@ Running
armarx::RobotUnitModule::ModuleBase::Instance
static ModuleBase & Instance()
Returns the singleton instance of this class.
Definition: RobotUnitModuleBase.h:194
armarx::RobotUnitModule::ModuleBase::onDisconnectComponent
void onDisconnectComponent() final override
Definition: RobotUnitModuleBase.cpp:162
armarx::RobotUnitModule::ModuleBase::componentPropertiesUpdated
void componentPropertiesUpdated(const std::set< std::string > &changedProperties) override
Definition: RobotUnitModuleBase.cpp:205
armarx::RobotUnitModule::ModuleBase::getControlThreadTargetPeriod
virtual IceUtil::Time getControlThreadTargetPeriod() const =0
The ControlThread's period.
armarx::RobotUnitModule::ModuleBase::ClockType
std::chrono::high_resolution_clock ClockType
Definition: RobotUnitModuleBase.h:227
armarx::RobotUnitModule::ModuleBase::IndexSentinel
static constexpr std::size_t IndexSentinel()
Returns a sentinel value for an index (std::numeric_limits<std::size_t>::max())
Definition: RobotUnitModuleBase.h:720
armarx::RobotUnitModule::ModuleBase::_postOnExitRobotUnit
void _postOnExitRobotUnit()
Hook for deriving RobotUnitModules called in onExitComponent (called after onExitRobotUnit was called...
Definition: RobotUnitModuleBase.h:390
armarx::RobotUnitModule::detail::ModuleBaseIntermediatePropertyDefinitions::ModuleBaseIntermediatePropertyDefinitions
ModuleBaseIntermediatePropertyDefinitions()
Definition: RobotUnitModuleBase.h:99
armarx::RobotUnitModule::ModuleBase::finishControlThreadInitialization
virtual void finishControlThreadInitialization()
Transition RobotUnitState::InitializingControlThread -> RobotUnitState::Running.
Definition: RobotUnitModuleBase.cpp:289
armarx::RobotUnitModule::ModuleBase::getGuard
GuardType getGuard() const
Returns a guard to the RobotUnits mutex.
Definition: RobotUnitModuleBase.cpp:430
max
T max(T t1, T t2)
Definition: gdiam.h:48
armarx::RobotUnitModule::ModuleBase::onExitRobotUnit
virtual void onExitRobotUnit()
called in onExitComponent before calling finishRunning
Definition: RobotUnitModuleBase.h:702
armarx::RobotUnitModule::ModuleBase::onDisconnectRobotUnit
virtual void onDisconnectRobotUnit()
called in onDisconnecComponent
Definition: RobotUnitModuleBase.h:691
armarx::RobotUnitModule::ModuleBase::_preOnExitRobotUnit
void _preOnExitRobotUnit()
Hook for deriving RobotUnitModules called in onExitComponent (called before onExitRobotUnit was calle...
Definition: RobotUnitModuleBase.h:380
armarx::RobotUnitModule::ModuleBase::finishRunning
virtual void finishRunning()
Transition RobotUnitState::Running -> RobotUnitState::Exiting.
Definition: RobotUnitModuleBase.cpp:311
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
armarx::to_string
const std::string & to_string(const std::string &s)
Definition: StringHelpers.h:40
armarx::RobotUnitModule::ModuleBase::joinControlThread
virtual void joinControlThread()=0
Implementations have to join their ControlThread in this hook. (used by RobotUnit::finishRunning())
armarx::RobotUnitState::InitializingControlThread
@ InitializingControlThread
Component.h
armarx::Component
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition: Component.h:95
armarx::RobotUnitModule::ModuleBase::_icePropertiesInitialized
void _icePropertiesInitialized()
Hook for deriving RobotUnitModules called in icePropertiesInitialized.
Definition: RobotUnitModuleBase.h:419
armarx::RobotUnitModule::ModuleBase::_postFinishDeviceInitialization
void _postFinishDeviceInitialization()
Hook for deriving RobotUnitModules called in finishDeviceInitialization (called after the state has c...
Definition: RobotUnitModuleBase.h:508
armarx::RobotUnitModule::ModuleBase::_preFinishDeviceInitialization
void _preFinishDeviceInitialization()
Hook for deriving RobotUnitModules called in finishDeviceInitialization (called before the state has ...
Definition: RobotUnitModuleBase.h:498
armarx::RobotUnitModule::ModuleBase::_modulePtr
T * _modulePtr()
Returns this as ptr to the given type.
Definition: RobotUnitModuleBase.h:271
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:70
armarx::RobotUnitModule::ModuleBase::_postOnConnectRobotUnit
void _postOnConnectRobotUnit()
Hook for deriving RobotUnitModules called in onConnectComponent (called after onConnectRobotUnit was ...
Definition: RobotUnitModuleBase.h:350
armarx::RobotUnitModule::ModuleBase::Instance
static T & Instance()
Returns the singleton instance of the given class.
Definition: RobotUnitModuleBase.h:206
armarx::RobotUnitModule::ModuleBase::areDevicesReady
bool areDevicesReady() const
Returns whether Devices are ready.
Definition: RobotUnitModuleBase.cpp:403
armarx::RobotUnitState::InitializingDevices
@ InitializingDevices
armarx::RobotUnitModule::ModuleBase::icePropertiesInitialized
void icePropertiesInitialized() override
Definition: RobotUnitModuleBase.cpp:215
armarx::RobotUnitModule::ModuleBase::GuardType
std::unique_lock< MutexType > GuardType
Definition: RobotUnitModuleBase.h:226
armarx::operator<<
std::ostream & operator<<(std::ostream &os, const PythonApplicationManager::Paths &paths)
Definition: PythonApplicationManager.cpp:221
armarx::RobotUnitState::InitializingComponent
@ InitializingComponent
armarx::RobotUnitModule::ModuleBase::_module
T & _module()
Returns this as ref to the given type.
Definition: RobotUnitModuleBase.h:249
armarx::RobotUnitModule::ModuleBase::_preOnConnectRobotUnit
void _preOnConnectRobotUnit()
Hook for deriving RobotUnitModules called in onConnectComponent (called before onConnectRobotUnit was...
Definition: RobotUnitModuleBase.h:340
armarx::RobotUnitModule::ModuleBase::throwIfInControlThread
void throwIfInControlThread(const std::string &fnc) const
Throws if the current thread is the ControlThread.
Definition: RobotUnitModuleBase.cpp:416
armarx::RobotUnitModule::ModuleBase::_preFinishUnitInitialization
void _preFinishUnitInitialization()
Hook for deriving RobotUnitModules called in finishUnitInitialization (called before the state has ch...
Definition: RobotUnitModuleBase.h:518
armarx::RobotUnitState
RobotUnitState
The current state of the multi step initialization of a RobotUnit.
Definition: RobotUnitModuleBase.h:74
armarx::RobotUnitModule::ModuleBase::throwIfDevicesNotReady
void throwIfDevicesNotReady(const std::string &fnc) const
Throws if the Devices are not ready.
Definition: RobotUnitModuleBase.cpp:530
armarx::RobotUnitModule::ModuleBase::throwIfStateIsNot
void throwIfStateIsNot(const std::set< RobotUnitState > &stateSet, const std::string &fnc, bool onlyWarn=false) const
Throws an exception if the current state is not in.
Definition: RobotUnitModuleBase.cpp:456
armarx::RobotUnitModule::ModuleBase::_postFinishUnitInitialization
void _postFinishUnitInitialization()
Hook for deriving RobotUnitModules called in finishUnitInitialization (called after the state has cha...
Definition: RobotUnitModuleBase.h:528
armarx::RobotUnitModule
Definition: ControlDevice.h:34
armarx::RobotUnitModule::ModuleBase::finishComponentInitialization
virtual void finishComponentInitialization()
Transition RobotUnitState::InitializingComponent -> RobotUnitState::InitializingDevices.
Definition: RobotUnitModuleBase.cpp:226
armarx::RobotUnitModule::ModuleBase::onInitComponent
void onInitComponent() final override
armarx::RobotUnitModule::detail
Definition: RobotUnitModuleBase.h:94
T
float T
Definition: UnscentedKalmanFilterTest.cpp:35
armarx::RobotUnitModule::ModuleBase::_postOnInitRobotUnit
void _postOnInitRobotUnit()
Hook for deriving RobotUnitModules called in onInitComponent (called after onInitRobotUnit was called...
Definition: RobotUnitModuleBase.h:330
armarx::RobotUnitModule::detail::ModuleBaseIntermediatePropertyDefinitions
Definition: RobotUnitModuleBase.h:96
armarx::RobotUnitModule::ModuleBasePropertyDefinitions
Definition: RobotUnitModuleBase.h:107
armarx::RobotUnitModule::ModuleBase::finishDeviceInitialization
virtual void finishDeviceInitialization()
Transition RobotUnitState::InitializingDevices -> RobotUnitState::InitializingUnits.
Definition: RobotUnitModuleBase.cpp:247
armarx::RobotUnitModule::ModuleBase::_componentPropertiesUpdated
void _componentPropertiesUpdated(const std::set< std::string > &)
Hook for deriving RobotUnitModules called in componentPropertiesUpdated.
Definition: RobotUnitModuleBase.h:413
armarx::ctrlutil::s
double s(double t, double s0, double v0, double a0, double j)
Definition: CtrlUtil.h:33
armarx::RobotUnitState::Exiting
@ Exiting
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
using_module_types
#define using_module_types(...)
Definition: RobotUnitModuleBase.h:230
armarx::RobotUnitModule::ModuleBase
Base class for all RobotUnitModules.
Definition: RobotUnitModuleBase.h:183
armarx::RobotUnitModule::ModuleBase::onConnectComponent
void onConnectComponent() final override
Definition: RobotUnitModuleBase.cpp:143
armarx::CheckedCastAndDeref
Targ & CheckedCastAndDeref(Src *src)
Definition: RobotUnitModuleBase.h:56