4 #include <VirtualRobot/TimeOptimalTrajectory/Path.h>
7 #define TRAJECTORYCALCULATION_TIMESTEP 0.001
18 if (!environment->getRobot()->hasRobotNodeSet(rns))
20 throw InvalidArgumentException(
"Robot does not have the supplied robotnodeset!");
26 if (path.getLength() == 0)
29 std::vector<double> timestamps;
31 for (
unsigned int i = 0; i < userPoints.size(); i ++)
33 timestamps.push_back(0.01 * i);
37 std::vector<std::vector<double>> nodeData;
38 for (
unsigned int i = 0; i < userPoints[0].size(); i++)
40 nodeData.push_back({userPoints[0][i]});
43 for (
unsigned int i = 1; i < userPoints.size(); i++)
45 for (
unsigned int j = 0; j < userPoints[0].size(); j++)
47 nodeData[j].push_back(userPoints[i][j]);
51 Ice::StringSeq dimensionNames = rns->getNodeNames();
63 std::vector<double> timestamps = std::vector<double>();
64 for (
unsigned int j = 0; j < trajectory.size(); j++)
66 timestamps.push_back(j * 0.01);
68 std::vector<std::vector<double>> nodeData = std::vector<std::vector<double>>();
69 for (
unsigned int i = 0; i < rns->getAllRobotNodes().size(); i++)
71 std::vector<double> node = std::vector<double>();
72 for (
unsigned int j = 0; j < trajectory.size(); j++)
74 node.push_back(trajectory[j][i]);
76 nodeData.push_back(node);
79 Ice::StringSeq dimensionNames = rns->getNodeNames();
83 LimitlessStateSeq state;
84 for (VirtualRobot::RobotNodePtr node : rns->getAllRobotNodes())
86 LimitlessState current;
87 current.enabled = node->isLimitless();
88 current.limitLo = node->getJointLimitLow();
89 current.limitHi = node->getJointLimitHigh();
90 state.push_back(current);
92 traj->setLimitless(state);
96 std::vector<std::vector<double>> newPathVector = std::vector<std::vector<double>>();
99 Eigen::MatrixXd trajMatrix = traj->toEigen();
100 for (
int i = 0; i < trajMatrix.rows(); i++)
103 std::vector<double> jA = std::vector<double>();
104 for (
int j = 0; j < trajMatrix.cols(); j++)
106 jA.push_back(trajMatrix(i, j));
109 newPathVector.push_back(jA);
116 std::vector<double> mVelocity;
117 std::vector<double> mAcceleration;
118 for (VirtualRobot::RobotNodePtr rn : rns->getAllRobotNodes())
120 if (rn->getMaxVelocity() == -1.0)
122 mVelocity.push_back(10);
126 mVelocity.push_back(rn->getMaxVelocity());
128 if (rn->getMaxAcceleration() == -1.0)
130 mAcceleration.push_back(10);
134 mAcceleration.push_back(rn->getMaxAcceleration());
138 const Eigen::VectorXd maxAcceleration =
Eigen::VectorXd::Map(&mAcceleration[0], mAcceleration.size());
144 VirtualRobot::TimeOptimalTrajectory timeOptimalTrajectory = VirtualRobot::TimeOptimalTrajectory(unfoldedPath, maxVelocity, maxAcceleration, timeStep / accuracyFactor);
146 if (timeOptimalTrajectory.isValid() == 0)
149 throw InvalidArgumentException(
"Input trajectory can not generate a continuous path");
152 if (timeOptimalTrajectory.getDuration() <= 0 || std::isnan(timeOptimalTrajectory.getDuration()) || timeOptimalTrajectory.getDuration() >= HUGE_VAL)
155 throw InvalidArgumentException(
"Input trajectory can not generate a continuous path with positive real duration");