TrajectoryControllerSubUnit.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::TrajectoryControllerSubUnit
17  * @author Stefan Reither ( stef dot reither at web dot de )
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 
25 #include <mutex>
26 
27 #include <RobotAPI/interface/components/TrajectoryPlayerInterface.h>
28 
29 #include "../NJointControllers/NJointTrajectoryController.h"
30 #include "../RobotUnit.h"
31 #include "KinematicSubUnit.h"
32 #include "RobotUnitSubUnit.h"
33 
34 namespace armarx
35 {
38  {
39  public:
42  {
43  defineRequiredProperty<std::string>("KinematicUnitName",
44  "Name of the KinematicUnit. Only needed for "
45  "returning to zeroFramePose while resetting.");
46  defineOptionalProperty<float>("Kp",
47  1.f,
48  "Proportional gain value of PID Controller",
50  defineOptionalProperty<float>("Ki",
51  0.0f,
52  "Integral gain value of PID Controller",
54  defineOptionalProperty<float>("Kd",
55  0.0f,
56  "Differential gain value of PID Controller",
58  defineOptionalProperty<float>(
59  "absMaximumVelocity",
60  80.0f,
61  "The PID will never set a velocity above this threshold (degree/s)");
62  defineOptionalProperty<std::string>("CustomRootNode",
63  "",
64  "If this value is set, the root pose of the motion "
65  "is set for this node instead of the root joint.");
66 
67  defineOptionalProperty<bool>("EnableRobotPoseUnit",
68  false,
69  "Specify whether RobotPoseUnit should be used to move the "
70  "robot's position. Only useful in simulation.");
71  defineOptionalProperty<std::string>(
72  "RobotPoseUnitName",
73  "RobotPoseUnit",
74  "Name of the RobotPoseUnit to which the robot position should be sent");
75  }
76  };
77 
78  TYPEDEF_PTRS_HANDLE(TrajectoryControllerSubUnit);
79 
81  virtual public RobotUnitSubUnit,
82  virtual public TrajectoryPlayerInterface,
83  virtual public Component
84  {
85  // TrajectoryControllerSubUnitInterface interface
86  public:
87  bool startTrajectoryPlayer(const Ice::Current& = Ice::emptyCurrent) override;
88  bool pauseTrajectoryPlayer(const Ice::Current& = Ice::emptyCurrent) override;
89  bool stopTrajectoryPlayer(const Ice::Current& = Ice::emptyCurrent) override;
90  bool resetTrajectoryPlayer(bool moveToFrameZeroPose,
91  const Ice::Current& = Ice::emptyCurrent) override;
92 
93  void loadJointTraj(const TrajectoryBasePtr& jointTraj,
94  const Ice::Current& = Ice::emptyCurrent) override;
95  void loadBasePoseTraj(const TrajectoryBasePtr& basePoseTraj,
96  const Ice::Current& = Ice::emptyCurrent) override;
97 
98  void setLoopPlayback(bool loop, const Ice::Current& = Ice::emptyCurrent) override;
99  Ice::Double getEndTime(const Ice::Current& = Ice::emptyCurrent) override;
100  Ice::Double getTrajEndTime(const Ice::Current& = Ice::emptyCurrent) override;
101  Ice::Double getCurrentTime(const Ice::Current& = Ice::emptyCurrent) override;
102  void setEndTime(Ice::Double, const Ice::Current& = Ice::emptyCurrent) override;
103 
104  // Within the RobotUnit the NJointTrajectoryController is always in VelocityControl
105  void
106  setIsVelocityControl(bool, const Ice::Current& = Ice::emptyCurrent) override
107  {
108  }
109 
110  void setIsPreview(bool, const Ice::Current& = Ice::emptyCurrent) override;
111  bool
112  setJointsInUse(const std::string&, bool, const Ice::Current& = Ice::emptyCurrent) override;
113  void enableRobotPoseUnit(bool, const Ice::Current& = Ice::emptyCurrent) override;
114 
115  void considerConstraints(bool, const Ice::Current& = Ice::emptyCurrent) override;
116 
117  // RobotUnitSubUnit interface
118  void update(const SensorAndControl& sc, const JointAndNJointControllers& c) override;
119 
120  void setup(RobotUnit* rUnit);
121 
122  // KinematicUnitListener interface
123  void
124  reportControlModeChanged(const NameControlModeMap&,
125  Ice::Long,
126  bool,
127  const Ice::Current&) override
128  {
129  }
130 
131  void
132  reportJointAngles(const NameValueMap&, Ice::Long, bool, const Ice::Current&) override
133  {
134  }
135 
136  void
137  reportJointVelocities(const NameValueMap&, Ice::Long, bool, const Ice::Current&) override
138  {
139  }
140 
141  void
142  reportJointTorques(const NameValueMap&, Ice::Long, bool, const Ice::Current&) override
143  {
144  }
145 
146  void
147  reportJointAccelerations(const NameValueMap&, Ice::Long, bool, const Ice::Current&) override
148  {
149  }
150 
151  void
152  reportJointCurrents(const NameValueMap&, Ice::Long, bool, const Ice::Current&) override
153  {
154  }
155 
156  void
158  Ice::Long,
159  bool,
160  const Ice::Current&) override
161  {
162  }
163 
164  void
165  reportJointStatuses(const NameStatusMap&, Ice::Long, bool, const Ice::Current&) override
166  {
167  }
168 
169  void
170  setOffset(const ::Eigen::Matrix4f&, const ::Ice::Current& = ::Ice::emptyCurrent) override
171  {
172  }
173 
174  // ManagedIceObject interface
175  protected:
176  void onInitComponent() override;
177  void onConnectComponent() override;
178  void onDisconnectComponent() override;
179 
180  std::string
181  getDefaultName() const override
182  {
183  return "TrajectoryPlayer";
184  }
185 
186  /**
187  * @see PropertyUser::createPropertyDefinitions()
188  */
191  {
194  }
195 
196  private:
197  NJointTrajectoryControllerPtr
198  createTrajectoryController(std::vector<std::string>& jointNames, bool deleteIfAlreadyExist);
199  void assureTrajectoryController();
200  bool controllerExists();
201  void previewRun();
202 
203  RobotUnit* robotUnit = NULL;
204  NJointTrajectoryControllerPtr jointTrajController;
205  std::string controllerName = this->getName() + "_" + "JointTrajectory";
206 
207  TrajectoryPtr jointTraj;
208 
209  // so far no usage -> need to implement usage of robotPoseUnit (only for simulation) -> does it really belong here?
210  TrajectoryPtr basePoseTraj;
211  bool robotPoseUnitEnabled;
212  std::string robotPoseUnitName;
213 
214  double endTime;
215  double trajEndTime;
216  std::vector<std::string> usedJoints;
217 
218  std::string kinematicUnitName;
219  KinematicUnitInterfacePrx kinematicUnit;
220  std::string customRootNode;
221 
222  float kp;
223  float ki;
224  float kd;
225  float maxVelocity;
226  bool considerConstraintsForTrajectoryOptimization = false;
227 
228  bool isPreview = false;
229  DebugDrawerInterfacePrx debugDrawer;
231 
232  std::mutex dataMutex;
233  std::recursive_mutex controllerMutex;
234  bool recreateController = true;
235 
236  // Component interface
237  public:
238  virtual void
239  componentPropertiesUpdated(const std::set<std::string>& changedProperties) override;
240  };
241 } // namespace armarx
armarx::TrajectoryControllerSubUnit::setJointsInUse
bool setJointsInUse(const std::string &, bool, const Ice::Current &=Ice::emptyCurrent) override
Definition: TrajectoryControllerSubUnit.cpp:341
armarx::TrajectoryControllerSubUnit::componentPropertiesUpdated
virtual void componentPropertiesUpdated(const std::set< std::string > &changedProperties) override
Implement this function if you would like to react to changes in the properties.
Definition: TrajectoryControllerSubUnit.cpp:526
armarx::TrajectoryControllerSubUnit::setOffset
void setOffset(const ::Eigen::Matrix4f &, const ::Ice::Current &=::Ice::emptyCurrent) override
Definition: TrajectoryControllerSubUnit.h:170
armarx::JointAndNJointControllers
Structure used by the RobotUnit to swap lists of Joint and NJoint controllers.
Definition: JointAndNJointControllers.h:32
armarx::TYPEDEF_PTRS_HANDLE
TYPEDEF_PTRS_HANDLE(NJointCartesianNaturalPositionController)
armarx::TrajectoryControllerSubUnit::getTrajEndTime
Ice::Double getTrajEndTime(const Ice::Current &=Ice::emptyCurrent) override
Definition: TrajectoryControllerSubUnit.cpp:263
armarx::TrajectoryControllerSubUnit::getDefaultName
std::string getDefaultName() const override
Retrieve default name of component.
Definition: TrajectoryControllerSubUnit.h:181
armarx::TrajectoryControllerSubUnit::reportJointTorques
void reportJointTorques(const NameValueMap &, Ice::Long, bool, const Ice::Current &) override
Definition: TrajectoryControllerSubUnit.h:142
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:333
armarx::TrajectoryControllerSubUnit
Definition: TrajectoryControllerSubUnit.h:80
armarx::TrajectoryControllerSubUnit::reportJointAngles
void reportJointAngles(const NameValueMap &, Ice::Long, bool, const Ice::Current &) override
Definition: TrajectoryControllerSubUnit.h:132
armarx::TrajectoryControllerSubUnit::update
void update(const SensorAndControl &sc, const JointAndNJointControllers &c) override
Definition: TrajectoryControllerSubUnit.cpp:388
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
armarx::RobotUnitSubUnit
Definition: RobotUnitSubUnit.h:35
armarx::navigation::platform_controller::platform_global_trajectory::NameValueMap
std::map< std::string, float > NameValueMap
Definition: PlatformGlobalTrajectoryController.h:93
armarx::TrajectoryControllerSubUnit::reportJointCurrents
void reportJointCurrents(const NameValueMap &, Ice::Long, bool, const Ice::Current &) override
Definition: TrajectoryControllerSubUnit.h:152
IceInternal::Handle< Trajectory >
armarx::detail::ControlThreadOutputBufferEntry
Definition: ControlThreadOutputBuffer.h:177
armarx::VariantType::Double
const VariantTypeId Double
Definition: Variant.h:919
armarx::TrajectoryControllerSubUnit::setup
void setup(RobotUnit *rUnit)
Definition: TrajectoryControllerSubUnit.cpp:518
armarx::TrajectoryControllerSubUnit::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: TrajectoryControllerSubUnit.h:190
armarx::TrajectoryControllerSubUnitPropertyDefinitions
Definition: TrajectoryControllerSubUnit.h:36
armarx::TrajectoryControllerSubUnit::stopTrajectoryPlayer
bool stopTrajectoryPlayer(const Ice::Current &=Ice::emptyCurrent) override
Definition: TrajectoryControllerSubUnit.cpp:113
armarx::TrajectoryControllerSubUnit::onConnectComponent
void onConnectComponent() override
Pure virtual hook for the subclass.
Definition: TrajectoryControllerSubUnit.cpp:45
armarx::TrajectoryControllerSubUnit::enableRobotPoseUnit
void enableRobotPoseUnit(bool, const Ice::Current &=Ice::emptyCurrent) override
Definition: TrajectoryControllerSubUnit.cpp:382
armarx::VariantType::Long
const VariantTypeId Long
Definition: Variant.h:917
armarx::TrajectoryControllerSubUnit::reportJointAccelerations
void reportJointAccelerations(const NameValueMap &, Ice::Long, bool, const Ice::Current &) override
Definition: TrajectoryControllerSubUnit.h:147
RobotUnitSubUnit.h
armarx::TrajectoryControllerSubUnit::getEndTime
Ice::Double getEndTime(const Ice::Current &=Ice::emptyCurrent) override
Definition: TrajectoryControllerSubUnit.cpp:257
armarx::TrajectoryControllerSubUnit::reportJointVelocities
void reportJointVelocities(const NameValueMap &, Ice::Long, bool, const Ice::Current &) override
Definition: TrajectoryControllerSubUnit.h:137
armarx::TrajectoryControllerSubUnit::onInitComponent
void onInitComponent() override
Pure virtual hook for the subclass.
Definition: TrajectoryControllerSubUnit.cpp:28
armarx::TrajectoryControllerSubUnit::setLoopPlayback
void setLoopPlayback(bool loop, const Ice::Current &=Ice::emptyCurrent) override
Definition: TrajectoryControllerSubUnit.cpp:244
armarx::Component
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition: Component.h:95
armarx::TrajectoryControllerSubUnit::startTrajectoryPlayer
bool startTrajectoryPlayer(const Ice::Current &=Ice::emptyCurrent) override
Definition: TrajectoryControllerSubUnit.cpp:58
armarx::TrajectoryControllerSubUnit::pauseTrajectoryPlayer
bool pauseTrajectoryPlayer(const Ice::Current &=Ice::emptyCurrent) override
Definition: TrajectoryControllerSubUnit.cpp:94
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:74
armarx::TrajectoryControllerSubUnit::considerConstraints
void considerConstraints(bool, const Ice::Current &=Ice::emptyCurrent) override
Definition: TrajectoryControllerSubUnit.cpp:393
armarx::TrajectoryControllerSubUnit::reportControlModeChanged
void reportControlModeChanged(const NameControlModeMap &, Ice::Long, bool, const Ice::Current &) override
Definition: TrajectoryControllerSubUnit.h:124
armarx::TrajectoryControllerSubUnit::loadBasePoseTraj
void loadBasePoseTraj(const TrajectoryBasePtr &basePoseTraj, const Ice::Current &=Ice::emptyCurrent) override
Definition: TrajectoryControllerSubUnit.cpp:237
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:601
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:70
KinematicSubUnit.h
armarx::TrajectoryControllerSubUnit::setEndTime
void setEndTime(Ice::Double, const Ice::Current &=Ice::emptyCurrent) override
Definition: TrajectoryControllerSubUnit.cpp:282
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::TrajectoryControllerSubUnitPropertyDefinitions::TrajectoryControllerSubUnitPropertyDefinitions
TrajectoryControllerSubUnitPropertyDefinitions(std::string prefix)
Definition: TrajectoryControllerSubUnit.h:40
armarx::RobotUnit
The RobotUnit class manages a robot and its controllers.
Definition: RobotUnit.h:180
IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface >
armarx::TrajectoryControllerSubUnit::onDisconnectComponent
void onDisconnectComponent() override
Hook for subclass.
Definition: TrajectoryControllerSubUnit.cpp:52
armarx::TrajectoryControllerSubUnit::setIsVelocityControl
void setIsVelocityControl(bool, const Ice::Current &=Ice::emptyCurrent) override
Definition: TrajectoryControllerSubUnit.h:106
armarx::TrajectoryControllerSubUnit::getCurrentTime
Ice::Double getCurrentTime(const Ice::Current &=Ice::emptyCurrent) override
Definition: TrajectoryControllerSubUnit.cpp:269
armarx::TrajectoryControllerSubUnit::setIsPreview
void setIsPreview(bool, const Ice::Current &=Ice::emptyCurrent) override
Definition: TrajectoryControllerSubUnit.cpp:323
armarx::ManagedIceObject::getName
std::string getName() const
Retrieve name of object.
Definition: ManagedIceObject.cpp:107
armarx::TrajectoryControllerSubUnit::reportJointStatuses
void reportJointStatuses(const NameStatusMap &, Ice::Long, bool, const Ice::Current &) override
Definition: TrajectoryControllerSubUnit.h:165
armarx::TrajectoryControllerSubUnit::reportJointMotorTemperatures
void reportJointMotorTemperatures(const NameValueMap &, Ice::Long, bool, const Ice::Current &) override
Definition: TrajectoryControllerSubUnit.h:157
armarx::TrajectoryControllerSubUnit::resetTrajectoryPlayer
bool resetTrajectoryPlayer(bool moveToFrameZeroPose, const Ice::Current &=Ice::emptyCurrent) override
Definition: TrajectoryControllerSubUnit.cpp:135
armarx::PropertyDefinitionBase::eModifiable
@ eModifiable
Definition: PropertyDefinitionInterface.h:57
armarx::TrajectoryControllerSubUnit::loadJointTraj
void loadJointTraj(const TrajectoryBasePtr &jointTraj, const Ice::Current &=Ice::emptyCurrent) override
Definition: TrajectoryControllerSubUnit.cpp:180
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28