RobotUnitModuleUnits.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 
26 #include <RobotAPI/interface/units/RobotUnit/RobotUnitInterface.h>
27 
28 #include "../Units/RobotUnitSubUnit.h"
29 #include "RobotUnitModuleBase.h"
30 
32 {
34  {
35  public:
37  {
38  defineOptionalProperty<std::string>(
39  "KinematicUnitName", "KinematicUnit", "The name of the created kinematic unit");
40  defineOptionalProperty<std::string>(
41  "KinematicUnitNameTopicPrefix", "", "Prefix for the kinematic sensor values topic");
42 
43  defineOptionalProperty<std::string>(
44  "DiagnosticsUnitName", "DiagnosticsUnit", "Name of the diagnostics unit.");
45 
46  defineOptionalProperty<std::string>(
47  "PlatformUnitName", "PlatformUnit", "The name of the created platform unit");
48 
49  auto& types = defineOptionalProperty<NJointHolonomicPlatformVelocityControllerTypes>(
50  "PlatformUnitVelocityControllerType",
52  "Which controller to use for velocity control of the platform");
53  for (const auto& [type, name] :
55  {
56  types.map(name, type);
57  }
58 
59  defineOptionalProperty<float>(
60  "PlatformUnitMaximumPositionAcceleration",
61  800,
62  "The maximum allowed acceleration for the position of the platform");
63  defineOptionalProperty<float>(
64  "PlatformUnitMaximumOrientationAcceleration",
65  80,
66  "The maximum allowed acceleration for the orientation of the platform");
67 
68  defineOptionalProperty<std::string>(
69  "ForceTorqueUnitName",
70  "ForceTorqueUnit",
71  "The name of the created force troque unit (empty = default)");
72  defineOptionalProperty<std::string>(
73  "ForceTorqueTopicName",
74  "ForceTorqueValues",
75  "Name of the topic on which the force torque sensor values are provided");
76 
77  defineOptionalProperty<std::string>(
78  "InertialMeasurementUnitName",
79  "InertialMeasurementUnit",
80  "The name of the created inertial measurement unit (empty = default)");
81  defineOptionalProperty<std::string>(
82  "IMUTopicName", "IMUValues", "Name of the IMU Topic.");
83 
84  defineOptionalProperty<bool>("CreateTCPControlUnit",
85  false,
86  "If true the TCPControl SubUnit is created and added");
87  defineOptionalProperty<std::string>(
88  "TCPControlUnitName", "TCPControlUnit", "Name of the TCPControlUnit.");
89 
90  defineOptionalProperty<bool>(
91  "CreateTrajectoryPlayer",
92  true,
93  "If true the TrajectoryPlayer SubUnit is created and added");
94  defineOptionalProperty<std::string>(
95  "TrajectoryControllerUnitName",
96  "TrajectoryPlayer",
97  "Name of the TrajectoryControllerUnit. The respective component outside of the "
98  "RobotUnit is TrajectoryPlayer");
99 
100  defineOptionalProperty<std::string>(
101  "EmergencyStopMasterName",
102  "EmergencyStopMaster",
103  "The name used to register as an EmergencyStopMaster");
104  defineOptionalProperty<std::string>(
105  "EmergencyStopTopic",
106  "EmergencyStop",
107  "The name of the topic over which changes of the emergencyStopState are sent.");
108  }
109  };
110 
111  /**
112  * @ingroup Library-RobotUnit-Modules
113  * @brief This \ref ModuleBase "Module" manages all Units of a \ref RobotUnit
114  *
115  * These are the managed Units:
116  * - \ref getKinematicUnit "KinematicUnit"
117  * - \ref getForceTorqueUnit "ForceTorqueUnit"
118  * - \ref getInertialMeasurementUnit "InertialMeasurementUnit"
119  * - \ref getPlatformUnit "PlatformUnit"
120  * - \ref getTCPControlUnit "TCPControlUnit"
121  * - \ref getTrajectoryPlayer "TrajectoryPlayer"
122  *
123  * @see ModuleBase
124  */
125  class Units : virtual public ModuleBase, virtual public RobotUnitUnitInterface
126  {
127  friend class ModuleBase;
128 
129  public:
130  /**
131  * @brief Returns the singleton instance of this class
132  * @return The singleton instance of this class
133  */
134  static Units& Instance();
135  // //////////////////////////////////////////////////////////////////////////////////////// //
136  // ///////////////////////////////// RobotUnitModule hooks //////////////////////////////// //
137  // //////////////////////////////////////////////////////////////////////////////////////// //
138  private:
139  /// @see ModuleBase::_preOnInitRobotUnit
140  void _preOnInitRobotUnit();
141  /// @see ModuleBase::_icePropertiesInitialized
142  void _icePropertiesInitialized();
143  /// @see ModuleBase::_preFinishRunning
144  void _preFinishRunning();
145  /// @see ModuleBase::_postOnExitRobotUnit
146  void _postOnExitRobotUnit();
147  // //////////////////////////////////////////////////////////////////////////////////////// //
148  // ///////////////////////////////////// ice interface //////////////////////////////////// //
149  // //////////////////////////////////////////////////////////////////////////////////////// //
150  public:
151  /**
152  * @brief Returns proxies to all units
153  * @return Proxies to all units
154  */
155  Ice::ObjectProxySeq getUnits(const Ice::Current&) const override;
156  /**
157  * @brief Returns a proxy to the Unit with the given ice id (or null if there is none)
158  * @param staticIceId The Unit's ice id
159  * @return A proxy to the Unit with the given ice id (or null if there is none)
160  */
161  Ice::ObjectPrx getUnit(const std::string& staticIceId, const Ice::Current&) const override;
162 
163  /**
164  * @brief Returns a proxy to the KinematicUnit
165  * @return A proxy to the KinematicUnit
166  */
167  KinematicUnitInterfacePrx getKinematicUnit(const Ice::Current&) const override;
168  /**
169  * @brief Returns a proxy to the ForceTorqueUnit
170  * @return A proxy to the ForceTorqueUnit
171  */
172  ForceTorqueUnitInterfacePrx getForceTorqueUnit(const Ice::Current&) const override;
173  /**
174  * @brief Returns a proxy to the InertialMeasurementUnit
175  * @return A proxy to the InertialMeasurementUnit
176  */
177  InertialMeasurementUnitInterfacePrx
178  getInertialMeasurementUnit(const Ice::Current&) const override;
179  /**
180  * @brief Returns a proxy to the PlatformUnit
181  * @return A proxy to the PlatformUnit
182  */
183  PlatformUnitInterfacePrx getPlatformUnit(const Ice::Current&) const override;
184  /**
185  * @brief Returns a proxy to the TCPControlUnit
186  * @return A proxy to the TCPControlUnit
187  */
188  TCPControlUnitInterfacePrx getTCPControlUnit(const Ice::Current&) const override;
189  /**
190  * @brief Returns a proxy to the TrajectoryPlayer
191  * @return A proxy to the TrajectoryPlayer
192  */
193  TrajectoryPlayerInterfacePrx getTrajectoryPlayer(const Ice::Current&) const override;
194  // //////////////////////////////////////////////////////////////////////////////////////// //
195  // /////////////////////////////////// Module interface /////////////////////////////////// //
196  // //////////////////////////////////////////////////////////////////////////////////////// //
197  public:
198  //general getters
199  /**
200  * @brief Returns a pointer to the Unit with the given ice id (or null if there is none)
201  * @param staticIceId The Unit's ice id
202  * @return A pointer to the Unit with the given ice id (or null if there is none)
203  */
204  const ManagedIceObjectPtr& getUnit(const std::string& staticIceId) const;
205 
206  /**
207  * @brief Returns a pointer to the Unit for the given type (or null if there is none)
208  * @return A pointer to the Unit for the given type (or null if there is none)
209  */
210  template <class T>
211  typename T::PointerType getUnit() const;
212  /**
213  * @brief Returns a proxy to the Unit for the given type (or null if there is none)
214  * @return A proxy to the Unit for the given type (or null if there is none)
215  */
216  template <class T>
217  typename T::ProxyType getUnitPrx() const;
218 
219  //specific getters
220  /**
221  * @brief Returns a pointer to the KinematicUnit
222  * @return A pointer to the KinematicUnit
223  */
224  KinematicUnitInterfacePtr getKinematicUnit() const;
225  /**
226  * @brief Returns a pointer to the ForceTorqueUnit
227  * @return A pointer to the ForceTorqueUnit
228  */
229  ForceTorqueUnitInterfacePtr getForceTorqueUnit() const;
230  /**
231  * @brief Returns a pointer to the InertialMeasurementUnit
232  * @return A pointer to the InertialMeasurementUnit
233  */
234  InertialMeasurementUnitInterfacePtr getInertialMeasurementUnit() const;
235  /**
236  * @brief Returns a pointer to the PlatformUnit
237  * @return A pointer to the PlatformUnit
238  */
239  PlatformUnitInterfacePtr getPlatformUnit() const;
240  /**
241  * @brief Returns a pointer to the TCPControlUnit
242  * @return A pointer to the TCPControlUnit
243  */
244  TCPControlUnitInterfacePtr getTCPControlUnit() const;
245  /**
246  * @brief Returns a pointer to the TrajectoryPlayer
247  * @return A pointer to the TrajectoryPlayer
248  */
249  TrajectoryPlayerInterfacePtr getTrajectoryPlayer() const;
250  /**
251  * @brief Returns a pointer to the EmergencyStopMaster
252  * @return A pointer to the EmergencyStopMaster
253  */
254  const EmergencyStopMasterInterfacePtr& getEmergencyStopMaster() const;
255  // //////////////////////////////////////////////////////////////////////////////////////// //
256  // //////////////////////////////////// implementation //////////////////////////////////// //
257  // //////////////////////////////////////////////////////////////////////////////////////// //
258  protected:
259  /**
260  * @brief Calls all init hooks for all managed Units
261  *
262  * The called hooks are
263  * - \ref initializeKinematicUnit
264  * - \ref initializePlatformUnit
265  * - \ref initializeForceTorqueUnit
266  * - \ref initializeInertialMeasurementUnit
267  * - \ref initializeTrajectoryControllerUnit
268  * - \ref initializeTcpControllerUnit
269  */
270  virtual void initializeDefaultUnits();
271  /// @brief Initialize the diagnostics unit.
272  virtual void initializeDiagnosticsUnit();
273  /// @brief Initializes the KinematicUnit
274  virtual void initializeKinematicUnit();
275  /// @brief Initializes the PlatformUnit
276  virtual void initializePlatformUnit();
277  /// @brief Initializes the ForceTorqueUnit
278  virtual void initializeForceTorqueUnit();
279  /// @brief Initializes the InertialMeasurementUnit
280  virtual void initializeInertialMeasurementUnit();
281  /// @brief Initializes the TrajectoryControllerUnit
282  virtual void initializeTrajectoryControllerUnit();
283  /// @brief Initializes the TcpControllerUnit
284  virtual void initializeTcpControllerUnit();
285  /// @brief Initializes the TcpControllerUnit
286  virtual void initializeLocalizationUnit();
287  /// @brief Create the \ref KinematicUnit (this function should be called in \ref initializeKinematicUnit)
289  createKinematicSubUnit(const Ice::PropertiesPtr& properties,
290  const std::string& positionControlMode = ControlModes::Position1DoF,
291  const std::string& velocityControlMode = ControlModes::Velocity1DoF,
292  const std::string& torqueControlMode = ControlModes::Torque1DoF,
293  const std::string& pwmControlMode = ControlModes::PWM1DoF);
294  /**
295  * @brief Registers a unit for management (the Unit is added and removed to the \ref ArmarXManager
296  * and updated with new values.
297  * @param unit The Unit to add.
298  */
299  void addUnit(ManagedIceObjectPtr unit);
300  // //////////////////////////////////////////////////////////////////////////////////////// //
301  // ///////////////////////////////////////// Data ///////////////////////////////////////// //
302  // //////////////////////////////////////////////////////////////////////////////////////// //
303  private:
304  /// @brief holds all units managed by the RobotUnit
305  std::vector<ManagedIceObjectPtr> units;
306  /// @brief holds a copy of all units managed by the RobotUnit derived from RobotUnitSubUnit
307  /// this is done to prevent casting
308  std::vector<RobotUnitSubUnitPtr> subUnits;
309 
310  /// @brief Pointer to the EmergencyStopMaster used by the \ref RobotUnit
311  EmergencyStopMasterInterfacePtr emergencyStopMaster;
312 
313  /// @brief Temporary ptr to the TCPControlUnit
314  ManagedIceObjectPtr tcpControllerSubUnit;
315  /// @brief Temporary ptr to the TrajectoryPlayer
316  ManagedIceObjectPtr trajectoryControllerSubUnit;
317 
318  /// @brief A copy of the VirtualRobot to be used inside of this Module
319  VirtualRobot::RobotPtr unitCreateRobot;
320  // //////////////////////////////////////////////////////////////////////////////////////// //
321  // /////////////////////////////////////// Attorneys ////////////////////////////////////// //
322  // //////////////////////////////////////////////////////////////////////////////////////// //
323  private:
324  /**
325  * \brief This class allows minimal access to private members of \ref Units in a sane fashion for \ref Publisher.
326  * \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 !!
327  */
329  };
330 } // namespace armarx::RobotUnitModule
331 
332 #include "RobotUnitModuleUnits.ipp"
NJointHolonomicPlatformVelocityControllerTypes.h
armarx::RobotUnitModule::Units::initializePlatformUnit
virtual void initializePlatformUnit()
Initializes the PlatformUnit.
Definition: RobotUnitModuleUnits.cpp:472
armarx::RobotUnitModule::Units::initializeDefaultUnits
virtual void initializeDefaultUnits()
Calls all init hooks for all managed Units.
Definition: RobotUnitModuleUnits.cpp:201
armarx::NJointHolonomicPlatformVelocityControllerTypes::PassThroughController
@ PassThroughController
armarx::RobotUnitModule::Units::initializeForceTorqueUnit
virtual void initializeForceTorqueUnit()
Initializes the ForceTorqueUnit.
Definition: RobotUnitModuleUnits.cpp:699
armarx::RobotUnitModule::Units::addUnit
void addUnit(ManagedIceObjectPtr unit)
Registers a unit for management (the Unit is added and removed to the ArmarXManager and updated with ...
Definition: RobotUnitModuleUnits.cpp:854
armarx::RobotUnitModule::Units
This Module manages all Units of a RobotUnit.
Definition: RobotUnitModuleUnits.h:125
RobotUnitModuleBase.h
armarx::NJointHolonomicPlatformVelocityControllerTypesNames
const simox::meta::EnumNames< NJointHolonomicPlatformVelocityControllerTypes > NJointHolonomicPlatformVelocityControllerTypesNames
Definition: NJointHolonomicPlatformVelocityControllerTypes.h:37
armarx::RobotUnitModule::Units::createKinematicSubUnit
ManagedIceObjectPtr createKinematicSubUnit(const Ice::PropertiesPtr &properties, const std::string &positionControlMode=ControlModes::Position1DoF, const std::string &velocityControlMode=ControlModes::Velocity1DoF, const std::string &torqueControlMode=ControlModes::Torque1DoF, const std::string &pwmControlMode=ControlModes::PWM1DoF)
Create the KinematicUnit (this function should be called in initializeKinematicUnit)
Definition: RobotUnitModuleUnits.cpp:319
armarx::RobotUnitModule::Units::getUnits
Ice::ObjectProxySeq getUnits(const Ice::Current &) const override
Returns proxies to all units.
Definition: RobotUnitModuleUnits.cpp:162
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::Units::initializeInertialMeasurementUnit
virtual void initializeInertialMeasurementUnit()
Initializes the InertialMeasurementUnit.
Definition: RobotUnitModuleUnits.cpp:762
armarx::RobotUnitModule::Units::getKinematicUnit
KinematicUnitInterfacePtr getKinematicUnit() const
Returns a pointer to the KinematicUnit.
Definition: RobotUnitModuleUnits.ipp:79
armarx::RobotUnitModule::Units::getInertialMeasurementUnit
InertialMeasurementUnitInterfacePtr getInertialMeasurementUnit() const
Returns a pointer to the InertialMeasurementUnit.
Definition: RobotUnitModuleUnits.ipp:89
IceInternal::Handle< ManagedIceObject >
armarx::RobotUnitModule::Units::initializeTcpControllerUnit
virtual void initializeTcpControllerUnit()
Initializes the TcpControllerUnit.
Definition: RobotUnitModuleUnits.cpp:830
armarx::RobotUnitModule::Units::getUnit
T::PointerType getUnit() const
Returns a pointer to the Unit for the given type (or null if there is none)
Definition: RobotUnitModuleUnits.ipp:66
armarx::RobotUnitModule::Units::getForceTorqueUnit
ForceTorqueUnitInterfacePtr getForceTorqueUnit() const
Returns a pointer to the ForceTorqueUnit.
Definition: RobotUnitModuleUnits.ipp:84
armarx::RobotUnitModule::Units::initializeKinematicUnit
virtual void initializeKinematicUnit()
Initializes the KinematicUnit.
Definition: RobotUnitModuleUnits.cpp:298
armarx::RobotUnitModule::Units::Instance
static Units & Instance()
Returns the singleton instance of this class.
Definition: RobotUnitModuleUnits.ipp:29
armarx::RobotUnitModule::Units::getTrajectoryPlayer
TrajectoryPlayerInterfacePtr getTrajectoryPlayer() const
Returns a pointer to the TrajectoryPlayer.
Definition: RobotUnitModuleUnits.ipp:104
armarx::RobotUnitModule::UnitsAttorneyForPublisher
This class allows minimal access to private members of Units in a sane fashion for Publisher.
Definition: RobotUnitModulePublisher.cpp:106
armarx::RobotUnitModule::UnitsPropertyDefinitions
Definition: RobotUnitModuleUnits.h:33
armarx::RobotUnitModule::Units::getTCPControlUnit
TCPControlUnitInterfacePtr getTCPControlUnit() const
Returns a pointer to the TCPControlUnit.
Definition: RobotUnitModuleUnits.ipp:99
armarx::RobotUnitModule::Units::getPlatformUnit
PlatformUnitInterfacePtr getPlatformUnit() const
Returns a pointer to the PlatformUnit.
Definition: RobotUnitModuleUnits.ipp:94
armarx::ProxyType
ProxyType
Definition: ProxyPropertyDefinition.h:41
armarx::RobotUnitModule::Units::getEmergencyStopMaster
const EmergencyStopMasterInterfacePtr & getEmergencyStopMaster() const
Returns a pointer to the EmergencyStopMaster.
Definition: RobotUnitModuleUnits.cpp:194
RobotUnitModuleUnits.ipp
armarx::RobotUnitModule::Units::initializeDiagnosticsUnit
virtual void initializeDiagnosticsUnit()
Initialize the diagnostics unit.
Definition: RobotUnitModuleUnits.cpp:261
armarx::RobotUnitModule::Units::getUnitPrx
T::ProxyType getUnitPrx() const
Returns a proxy to the Unit for the given type (or null if there is none)
Definition: RobotUnitModuleUnits.ipp:73
armarx::RobotUnitModule::Units::initializeTrajectoryControllerUnit
virtual void initializeTrajectoryControllerUnit()
Initializes the TrajectoryControllerUnit.
Definition: RobotUnitModuleUnits.cpp:807
armarx::RobotUnitModule::Units::initializeLocalizationUnit
virtual void initializeLocalizationUnit()
Initializes the TcpControllerUnit.
Definition: RobotUnitModuleUnits.cpp:625
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
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:18