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