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