DesignerTrajectoryPlayer.cpp
Go to the documentation of this file.
1
3
4#include <QTimer>
5
6
7using namespace armarx;
8using 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
21void
22DesignerTrajectoryPlayer::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
51void
56
57void
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
83void
85{
86 this->fps = fps;
87}
void setFPS(int fps)
setFPS sets the refresh rate of the player (the amount of updates of the visualization) to fps
void startPlayback()
startPlayback starts the actual visualization of the trajectory
void finishedPlayback()
finishedPlayback tells all relevant controllers that the trajectory playback has stopped
void addTrajectory(DesignerTrajectoryPtr trajectory)
addTrajectory inserts a trajetory to the DesignerTrajectory player All added Trajectories will be pla...
DesignerTrajectoryPlayer(RobotVisualizationPtr viewer, VirtualRobot::RobotPtr robot)
DesignerTrajectoryPlayer construct a new DesignerTrajectoryPlayer that can be started to play a Traje...
The Trajectory class represents n-dimensional sampled trajectories.
Definition Trajectory.h:77
std::shared_ptr< class Robot > RobotPtr
Definition Bus.h:19
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< Trajectory > TrajectoryPtr
Definition Trajectory.h:52
std::shared_ptr< DesignerTrajectory > DesignerTrajectoryPtr
std::shared_ptr< RobotVisualization > RobotVisualizationPtr