DesignerTrajectoryPlayer.cpp
Go to the documentation of this file.
1 
3 
4 #include <QTimer>
5 
6 
7 
8 using namespace armarx;
9 using namespace VirtualRobot;
10 
12 {
13  this->viewer = viewer;
14  this->robot = robot;
15  this->currentTime = 0;
16  this->fps = 60;
17  this->trajectories = std::vector<DesignerTrajectoryPtr>();
18  this->timeOptimalTrajectories = std::vector<TrajectoryPtr>();
19 }
20 
21 void DesignerTrajectoryPlayer::updateLoop()
22 {
23  bool endReached = true;
24  int i = 0;
25  //ARMARX_INFO << "AT TIME: " + std::to_string(currentTime);
26  for (TrajectoryPtr currentTrajectory : this->timeOptimalTrajectories)
27  {
28  if (!currentTrajectory)
29  {
30  continue;
31  }
32  if (currentTime < currentTrajectory->getTimeLength() * 1000)
33  {
34  Ice::DoubleSeq ice_JA = currentTrajectory->getStates(currentTime / 1000, 0);
35  //ARMARX_INFO << ice_JA;
36  std::vector<float> jA = std::vector<float>(ice_JA.begin(), ice_JA.end());
37  robot->getRobotNodeSet(trajectories[i]->getRns()->getName())->setJointValues(jA);
38  endReached = false;
39  }
40  i++;
41  }
42  viewer->updateRobotVisualization();
43  currentTime = currentTime + (1000.0 / fps);
44  if (endReached)
45  {
46  emit finishedPlayback();
47  }
48 
49 }
50 
52 {
53  this->trajectories.push_back(trajectory);
54 }
55 
57 {
58  //Setup timer
59  timer = std::shared_ptr<QTimer>(new QTimer(this));
60  connect(timer.get(), SIGNAL(timeout()), this, SLOT(updateLoop()));
61  connect(this, SIGNAL(finishedPlayback()), timer.get(), SLOT(stop()));
62 
63  //get all finalTrajectories
64  for (DesignerTrajectoryPtr current : trajectories)
65  {
66  if (current && current->getNrOfUserWaypoints() != 1)
67  {
68  TrajectoryPtr traj = current->getFinalTrajectory();
69  timeOptimalTrajectories.push_back(traj);
70  }
71  else
72  {
73  timeOptimalTrajectories.push_back(TrajectoryPtr(new Trajectory()));
74  }
75  }
76 
77  //start Timer
78  timer->start(1000.0 / fps);
79 }
80 
82 {
83  this->fps = fps;
84 }
85 
86 
armarx::TrajectoryPtr
IceInternal::Handle< Trajectory > TrajectoryPtr
Definition: Trajectory.h:52
VirtualRobot
Definition: FramedPose.h:43
IceInternal::Handle< Trajectory >
armarx::DesignerTrajectoryPlayer::DesignerTrajectoryPlayer
DesignerTrajectoryPlayer(RobotVisualizationPtr viewer, VirtualRobot::RobotPtr robot)
DesignerTrajectoryPlayer construct a new DesignerTrajectoryPlayer that can be started to play a Traje...
Definition: DesignerTrajectoryPlayer.cpp:11
armarx::DesignerTrajectoryPlayer::startPlayback
void startPlayback()
startPlayback starts the actual visualization of the trajectory
Definition: DesignerTrajectoryPlayer.cpp:56
armarx::VariantType::Trajectory
const VariantTypeId Trajectory
Definition: Trajectory.h:44
armarx::RobotVisualizationPtr
std::shared_ptr< RobotVisualization > RobotVisualizationPtr
Definition: RobotVisualization.h:161
armarx::DesignerTrajectoryPtr
std::shared_ptr< DesignerTrajectory > DesignerTrajectoryPtr
Definition: DesignerTrajectory.h:165
armarx::DesignerTrajectoryPlayer::setFPS
void setFPS(int fps)
setFPS sets the refresh rate of the player (the amount of updates of the visualization) to fps
Definition: DesignerTrajectoryPlayer.cpp:81
armarx::DesignerTrajectoryPlayer::addTrajectory
void addTrajectory(DesignerTrajectoryPtr trajectory)
addTrajectory inserts a trajetory to the DesignerTrajectory player All added Trajectories will be pla...
Definition: DesignerTrajectoryPlayer.cpp:51
DesignerTrajectoryPlayer.h
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