RobotUnit.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::RobotUnit
17  * @author Raphael Grimm ( raphael dot grimm at kit dot edu )
18  * @date 2017
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 #pragma once
24 
26 
27 // This include is not necessary but a lot of other files rely on it being included here
28 // Can be removed if other files include what they use
30 
31 /**
32 * @defgroup Library-RobotUnit RobotUnit
33 * @ingroup RobotAPI
34 * A description of the library RobotUnit.
35 */
36 
37 namespace armarx
38 {
39  TYPEDEF_PTRS_HANDLE(RobotUnit);
40 
41  /**
42  * @ingroup Library-RobotUnit
43  * @brief
44  */
54  {
55  public:
65  {
66  }
67  };
68 } // namespace armarx
69 
70 namespace armarx
71 {
72  /**
73  * @ingroup Library-RobotUnit
74  * @brief The RobotUnit class manages a robot and its controllers.
75  *
76  * The \ref RobotUnit manages \ref NJointControllerBase and \ref JointController for a robot.
77  * Controllers are executed in a control thread.
78  *
79  * \section Controllers
80  *
81  * \subsection RobotUnitCtrlsJoint Joint Controller
82  *
83  * \subsection RobotUnitCtrlsNJoint Multi Joint Controller
84  *
85  * \subsection RobotUnitControlModes Control Modes
86  * \subsubsection RobotUnitCtrlModesJointCtrl Control Modes of JointControlers
87  * \subsubsection RobotUnitCtrlModesHWCtrl Hardware Control Modes of JointControlers
88  * \subsubsection RobotUnitCtrlModeGroups Device Groups of Control Modes
89  *
90  * \section Units
91  * Units are created on an as needed basis.
92  * (e.g. If there is a platform, a \ref PlatformSubUnit is created)
93  *
94  * Available units are
95  *
96  * - \ref KinematicSubUnit
97  * - \ref PlatformSubUnit
98  * - \ref ForceTorqueSubUnit
99  *
100  * \section Publishing
101  * \section RtLogging
102  * Since the control thread (Section \ref softrt) should adhere soft rt properties,
103  * no function executed in it is allowed to block.
104  * Hence logging of messages via armarx logging streams (e.g. \ref ARMARX_INFO) is forbidden.
105  *
106  * There are non-blocking macros to log messages in the control thread:
107  *
108  * - \ref ARMARX_RT_LOGF_DEBUG
109  * - \ref ARMARX_RT_LOGF_VERBOSE
110  * - \ref ARMARX_RT_LOGF_INFO
111  * - \ref ARMARX_RT_LOGF_IMPORTANT
112  * - \ref ARMARX_RT_LOGF_WARN
113  * - \ref ARMARX_RT_LOGF_ERROR
114  * - \ref ARMARX_RT_LOGF_FATAL
115  *
116  * \warning These functions must only be called in the control thread after calling armarx::RobotUnit::finishControlThreadInitialization
117  *
118  * These macros work similar to printf and write their content to the corresponding
119  * armarx logging stream.
120  *
121  * The stream returns an object of the type \ref armarx::detail::RtMessageLogEntryBase.
122  * It is possible to deactivate spam on these streams by calling
123  * \ref armarx::detail::RtMessageLogEntryBase::deactivateSpam .
124  *
125  * E.g.
126  * \code
127  // prints every 1.5 seconds the message "foo 42 bar 24" to ARMARX_IMPORTANT
128  ARMARX_RT_LOGF_IMPORTANT("foo %d bar %d\n", 42, 24).deactivateSpam(1.5);
129  * \endcode
130  * \note It is not possible to print out strings this would need memory allocation.
131  *
132  * If an error occours, it is possible to print all recent messages (even the deactivated messages)
133  * to a file by calling the ice interface function \ref RobotUnitInterface::writeRecentIterationsToFile.
134  * The property "RTLoggingKeepIterationsForMs" decides how long all logging messages are keept (default 60 seconds).
135  * The \ref RobotUnitGui has a button to call this function.
136  *
137  * \section Threads
138  * This section explains the running threads and their responsibilities.
139  * \subsection ctrlthrd Control Thread
140  * This thread should be able to adhere soft rt if PREEMPT_RT is used.
141  *
142  * Its tasks are:
143  *
144  * - Communication with the Robot
145  * - Execution of \ref NJointControllerBase and \ref JointController
146  * - Transferring data (\ref SensorValues, \ref ControlTargets) to other threads
147  * (publishing, units, logging)
148  *
149  * \subsubsection softrt Soft rt
150  *
151  * To adhere soft rt, the following actions are forbidden (an example and the reason are in parentheses):
152  *
153  * - Blocking operations (e.g. lock on a mutex) (can block the thread for a long time)
154  * - Writing data to an armarx stream (e.g. \ref ARMARX_INFO << "foo") (is blocking)
155  * - Allocating / freeing memory on the heap (e.g. std::vector<int>(2,2) ) (is blocking)
156  * - Writing data to a stream (e.g. std::cout << "bar") (may allocate memory)
157  * - Making remote calls (e.g. via ICE) (is blocking)
158  *
159  * \subsection pubthrd Publish Thread
160  *
161  * Its tasks are:
162  *
163  * - Update Units
164  * - Call publishing hooks of \ref NJointControllerBase
165  * - Publish data to \ref RobotUnitListener
166  *
167  * \subsection logthrd RtLogging Thread
168  * If this thread is deactivated, no Rt Logging is possible and
169  * no messages from the control Thread are printed.
170  *
171  * Its tasks are:
172  *
173  * - Log SensorValues and ControlTargets to files
174  * - Print messages from the Control Thread
175  *
176  * \subsection icethrd ICE Threads
177  *
178  * - Receive ICE calls
179  */
180  class RobotUnit :
181  virtual public RobotUnitInterface,
182  virtual public RobotUnitModule::Units,
183  virtual public RobotUnitModule::Logging,
184  virtual public RobotUnitModule::Devices,
185  virtual public RobotUnitModule::Publisher,
186  virtual public RobotUnitModule::RobotData,
187  virtual public RobotUnitModule::Management,
188  virtual public RobotUnitModule::ControlThread,
192  {
193  public:
194  ~RobotUnit();
195 
196  static RobotUnit&
198  {
199  return ModuleBase::Instance<RobotUnit>();
200  }
201 
202  /// @see PropertyUser::createPropertyDefinitions()
205  {
207  }
208  };
209 } // namespace armarx
armarx::RobotUnitModule::RobotDataPropertyDefinitions::RobotDataPropertyDefinitions
RobotDataPropertyDefinitions(std::string prefix)
Definition: RobotUnitModuleRobotData.cpp:37
NJointControllerBase.h
armarx::TYPEDEF_PTRS_HANDLE
TYPEDEF_PTRS_HANDLE(NJointCartesianNaturalPositionController)
RobotUnitModules.h
armarx::RobotUnitModule::ControlThreadPropertyDefinitions
Definition: RobotUnitModuleControlThread.h:41
armarx::RobotUnitModule::Units
This Module manages all Units of a RobotUnit.
Definition: RobotUnitModuleUnits.h:125
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::UnitsPropertyDefinitions::UnitsPropertyDefinitions
UnitsPropertyDefinitions(std::string prefix)
Definition: RobotUnitModuleUnits.h:36
armarx::RobotUnitModule::RobotDataPropertyDefinitions
Definition: RobotUnitModuleRobotData.h:40
armarx::RobotUnitModule::Logging
This Module manages logging of data.
Definition: RobotUnitModuleLogging.h:120
armarx::RobotUnitModule::LoggingPropertyDefinitions::LoggingPropertyDefinitions
LoggingPropertyDefinitions(std::string prefix)
Definition: RobotUnitModuleLogging.h:48
armarx::RobotUnitModule::ControlThread
This Module manages the ControlThread.
Definition: RobotUnitModuleControlThread.h:83
armarx::RobotUnitModule::LoggingPropertyDefinitions
Definition: RobotUnitModuleLogging.h:45
armarx::RobotUnitModule::SelfCollisionChecker
This Module manages self collision avoidance. If the distance between a pair of bodies falls below a ...
Definition: RobotUnitModuleSelfCollisionChecker.h:74
armarx::RobotUnit::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: RobotUnit.h:204
armarx::RobotUnitModule::ControlThreadPropertyDefinitions::ControlThreadPropertyDefinitions
ControlThreadPropertyDefinitions(std::string prefix)
Definition: RobotUnitModuleControlThread.h:44
armarx::RobotUnitModule::ManagementPropertyDefinitions::ManagementPropertyDefinitions
ManagementPropertyDefinitions(std::string prefix)
Definition: RobotUnitModuleManagement.h:33
armarx::RobotUnitModule::UnitsPropertyDefinitions
Definition: RobotUnitModuleUnits.h:33
armarx::RobotUnitModule::PublisherPropertyDefinitions
Definition: RobotUnitModulePublisher.h:47
armarx::RobotUnitModule::SelfCollisionCheckerPropertyDefinitions::SelfCollisionCheckerPropertyDefinitions
SelfCollisionCheckerPropertyDefinitions(std::string prefix)
Definition: RobotUnitModuleSelfCollisionChecker.h:40
armarx::RobotUnitModule::Publisher
This Module manages publishing of all data to Topics, updating of all units managed by the Units modu...
Definition: RobotUnitModulePublisher.h:98
armarx::RobotUnitModule::Devices
This Module manages sensor and control devices for a RobotUnit and only allows save and sane access.
Definition: RobotUnitModuleDevices.h:67
armarx::RobotUnitModule::DevicesPropertyDefinitions
Definition: RobotUnitModuleDevices.h:38
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:74
armarx::RobotUnitModule::DevicesPropertyDefinitions::DevicesPropertyDefinitions
DevicesPropertyDefinitions(std::string prefix)
Definition: RobotUnitModuleDevices.h:41
armarx::RobotUnitModule::PublisherPropertyDefinitions::PublisherPropertyDefinitions
PublisherPropertyDefinitions(std::string prefix)
Definition: RobotUnitModulePublisher.h:50
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::RobotUnit::Instance
static RobotUnit & Instance()
Definition: RobotUnit.h:197
armarx::RobotUnit
The RobotUnit class manages a robot and its controllers.
Definition: RobotUnit.h:180
armarx::RobotUnitModule::ControllerManagement
This Module manages NJointControllers.
Definition: RobotUnitModuleControllerManagement.h:39
armarx::RobotUnitPropertyDefinitions::RobotUnitPropertyDefinitions
RobotUnitPropertyDefinitions(std::string prefix)
Definition: RobotUnit.h:56
armarx::RobotUnitModule::ManagementPropertyDefinitions
Definition: RobotUnitModuleManagement.h:30
armarx::RobotUnitModule::RobotData
This Module holds all high-level data about the robot.
Definition: RobotUnitModuleRobotData.h:52
armarx::RobotUnitPropertyDefinitions
Definition: RobotUnit.h:45
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:34
armarx::RobotUnitModule::SelfCollisionCheckerPropertyDefinitions
Definition: RobotUnitModuleSelfCollisionChecker.h:37
armarx::RobotUnit::~RobotUnit
~RobotUnit()
Definition: RobotUnit.cpp:28
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::RobotUnitModule::ControlThreadDataBuffer
This Module manages all communication into and out of the ControlThread.
Definition: RobotUnitModuleControlThreadDataBuffer.h:79