25 #include <VirtualRobot/TimeOptimalTrajectory/TimeOptimalTrajectory.h>
31 using namespace MotionControlGroup;
37 TransformTrajectoryIntoTimeOptimal::GetName(),
44 double length = t->getLength(0);
50 double timelength = t->getTimeLength();
52 auto timestamps = t->getTimestamps();
54 Ice::DoubleSeq newTimestamps;
55 newTimestamps.push_back(0);
56 for (
size_t var = 0; var < timestamps.size() - 1; ++var)
58 double tBefore = timestamps.at(var);
59 double tAfter = (timestamps.at(var + 1));
61 double partLength = t->getLength(0, tBefore, tAfter);
62 double lengthPortion = partLength / length;
64 newTimestamps.push_back(*newTimestamps.rbegin() + timelength * lengthPortion);
68 for (
size_t d = 0; d < t->dim(); ++d)
70 newTraj->addDimension(t->getDimensionData(d), newTimestamps, t->getDimensionName(d));
87 double maxDeviation = in.getMaxDeviation();
88 double timeStep = in.getTimeStep();
89 float maxJointVelocity = in.getMaxJointVelocity();
90 float maxJointAcceleration = in.getMaxJointAcceleration();
92 Ice::StringSeq jointNames = inputTrajectory->getDimensionNames();
93 Eigen::VectorXd maxAccelerations(jointNames.size());
94 Eigen::VectorXd maxVelocities(jointNames.size());
95 for (
size_t i = 0; i < jointNames.size(); i++)
97 maxAccelerations(i) = maxJointAcceleration;
98 maxVelocities(i) = maxJointVelocity;
101 if (in.isMaxJointVelocitiesSet())
103 NameFloatMap maxJointVelocities = in.getMaxJointVelocities();
104 NameFloatMap::iterator itv;
106 for (std::string name : jointNames)
108 itv = maxJointVelocities.find(name);
110 (double)(itv != maxJointVelocities.end() ? itv->second : maxJointVelocity);
115 if (in.isMaxJointAccelerationsSet())
117 NameFloatMap maxJointAccelerations = in.getMaxJointAccelerations();
118 NameFloatMap::iterator ita;
120 for (std::string name : jointNames)
122 ita = maxJointAccelerations.find(name);
123 maxAccelerations(i) =
124 (double)(ita != maxJointAccelerations.end() ? ita->second : maxJointAcceleration);
128 ARMARX_INFO <<
"Calculating time optimal trajectory: " << inputTrajectory->output();
129 auto timeOptimalTraj = inputTrajectory->calculateTimeOptimalTrajectory(
130 maxVelocities, maxAccelerations, maxDeviation, IceUtil::Time::secondsDouble(timeStep));
131 ARMARX_INFO <<
"Done: " << timeOptimalTraj->output();
132 out.setTimeOptimalTrajectory(timeOptimalTraj);