RobotUnitModuleManagement.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 "RobotUnitModuleBase.h"
26 
28 {
29 
31  {
32  public:
34  {
35  defineOptionalProperty<std::uint64_t>(
36  "AdditionalObjectSchedulerCount", 10, "Number of ObjectSchedulers to be added");
37 
38  defineOptionalProperty<bool>(
39  "HeartbeatRequired", true, "Whether the Heatbeat is required.");
40  defineOptionalProperty<long>("HeartbeatMaxCycleMS", 100, "The heartbeats cycle time");
41  defineOptionalProperty<long>(
42  "HeartbeatStartupMarginMS", 1000, "Startup time for heartbeats");
43  defineOptionalProperty<std::string>("AggregatedRobotHealthTopicName",
44  "AggregatedRobotHealthTopic",
45  "Name of the AggregatedRobotHealthTopic");
46  }
47  };
48 
49  /**
50  * @ingroup Library-RobotUnit-Modules
51  * @brief This \ref ModuleBase "Module" handles some general management tasks.
52  * It implements the \ref RobotUnitManagementInterface.
53  *
54  * @see ModuleBase
55  */
56  class Management : virtual public ModuleBase, virtual public RobotUnitManagementInterface
57  {
58  friend class ModuleBase;
59 
60  public:
61  /**
62  * @brief Returns the singleton instance of this class
63  * @return The singleton instance of this class
64  */
65  static Management&
67  {
68  return ModuleBase::Instance<Management>();
69  }
70 
71  // //////////////////////////////////////////////////////////////////////////////////////// //
72  // ///////////////////////////////// RobotUnitModule hooks //////////////////////////////// //
73  // //////////////////////////////////////////////////////////////////////////////////////// //
74  private:
75  /// @see ModuleBase::_preOnInitRobotUnit
76  void _preOnInitRobotUnit();
77  void _postFinishControlThreadInitialization();
78  // //////////////////////////////////////////////////////////////////////////////////////// //
79  // ///////////////////////////////////// ice interface //////////////////////////////////// //
80  // //////////////////////////////////////////////////////////////////////////////////////// //
81  public:
82  /**
83  * @brief Returns whether the RobotUnit is running.
84  * @return Whether the RobotUnit is running.
85  */
86  bool
87  isRunning(const Ice::Current& = Ice::emptyCurrent) const override
88  {
89  throwIfInControlThread(BOOST_CURRENT_FUNCTION);
91  }
92 
93  void aggregatedHeartbeat(RobotHealthState overallHealthState, const Ice::Current&) override;
94 
95  bool
96  isSimulation(const Ice::Current& = Ice::emptyCurrent) const override
97  {
98  return false;
99  }
100 
101  // //////////////////////////////////////////////////////////////////////////////////////// //
102  // ///////////////////////////////////////// Data ///////////////////////////////////////// //
103  // //////////////////////////////////////////////////////////////////////////////////////// //
104  private:
105  /// @brief The number of additional object schedulers
106  std::int64_t additionalObjectSchedulerCount{0};
107  std::int64_t controlLoopStartTime{0};
108  std::int64_t heartbeatStartupMarginMS{0};
109  std::atomic_bool heartbeatRequired{false};
110  std::atomic_long heartbeatMaxCycleMS{100};
111  std::atomic_long lastHeartbeat{0};
112 
113  // //////////////////////////////////////////////////////////////////////////////////////// //
114  // /////////////////////////////////////// Attorneys ////////////////////////////////////// //
115  // //////////////////////////////////////////////////////////////////////////////////////// //
116  private:
117  /**
118  * \brief This class allows minimal access to private members of \ref Management in a sane fashion for \ref ControlThread.
119  * \warning !! DO NOT ADD ADDITIONAL FRIENDS IF YOU DO NOT KNOW WAHT YOU ARE DOING! IF YOU DO SOMETHING WRONG YOU WILL CAUSE UNDEFINED BEHAVIOUR !!
120  */
122  };
123 } // namespace armarx::RobotUnitModule
armarx::RobotUnitModule::Management::isSimulation
bool isSimulation(const Ice::Current &=Ice::emptyCurrent) const override
Definition: RobotUnitModuleManagement.h:96
armarx::RobotUnitModule::Management::isRunning
bool isRunning(const Ice::Current &=Ice::emptyCurrent) const override
Returns whether the RobotUnit is running.
Definition: RobotUnitModuleManagement.h:87
RobotUnitModuleBase.h
armarx::RobotUnitModule::Management
This Module handles some general management tasks. It implements the RobotUnitManagementInterface.
Definition: RobotUnitModuleManagement.h:56
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:333
armarx::RobotUnitModule::ModuleBase::getRobotUnitState
RobotUnitState getRobotUnitState() const
Returns the RobotUnit's State.
Definition: RobotUnitModuleBase.ipp:29
armarx::RobotUnitModule::Management::Instance
static Management & Instance()
Returns the singleton instance of this class.
Definition: RobotUnitModuleManagement.h:66
armarx::RobotUnitModule::Management::aggregatedHeartbeat
void aggregatedHeartbeat(RobotHealthState overallHealthState, const Ice::Current &) override
Definition: RobotUnitModuleManagement.cpp:51
armarx::RobotUnitState::Running
@ Running
armarx::RobotUnitModule::ManagementPropertyDefinitions::ManagementPropertyDefinitions
ManagementPropertyDefinitions(std::string prefix)
Definition: RobotUnitModuleManagement.h:33
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::ManagementPropertyDefinitions
Definition: RobotUnitModuleManagement.h:30
armarx::RobotUnitModule
Definition: ControlDevice.h:34
armarx::RobotUnitModule::ModuleBasePropertyDefinitions
Definition: RobotUnitModuleBase.h:107
armarx::RobotUnitModule::ModuleBase
Base class for all RobotUnitModules.
Definition: RobotUnitModuleBase.h:183
armarx::RobotUnitModule::ManagementAttorneyForControlThread
This class allows minimal access to private members of Devices in a sane fashion for ControlThread.
Definition: RobotUnitModuleControlThread.cpp:270