24 #include <VirtualRobot/TimeOptimalTrajectory/TimeOptimalTrajectory.h>
30 using namespace MotionControlGroup;
40 double length = t->getLength(0);
46 double timelength = t->getTimeLength();
48 auto timestamps = t->getTimestamps();
50 Ice::DoubleSeq newTimestamps;
51 newTimestamps.push_back(0);
52 for (
size_t var = 0; var < timestamps.size() - 1; ++var)
54 double tBefore = timestamps.at(var);
55 double tAfter = (timestamps.at(var + 1));
57 double partLength = t->getLength(0, tBefore, tAfter);
58 double lengthPortion = partLength / length;
60 newTimestamps.push_back(*newTimestamps.rbegin() + timelength * lengthPortion);
64 for (
size_t d = 0; d < t->dim(); ++d)
66 newTraj->addDimension(t->getDimensionData(d), newTimestamps, t->getDimensionName(d));
82 double maxDeviation = in.getMaxDeviation();
83 double timeStep = in.getTimeStep();
84 float maxJointVelocity = in.getMaxJointVelocity();
85 float maxJointAcceleration = in.getMaxJointAcceleration();
87 Ice::StringSeq jointNames = inputTrajectory->getDimensionNames();
88 Eigen::VectorXd maxAccelerations(jointNames.size());
89 Eigen::VectorXd maxVelocities(jointNames.size());
90 for (
size_t i = 0; i < jointNames.size(); i++)
92 maxAccelerations(i) = maxJointAcceleration;
93 maxVelocities(i) = maxJointVelocity;
96 if (in.isMaxJointVelocitiesSet())
98 NameFloatMap maxJointVelocities = in.getMaxJointVelocities();
99 NameFloatMap::iterator itv;
101 for (std::string name : jointNames)
103 itv = maxJointVelocities.find(name);
104 maxVelocities(i) = (double)(itv != maxJointVelocities.end() ? itv->second : maxJointVelocity);
109 if (in.isMaxJointAccelerationsSet())
111 NameFloatMap maxJointAccelerations = in.getMaxJointAccelerations();
112 NameFloatMap::iterator ita;
114 for (std::string name : jointNames)
116 ita = maxJointAccelerations.find(name);
117 maxAccelerations(i) = (double)(ita != maxJointAccelerations.end() ? ita->second : maxJointAcceleration);
121 ARMARX_INFO <<
"Calculating time optimal trajectory: " << inputTrajectory->output();
122 auto timeOptimalTraj = inputTrajectory->calculateTimeOptimalTrajectory(maxVelocities, maxAccelerations, maxDeviation, IceUtil::Time::secondsDouble(timeStep));
123 ARMARX_INFO <<
"Done: " << timeOptimalTraj->output();
124 out.setTimeOptimalTrajectory(timeOptimalTraj);