PlayJointTrajectory.cpp
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 RobotSkillTemplates::GraspingPipelineGroup
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 #include "PlayJointTrajectory.h"
27 
28 using namespace armarx;
29 using namespace GraspingPipelineGroup;
30 
31 // DO NOT EDIT NEXT LINE
32 PlayJointTrajectory::SubClassRegistry PlayJointTrajectory::Registry(PlayJointTrajectory::GetName(), &PlayJointTrajectory::CreateInstance);
33 
34 
35 
37 {
38  // put your user code for the enter-point here
39  // execution time should be short (<100ms)
40 }
41 
43 {
44  // put your user code for the execution-phase here
45  // runs in seperate thread, thus can do complex operations
46  // should check constantly whether isRunningTaskStopped() returns true
47 
48  // while (!isRunningTaskStopped()) // stop run function if returning true
49  // {
50  // // do your calculations
51  // }
52 
53  TrajectoryPlayerInterfacePrx trajectoryPlayer = getTrajectoryPlayer();
54 
55 
56  TrajectoryPtr trajectory = TrajectoryPtr::dynamicCast(in.getTrajectory());
57  if (trajectory->size() == 0)
58  {
59  emitFailure();
60  return;
61  }
62 
63  ARMARX_INFO << VAROUT(trajectory->output());
64  ARMARX_INFO << trajectory->getTimestamps();
65  JSONObjectPtr json = new JSONObject();
66  json->setVariant("trajectory", new Variant(trajectory));
67  ARMARX_INFO << "Json: " << json->asString(true);
68  trajectoryPlayer->resetTrajectoryPlayer(false);
69  trajectoryPlayer->loadJointTraj(trajectory);
70  trajectoryPlayer->loadBasePoseTraj(trajectory);
71  trajectoryPlayer->setIsVelocityControl(true);
72 
73  if (!in.getIsTimeOptimal())
74  {
75  size_t dim = trajectory->dim();
76 
77  double length = 0.0;
78  for (size_t i = 0; i < dim; i++)
79  {
80  double tempLength = trajectory->getLength(i, 0);
81  if (tempLength > length)
82  {
83  length = tempLength;
84  }
85  }
86  double speed = length * in.getPlayTimePer1Rad();
87 
88  ARMARX_INFO << trajectoryPlayer->getEndTime();
89  trajectoryPlayer->setEndTime(trajectory->begin()->getTimestamp() + trajectory->getTimeLength() * speed);
90  ARMARX_INFO << trajectoryPlayer->getEndTime();
91  }
92 
93  trajectoryPlayer->startTrajectoryPlayer();
94 
95  ARMARX_INFO << VAROUT(trajectory->output());
96  ARMARX_INFO << trajectory->getTimestamps();
97 
98  while (!isRunningTaskStopped()) // stop run function if returning true
99  {
100  if (this->getTrajectoryPlayer()->getCurrentTime() >= this->getTrajectoryPlayer()->getEndTime())
101  {
102  ARMARX_LOG << "emitSuccess()";
103  this->emitSuccess();
104  return;
105  }
106  //Wait 50ms
107  usleep(50000);
108  }
109 
110 
111 
112 }
113 
114 //void PlayJointTrajectory::onBreak()
115 //{
116 // // put your user code for the breaking point here
117 // // execution time should be short (<100ms)
118 //}
119 
121 {
122  // put your user code for the exit point here
123  // execution time should be short (<100ms)
124 }
125 
126 
127 // DO NOT EDIT NEXT FUNCTION
129 {
130  return XMLStateFactoryBasePtr(new PlayJointTrajectory(stateData));
131 }
132 
armarx::Variant
The Variant class is described here: Variants.
Definition: Variant.h:224
armarx::GraspingPipelineGroup::PlayJointTrajectory::run
void run() override
Definition: PlayJointTrajectory.cpp:42
JSONObject.h
armarx::JSONObject
The JSONObject class is used to represent and (de)serialize JSON objects.
Definition: JSONObject.h:43
armarx::XMLStateConstructorParams
Definition: XMLState.h:50
armarx::GraspingPipelineGroup::PlayJointTrajectory::CreateInstance
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
Definition: PlayJointTrajectory.cpp:128
IceInternal::Handle< Trajectory >
ManagedIceObject.h
armarx::GraspingPipelineGroup::PlayJointTrajectory::Registry
static SubClassRegistry Registry
Definition: PlayJointTrajectory.h:46
ARMARX_LOG
#define ARMARX_LOG
Definition: Logging.h:163
Component.h
armarx::GraspingPipelineGroup::PlayJointTrajectory::onEnter
void onEnter() override
Definition: PlayJointTrajectory.cpp:36
armarx::XMLStateFactoryBasePtr
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition: XMLState.h:65
armarx::GraspingPipelineGroup::PlayJointTrajectory::onExit
void onExit() override
Definition: PlayJointTrajectory.cpp:120
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
VAROUT
#define VAROUT(x)
Definition: StringHelpers.h:182
armarx::GraspingPipelineGroup::PlayJointTrajectory::PlayJointTrajectory
PlayJointTrajectory(const XMLStateConstructorParams &stateData)
Definition: PlayJointTrajectory.h:33
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
PlayJointTrajectory.h