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
37namespace armarx
38{
40
41 /**
42 * @ingroup Library-RobotUnit
43 * @brief
44 */
68} // namespace armarx
69
70namespace 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()
204 };
205} // namespace armarx
#define TYPEDEF_PTRS_HANDLE(T)
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
This Module manages all communication into and out of the ControlThread.
This Module manages the ControlThread.
This Module manages sensor and control devices for a RobotUnit and only allows save and sane access.
This Module manages logging of data.
This Module handles some general management tasks.
This Module manages publishing of all data to Topics, updating of all units managed by the Units modu...
This Module holds all high-level data about the robot.
This Module manages all Units of a RobotUnit.
RobotUnitPropertyDefinitions(std::string prefix)
Definition RobotUnit.h:56
The RobotUnit class manages a robot and its controllers.
Definition RobotUnit.h:192
static RobotUnit & Instance()
Definition RobotUnit.h:197
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition RobotUnit.cpp:33
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.