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