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