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