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/VirtualRobot.h>
34
37
38#include <RobotAPI/interface/units/RobotUnit/RobotUnitInterface.h>
39
41#include "../util.h"
43
44/**
45 * @defgroup Library-RobotUnit-Modules RobotUnitModules
46 * @ingroup Library-RobotUnit
47 */
48
49namespace armarx
50{
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 '" +
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
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{
103} // namespace armarx::RobotUnitModule::detail
104
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 {
208 static_assert(std::is_base_of<ModuleBase, T>::value,
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.
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*
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
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
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
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
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
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 */
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
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
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
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
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
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
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
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
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
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 {
722 return std::numeric_limits<std::size_t>::max();
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
#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:46
Component()
Protected default constructor. Used for virtual inheritance. Use createManagedIceObject() instead.
Definition Component.cpp:66
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)