TrajectoryPlayer.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 RobotComponents::ArmarXObjects::TrajectoryPlayer
17  * @author zhou ( derekyou dot zhou at gmail dot com )
18  * @date 2016
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 #pragma once
24 
25 
26 #include <mutex>
27 
30 #include <ArmarXCore/interface/observers/ObserverInterface.h>
31 
33 #include <RobotAPI/interface/components/TrajectoryPlayerInterface.h>
34 #include <RobotAPI/interface/units/RobotPoseUnitInterface.h>
40 
41 namespace armarx
42 {
43  /**
44  * @class TrajectoryPlayerPropertyDefinitions
45  * @brief
46  */
48  {
49  public:
52  {
53  defineRequiredProperty<std::string>(
54  "KinematicUnitName",
55  "Name of the KinematicUnit to which the joint values should be sent");
56  defineRequiredProperty<std::string>("KinematicTopicName",
57  "Name of the KinematicUnit reporting topic");
58 
59  defineOptionalProperty<std::string>(
60  "ArmarXProjects",
61  "Armar4",
62  "Comma-separated list with names of ArmarXProjects (e.g. 'Armar3,Armar4'). The MMM "
63  "XML File can be specified relatively to a data path of one of these projects.");
64  defineOptionalProperty<float>(
65  "FPS",
66  100.0f,
67  "FPS with which the recording should be executed. Velocities will be adapted.");
68  defineOptionalProperty<bool>(
69  "LoopPlayback", false, "Specify whether motion should be repeated after execution");
70  defineOptionalProperty<bool>(
71  "isVelocityControl",
72  true,
73  "Specify whether the PID Controller should be used (==velocity control)");
74  defineOptionalProperty<float>("Kp", 1.f, "Proportional gain value of PID Controller");
75  defineOptionalProperty<float>("Ki", 0.00001f, "Integral gain value of PID Controller");
76  defineOptionalProperty<float>("Kd", 0.0f, "Differential gain value of PID Controller");
77  defineOptionalProperty<float>(
78  "absMaximumVelocity",
79  120.0f,
80  "The PID will never set a velocity above this threshold (degree/s)");
81  defineOptionalProperty<std::string>(
82  "RobotNodeSetName",
83  "RobotState",
84  "The name of the robot node set to be used (only need for PIDController mode)");
85  defineOptionalProperty<std::string>("CustomRootNode",
86  "",
87  "If this value is set, the root pose of the motion "
88  "is set for this node instead of the root joint.");
89 
90  defineOptionalProperty<bool>("EnableRobotPoseUnit",
91  false,
92  "Specify whether RobotPoseUnit should be used to move the "
93  "robot's position. Only useful in simulation.");
94  defineOptionalProperty<std::string>(
95  "RobotPoseUnitName",
96  "RobotPoseUnit",
97  "Name of the RobotPoseUnit to which the robot position should be sent");
98  defineOptionalProperty<float>(
99  "Offset.x", 0.f, "x component of initial robot position (mm)");
100  defineOptionalProperty<float>(
101  "Offset.y", 0.f, "y component of initial robot position (mm)");
102  defineOptionalProperty<float>(
103  "Offset.z", 0.f, "z component of initial robot position (mm)");
104  defineOptionalProperty<float>(
105  "Offset.roll", 0.f, "Initial robot pose: roll component of RPY angles (radian)");
106  defineOptionalProperty<float>(
107  "Offset.pitch", 0.f, "Initial robot pose: pitch component of RPY angles (radian)");
108  defineOptionalProperty<float>(
109  "Offset.yaw", 0.f, "Initial robot pose: yaw component of RPY angles (radian)");
110  }
111  };
112 
113  /**
114  * @defgroup Component-TrajectoryPlayer TrajectoryPlayer
115  * @ingroup RobotComponents-Components
116  * A description of the component TrajectoryPlayer.
117  *
118  * @class TrajectoryPlayer
119  * @ingroup Component-TrajectoryPlayer
120  * @brief Brief description of class TrajectoryPlayer.
121  *
122  * Detailed description of class TrajectoryPlayer.
123  */
125  virtual public armarx::Component,
126  public armarx::TrajectoryPlayerInterface
127 
128  {
129  public:
130  /**
131  * @see armarx::ManagedIceObject::getDefaultName()
132  */
133  std::string
134  getDefaultName() const override
135  {
136  return "TrajectoryPlayer";
137  }
138 
139  // interface
140  bool startTrajectoryPlayer(const Ice::Current&) override;
141  bool pauseTrajectoryPlayer(const Ice::Current&) override;
142  bool stopTrajectoryPlayer(const Ice::Current&) override;
143  bool resetTrajectoryPlayer(bool moveToFrameZeroPose, const Ice::Current&) override;
144  void setLoopPlayback(bool loop, const Ice::Current&) override;
145  void setIsVelocityControl(bool isVelocity,
146  const ::Ice::Current& = Ice::emptyCurrent) override;
147 
148  // virtual void load(const TrajSource& trajs,
149  // double start = 0.0,
150  // double end = 1.0,
151  // double timestep = 0.01,
152  // const ::Ice::StringSeq& joints = std::vector<std::string>(),
153  // const ::Ice::Current& = Ice::emptyCurrent);
154 
155  // virtual void load(const TrajectoryBasePtr& trajs,
156  // double start = 0.0,
157  // double end = 1.0,
158  // double timestep = 0.01,
159  // const ::Ice::StringSeq& joints = std::vector<std::string>(),
160  // const ::Ice::Current& = Ice::emptyCurrent);
161 
162  void loadJointTraj(const TrajectoryBasePtr& trajs,
163  const ::Ice::Current& = Ice::emptyCurrent) override;
164  void loadBasePoseTraj(const TrajectoryBasePtr& trajs,
165  const ::Ice::Current& = Ice::emptyCurrent) override;
166 
167  double
168  getCurrentTime(const Ice::Current&) override
169  {
170  return currentTime;
171  }
172 
173  double
174  getEndTime(const Ice::Current&) override
175  {
176  return endTime;
177  }
178 
179  void
180  setEndTime(double end, const Ice::Current&) override
181  {
182  if (endTime == end)
183  {
184  return;
185  }
186 
187  endTime = end;
188  jointTraj = jointTraj->normalize(0, endTime);
189  basePoseTraj = basePoseTraj->normalize(0, endTime);
190  }
191 
192  double
193  getTrajEndTime(const Ice::Current&) override
194  {
195  return trajEndTime;
196  }
197 
198  void
199  setIsPreview(bool isPreview, const Ice::Current&) override
200  {
201  this->isPreview = isPreview;
202  }
203 
204  void
205  enableRobotPoseUnit(bool isRobotPose, const Ice::Current&) override
206  {
207  robotPoseUnitEnabled = isRobotPose;
208  }
209 
210  void
211  considerConstraints(bool, const Ice::Current&) override
212  {
213  ARMARX_WARNING << "NYI TrajectoryPlayer::considerConstraints()";
214  }
215 
216  bool setJointsInUse(const std::string& jointName, bool inUse, const Ice::Current&) override;
217 
218  // KinematicUnitListener interface
219  void
220  reportControlModeChanged(const NameControlModeMap&,
221  Ice::Long,
222  bool,
223  const Ice::Current&) override
224  {
225  }
226 
227  void reportJointAngles(const NameValueMap& angles,
228  Ice::Long,
229  bool,
230  const Ice::Current&) override;
231 
232  void
233  reportJointVelocities(const NameValueMap&, Ice::Long, bool, const Ice::Current&) override
234  {
235  }
236 
237  void
238  reportJointTorques(const NameValueMap&, Ice::Long, bool, const Ice::Current&) override
239  {
240  }
241 
242  void
243  reportJointAccelerations(const NameValueMap&, Ice::Long, bool, const Ice::Current&) override
244  {
245  }
246 
247  void
248  reportJointCurrents(const NameValueMap&, Ice::Long, bool, const Ice::Current&) override
249  {
250  }
251 
252  void
254  Ice::Long,
255  bool,
256  const Ice::Current&) override
257  {
258  }
259 
260  void
261  reportJointStatuses(const NameStatusMap&, Ice::Long, bool, const Ice::Current&) override
262  {
263  }
264 
265  void
266  setOffset(const Eigen::Matrix4f& offset, const Ice::Current&) override
267  {
268  this->offset = offset;
269  }
270 
271  void updateTargetValues();
272 
273  protected:
274  /**
275  * @see armarx::ManagedIceObject::onInitComponent()
276  */
277  void onInitComponent() override;
278 
279  /**
280  * @see armarx::ManagedIceObject::onConnectComponent()
281  */
282  void onConnectComponent() override;
283 
284  /**
285  * @see armarx::ManagedIceObject::onDisconnectComponent()
286  */
287  void onDisconnectComponent() override;
288 
289  /**
290  * @see armarx::ManagedIceObject::onExitComponent()
291  */
292  void onExitComponent() override;
293 
294  /**
295  * @see PropertyUser::createPropertyDefinitions()
296  */
298 
299 
302 
303 
304  KinematicUnitInterfacePrx kinematicUnit;
307 
308  std::string armarxProject;
310 
312 
314  Ice::StringSeq jointNames;
315  std::map<std::string, bool> jointNamesUsed;
316  std::map<std::string, bool> limitlessMap;
317 
319 
320  double currentTime;
321  double runningTime;
323  double timeOffset;
324  double endTime;
325 
327  bool isPreview;
328  std::map<std::string, PIDControllerPtr> PIDs;
334  // float start, end;
337  float maxVel;
338 
339  std::string modelFileName;
340 
341 
342  void run();
343  bool checkJointsLimit();
344  bool checkSelfCollision();
345 
346  VirtualRobot::RobotPtr localModel; // to analyze the availability of the trajectory point.
347 
348  private:
349  bool start();
350  bool pause();
351  bool stop();
352  void updatePIDController(const NameValueMap& angles);
353 
354  double trajEndTime;
355 
356  IceUtil::Time startCal;
357  double frozenTime;
358 
359  std::recursive_mutex motionMutex;
360  NameValueMap latestJointAngles;
361  std::mutex jointAnglesMutex;
362 
363  bool paused;
364  bool firstRound;
365  VirtualRobot::RobotNodePtr customRootNode;
366  };
367 
369 
370 } // namespace armarx
DebugDrawerComponent.h
armarx::TrajectoryPlayer::offset
Eigen::Matrix4f offset
Definition: TrajectoryPlayer.h:311
armarx::TrajectoryPlayer::localModel
VirtualRobot::RobotPtr localModel
Definition: TrajectoryPlayer.h:346
RemoteRobot.h
armarx::TrajectoryPlayer::armarxProject
std::string armarxProject
Definition: TrajectoryPlayer.h:308
armarx::TrajectoryPlayer::debugObserver
DebugObserverInterfacePrx debugObserver
Definition: TrajectoryPlayer.h:305
armarx::TrajectoryPlayer::targetVelocityValues
NameValueMap targetVelocityValues
Definition: TrajectoryPlayer.h:330
armarx::TrajectoryPlayer::setOffset
void setOffset(const Eigen::Matrix4f &offset, const Ice::Current &) override
Definition: TrajectoryPlayer.h:266
armarx::TrajectoryPlayer::reportControlModeChanged
void reportControlModeChanged(const NameControlModeMap &, Ice::Long, bool, const Ice::Current &) override
Definition: TrajectoryPlayer.h:220
armarx::TrajectoryPlayer::onDisconnectComponent
void onDisconnectComponent() override
Definition: TrajectoryPlayer.cpp:454
armarx::TrajectoryPlayer::loadJointTraj
void loadJointTraj(const TrajectoryBasePtr &trajs, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: TrajectoryPlayer.cpp:245
armarx::TrajectoryPlayer::targetPositionValues
NameValueMap targetPositionValues
Definition: TrajectoryPlayer.h:329
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:650
armarx::TrajectoryPlayer::enableRobotPoseUnit
void enableRobotPoseUnit(bool isRobotPose, const Ice::Current &) override
Definition: TrajectoryPlayer.h:205
armarx::TrajectoryPlayer
Brief description of class TrajectoryPlayer.
Definition: TrajectoryPlayer.h:124
Pose.h
armarx::TrajectoryPlayer::run
void run()
Definition: TrajectoryPlayer.cpp:471
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:345
armarx::TrajectoryPlayer::kinematicUnit
KinematicUnitInterfacePrx kinematicUnit
Definition: TrajectoryPlayer.h:304
PeriodicTask.h
armarx::TrajectoryPlayer::endTime
double endTime
Definition: TrajectoryPlayer.h:324
armarx::TrajectoryPlayerPropertyDefinitions::TrajectoryPlayerPropertyDefinitions
TrajectoryPlayerPropertyDefinitions(std::string prefix)
Definition: TrajectoryPlayer.h:50
armarx::TrajectoryPlayer::jointNames
Ice::StringSeq jointNames
Definition: TrajectoryPlayer.h:314
armarx::TrajectoryPlayer::loopPlayback
bool loopPlayback
Definition: TrajectoryPlayer.h:326
armarx::TrajectoryPlayer::stopTrajectoryPlayer
bool stopTrajectoryPlayer(const Ice::Current &) override
Definition: TrajectoryPlayer.cpp:97
armarx::TrajectoryPlayer::limitlessMap
std::map< std::string, bool > limitlessMap
Definition: TrajectoryPlayer.h:316
armarx::TrajectoryPlayer::onConnectComponent
void onConnectComponent() override
Definition: TrajectoryPlayer.cpp:432
armarx::TrajectoryPlayer::nullVelocities
NameValueMap nullVelocities
Definition: TrajectoryPlayer.h:332
armarx::TrajectoryPlayer::jointTraj
::armarx::TrajectoryPtr jointTraj
Definition: TrajectoryPlayer.h:300
armarx::TrajectoryPlayer::setIsVelocityControl
void setIsVelocityControl(bool isVelocity, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: TrajectoryPlayer.cpp:374
RobotAPIObjectFactories.h
armarx::TrajectoryPlayer::startTime
IceUtil::Time startTime
Definition: TrajectoryPlayer.h:322
armarx::TrajectoryPlayer::modelFileName
std::string modelFileName
Definition: TrajectoryPlayer.h:339
IceInternal::Handle< Trajectory >
armarx::TrajectoryPlayerPropertyDefinitions
Definition: TrajectoryPlayer.h:47
armarx::TrajectoryPlayer::isVelocityControl
bool isVelocityControl
Definition: TrajectoryPlayer.h:318
armarx::TrajectoryPlayer::onInitComponent
void onInitComponent() override
Definition: TrajectoryPlayer.cpp:415
armarx::TrajectoryPlayer::getCurrentTime
double getCurrentTime(const Ice::Current &) override
Definition: TrajectoryPlayer.h:168
armarx::TrajectoryPlayer::setIsPreview
void setIsPreview(bool isPreview, const Ice::Current &) override
Definition: TrajectoryPlayer.h:199
armarx::TrajectoryPlayer::considerConstraints
void considerConstraints(bool, const Ice::Current &) override
Definition: TrajectoryPlayer.h:211
armarx::TrajectoryPlayer::maxVel
float maxVel
Definition: TrajectoryPlayer.h:337
armarx::TrajectoryPlayer::direction
int direction
Definition: TrajectoryPlayer.h:335
armarx::TrajectoryPlayer::currentTime
double currentTime
Definition: TrajectoryPlayer.h:320
armarx::TrajectoryPlayer::resetTrajectoryPlayer
bool resetTrajectoryPlayer(bool moveToFrameZeroPose, const Ice::Current &) override
Definition: TrajectoryPlayer.cpp:223
armarx::TrajectoryPlayer::runningTime
double runningTime
Definition: TrajectoryPlayer.h:321
armarx::TrajectoryPlayer::setLoopPlayback
void setLoopPlayback(bool loop, const Ice::Current &) override
Definition: TrajectoryPlayer.cpp:368
armarx::VariantType::Long
const VariantTypeId Long
Definition: Variant.h:918
armarx::TrajectoryPlayer::updateTargetValues
void updateTargetValues()
Definition: TrajectoryPlayer.cpp:134
armarx::TrajectoryPlayer::pauseTrajectoryPlayer
bool pauseTrajectoryPlayer(const Ice::Current &) override
Definition: TrajectoryPlayer.cpp:77
armarx::TrajectoryPlayer::checkJointsLimit
bool checkJointsLimit()
Definition: TrajectoryPlayer.cpp:739
armarx::TrajectoryPlayer::checkSelfCollision
bool checkSelfCollision()
Definition: TrajectoryPlayer.cpp:786
armarx::TrajectoryPlayer::reportJointVelocities
void reportJointVelocities(const NameValueMap &, Ice::Long, bool, const Ice::Current &) override
Definition: TrajectoryPlayer.h:233
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
armarx::TrajectoryPlayer::jointNamesUsed
std::map< std::string, bool > jointNamesUsed
Definition: TrajectoryPlayer.h:315
Component.h
armarx::Component
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition: Component.h:91
armarx::TrajectoryPlayer::isPreview
bool isPreview
Definition: TrajectoryPlayer.h:327
PIDController.h
armarx::control::njoint_controller::platform::platform_follower_controller::NameValueMap
std::map< std::string, float > NameValueMap
Definition: PlatformFollowerController.h:88
armarx::TrajectoryPlayer::reportJointAngles
void reportJointAngles(const NameValueMap &angles, Ice::Long, bool, const Ice::Current &) override
Definition: TrajectoryPlayer.cpp:405
Trajectory.h
armarx::TrajectoryPlayer::robotPoseUnitEnabled
bool robotPoseUnitEnabled
Definition: TrajectoryPlayer.h:309
armarx::TrajectoryPlayer::motionStartTime
IceUtil::Time motionStartTime
Definition: TrajectoryPlayer.h:333
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:69
armarx::TrajectoryPlayer::reportJointTorques
void reportJointTorques(const NameValueMap &, Ice::Long, bool, const Ice::Current &) override
Definition: TrajectoryPlayer.h:238
armarx::TrajectoryPlayer::jointOffets
NameValueMap jointOffets
Definition: TrajectoryPlayer.h:336
armarx::TrajectoryPlayer::reportJointStatuses
void reportJointStatuses(const NameStatusMap &, Ice::Long, bool, const Ice::Current &) override
Definition: TrajectoryPlayer.h:261
armarx::TrajectoryPlayer::debugDrawer
DebugDrawerInterfacePrx debugDrawer
Definition: TrajectoryPlayer.h:306
IceUtil::Handle< class PropertyDefinitionContainer >
IceInternal::ProxyHandle<::IceProxy::armarx::DebugObserverInterface >
armarx::TrajectoryPlayer::targetRobotPose
PosePtr targetRobotPose
Definition: TrajectoryPlayer.h:331
armarx::TrajectoryPlayer::getDefaultName
std::string getDefaultName() const override
Definition: TrajectoryPlayer.h:134
armarx::TrajectoryPlayer::task
PeriodicTask< TrajectoryPlayer >::pointer_type task
Definition: TrajectoryPlayer.h:313
armarx::TrajectoryPlayer::timeOffset
double timeOffset
Definition: TrajectoryPlayer.h:323
armarx::TrajectoryPlayer::startTrajectoryPlayer
bool startTrajectoryPlayer(const Ice::Current &) override
Definition: TrajectoryPlayer.cpp:38
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:193
armarx::TrajectoryPlayer::setEndTime
void setEndTime(double end, const Ice::Current &) override
Definition: TrajectoryPlayer.h:180
armarx::TrajectoryPlayer::reportJointMotorTemperatures
void reportJointMotorTemperatures(const NameValueMap &, Ice::Long, bool, const Ice::Current &) override
Definition: TrajectoryPlayer.h:253
armarx::TrajectoryPlayer::reportJointCurrents
void reportJointCurrents(const NameValueMap &, Ice::Long, bool, const Ice::Current &) override
Definition: TrajectoryPlayer.h:248
armarx::TrajectoryPlayer::reportJointAccelerations
void reportJointAccelerations(const NameValueMap &, Ice::Long, bool, const Ice::Current &) override
Definition: TrajectoryPlayer.h:243
armarx::TrajectoryPlayer::setJointsInUse
bool setJointsInUse(const std::string &jointName, bool inUse, const Ice::Current &) override
Definition: TrajectoryPlayer.cpp:238
armarx::TrajectoryPlayer::getEndTime
double getEndTime(const Ice::Current &) override
Definition: TrajectoryPlayer.h:174
armarx::TrajectoryPlayer::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: TrajectoryPlayer.cpp:464
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:19
armarx::TrajectoryPlayer::PIDs
std::map< std::string, PIDControllerPtr > PIDs
Definition: TrajectoryPlayer.h:328
armarx::TrajectoryPlayer::loadBasePoseTraj
void loadBasePoseTraj(const TrajectoryBasePtr &trajs, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: TrajectoryPlayer.cpp:362
armarx::TrajectoryPlayer::basePoseTraj
::armarx::TrajectoryPtr basePoseTraj
Definition: TrajectoryPlayer.h:301
armarx::TrajectoryPlayer::getTrajEndTime
double getTrajEndTime(const Ice::Current &) override
Definition: TrajectoryPlayer.h:193
armarx::TrajectoryPlayer::onExitComponent
void onExitComponent() override
Definition: TrajectoryPlayer.cpp:459