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
41namespace armarx
42{
43 /**
44 * @class TrajectoryPlayerPropertyDefinitions
45 * @brief
46 */
48 {
49 public:
52 {
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
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.");
65 "FPS",
66 100.0f,
67 "FPS with which the recording should be executed. Velocities will be adapted.");
69 "LoopPlayback", false, "Specify whether motion should be repeated after execution");
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");
78 "absMaximumVelocity",
79 120.0f,
80 "The PID will never set a velocity above this threshold (degree/s)");
82 "RobotNodeSetName",
83 "RobotState",
84 "The name of the robot node set to be used (only need for PIDController mode)");
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.");
95 "RobotPoseUnitName",
96 "RobotPoseUnit",
97 "Name of the RobotPoseUnit to which the robot position should be sent");
99 "Offset.x", 0.f, "x component of initial robot position (mm)");
101 "Offset.y", 0.f, "y component of initial robot position (mm)");
103 "Offset.z", 0.f, "z component of initial robot position (mm)");
105 "Offset.roll", 0.f, "Initial robot pose: roll component of RPY angles (radian)");
107 "Offset.pitch", 0.f, "Initial robot pose: pitch component of RPY angles (radian)");
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
253 reportJointMotorTemperatures(const NameValueMap&,
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
311 Eigen::Matrix4f offset;
312
314 Ice::StringSeq jointNames;
315 std::map<std::string, bool> jointNamesUsed;
316 std::map<std::string, bool> limitlessMap;
317
319
322 IceUtil::Time startTime;
324 double endTime;
325
328 std::map<std::string, PIDControllerPtr> PIDs;
332 NameValueMap nullVelocities;
333 IceUtil::Time motionStartTime;
334 // float start, end;
336 NameValueMap jointOffets;
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
Default component property definition container.
Definition Component.h:70
ComponentPropertyDefinitions(std::string prefix, bool hasObjectNameParameter=true)
Definition Component.cpp:46
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition Component.h:94
IceUtil::Handle< PeriodicTask< T > > pointer_type
Shared pointer type for convenience.
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
PropertyDefinition< PropertyType > & defineOptionalProperty(const std::string &name, PropertyType defaultValue, const std::string &description="", PropertyDefinitionBase::PropertyConstness constness=PropertyDefinitionBase::eConstant)
PropertyDefinition< PropertyType > & defineRequiredProperty(const std::string &name, const std::string &description="", PropertyDefinitionBase::PropertyConstness constness=PropertyDefinitionBase::eConstant)
Brief description of class TrajectoryPlayer.
void reportJointAccelerations(const NameValueMap &, Ice::Long, bool, const Ice::Current &) override
KinematicUnitInterfacePrx kinematicUnit
void setIsVelocityControl(bool isVelocity, const ::Ice::Current &=Ice::emptyCurrent) override
void setOffset(const Eigen::Matrix4f &offset, const Ice::Current &) override
std::map< std::string, PIDControllerPtr > PIDs
void reportJointStatuses(const NameStatusMap &, Ice::Long, bool, const Ice::Current &) override
bool pauseTrajectoryPlayer(const Ice::Current &) override
double getEndTime(const Ice::Current &) override
void reportJointAngles(const NameValueMap &angles, Ice::Long, bool, const Ice::Current &) override
void onDisconnectComponent() override
bool setJointsInUse(const std::string &jointName, bool inUse, const Ice::Current &) override
void considerConstraints(bool, const Ice::Current &) override
bool resetTrajectoryPlayer(bool moveToFrameZeroPose, const Ice::Current &) override
double getCurrentTime(const Ice::Current &) override
void reportJointCurrents(const NameValueMap &, Ice::Long, bool, const Ice::Current &) override
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
double getTrajEndTime(const Ice::Current &) override
void loadJointTraj(const TrajectoryBasePtr &trajs, const ::Ice::Current &=Ice::emptyCurrent) override
void reportControlModeChanged(const NameControlModeMap &, Ice::Long, bool, const Ice::Current &) override
void setIsPreview(bool isPreview, const Ice::Current &) override
bool startTrajectoryPlayer(const Ice::Current &) override
void reportJointMotorTemperatures(const NameValueMap &, Ice::Long, bool, const Ice::Current &) override
DebugObserverInterfacePrx debugObserver
std::map< std::string, bool > jointNamesUsed
std::map< std::string, bool > limitlessMap
void setLoopPlayback(bool loop, const Ice::Current &) override
VirtualRobot::RobotPtr localModel
bool stopTrajectoryPlayer(const Ice::Current &) override
PeriodicTask< TrajectoryPlayer >::pointer_type task
void reportJointVelocities(const NameValueMap &, Ice::Long, bool, const Ice::Current &) override
void setEndTime(double end, const Ice::Current &) override
void loadBasePoseTraj(const TrajectoryBasePtr &trajs, const ::Ice::Current &=Ice::emptyCurrent) override
void enableRobotPoseUnit(bool isRobotPose, const Ice::Current &) override
std::string getDefaultName() const override
DebugDrawerInterfacePrx debugDrawer
void reportJointTorques(const NameValueMap &, Ice::Long, bool, const Ice::Current &) override
::armarx::TrajectoryPtr basePoseTraj
::armarx::TrajectoryPtr jointTraj
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:193
std::shared_ptr< class Robot > RobotPtr
Definition Bus.h:19
This file offers overloads of toIce() and fromIce() functions for STL container types.
::IceInternal::ProxyHandle<::IceProxy::armarx::DebugObserverInterface > DebugObserverInterfacePrx
IceInternal::Handle< Trajectory > TrajectoryPtr
Definition Trajectory.h:52
IceInternal::Handle< Pose > PosePtr
Definition Pose.h:306
::IceInternal::Handle<::armarx::TrajectoryPlayer > TrajectoryPlayerPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
::IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface > DebugDrawerInterfacePrx