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