7 VirtualRobot::RobotNodeSetPtr DesignerTrajectory::getRns()
12 void DesignerTrajectory::setRns(
const VirtualRobot::RobotNodeSetPtr&
value)
20 throw InvalidArgumentException(
"Can not set VirtualRobot::RobotNodeSetPtr rns = nullptr");
24 std::vector<TrajectoryPtr> DesignerTrajectory::getInterBreakpointTrajectories()
26 return interBreakpointTrajectories;
29 void DesignerTrajectory::setInterBreakpointTrajectories(
30 const std::vector<TrajectoryPtr>&
value)
32 if (
value.size() != 0)
34 interBreakpointTrajectories =
value;
38 throw InvalidArgumentException(
39 "Can not set std::vector<TrajectoryPtr> interBreakpointTrajectories with empty vector ");
45 VirtualRobot::RobotNodeSetPtr newRns)
47 if (newRns !=
nullptr)
53 throw InvalidArgumentException(
"Can not construct DesignerTrajectory with VirtualRobot::RobotNodeSetPtr rns = nullptr");
55 if (firstPoint !=
nullptr)
57 addFirstUserWaypoint(firstPoint);
61 throw InvalidArgumentException(
"Can not construct DesignerTrajectory with UserWaypointPtr firstPoint = nullptr");
64 std::vector<Ice::DoubleSeq>
data;
65 std::vector<double>
jointAngles = firstPoint->getJointAngles();
69 for (
unsigned int i = 0; i <
jointAngles.size(); i++)
76 throw InvalidArgumentException(
"firstPoint of a DesignerTrajectory must have jointAngles");
80 {0}, rns->getNodeNames())));
86 std::vector<TrajectoryPtr> trajectoriesTmp;
87 std::vector<UserWaypointPtr> userWaypointsTmp;
88 std::vector<TransitionPtr> transitionsTmp;
101 for (
unsigned int i = 0; i < userWaypointsTmp.size() - 1; i++)
110 userWaypoints = userWaypointsTmp;
111 interBreakpointTrajectories = trajectoriesTmp;
112 transitions = transitionsTmp;
117 if (point !=
nullptr)
119 userWaypoints.insert(userWaypoints.begin(), point);
121 if (userWaypoints.size() > 1)
124 new Transition(userWaypoints[0], userWaypoints[1])));
130 throw InvalidArgumentException(
"Can not add UserWaypoint with point = nullptr");
137 if (point !=
nullptr)
139 userWaypoints.push_back(point);
140 if (userWaypoints.size() > 1)
143 userWaypoints[userWaypoints.size() - 2],
144 userWaypoints[userWaypoints.size() - 1])));
149 throw InvalidArgumentException(
"Can not add UserWaypoint with point = nullptr");
156 if (point !=
nullptr)
158 if (
index != 0 &&
index < userWaypoints.size())
160 userWaypoints.insert(userWaypoints.begin() +
index, point);
162 if (userWaypoints.size() > 1)
164 transitions.insert(transitions.begin() +
index - 1,
167 userWaypoints[
index])));
168 transitions[
index]->setStart(userWaypoints[
index]);
179 throw IndexOutOfBoundsException(
"insertUserWaypoint");
185 throw InvalidArgumentException(
"Can not add UserWaypoint with point = nullptr");
192 if (
index < userWaypoints.size())
194 userWaypoints.erase(userWaypoints.begin() +
index);
198 transitions.erase(transitions.begin());
201 else if (
index == transitions.size())
203 transitions.erase(transitions.begin() +
index - 1);
207 transitions.erase(transitions.begin() +
index);
208 transitions.erase(transitions.begin() +
index - 1);
209 transitions.insert(transitions.begin() +
index - 1,
210 std::shared_ptr<Transition>(
212 userWaypoints[
index])));
217 throw IndexOutOfBoundsException(
"deleteUserWaypoint");
224 return userWaypoints.size();
229 if (
index < userWaypoints.size())
231 return userWaypoints[
index];
235 throw IndexOutOfBoundsException(
"getUserWaypoint");
242 if (
index < transitions.size())
244 return transitions[
index];
248 throw IndexOutOfBoundsException();
255 std::vector<Ice::DoubleSeq> dimensionDatas = getDimensionDatas();
256 Ice::DoubleSeq timestamps = getAllTimestamps();
258 interBreakpointTrajectories[0]->getDimensionNames()));
259 setLimitless(tmp, rns);
266 if (
index < interBreakpointTrajectories.size())
268 return interBreakpointTrajectories[
index];
272 throw IndexOutOfBoundsException();
279 std::vector <UserWaypointPtr> tmp;
281 for (
unsigned int i = 0; i < userWaypoints.size(); i++)
290 return userWaypoints;
295 if (userWaypoints.size() > 1)
298 std::vector<Ice::DoubleSeq> dimensionDatas = getDimensionDatas();
299 std::vector<double> timestamps = getAllTimestamps();
302 unsigned int count = 0;
303 for (
unsigned int i = 0; i < transitions.size() - 1; i++)
306 double stretch = t->getUserDuration() / t->getTimeOptimalDuration();
307 unsigned int start = count;
309 double endTime = t->getEnd()->getTimeOptimalTimestamp();
310 while (count + 1 < timestamps.size() && endTime > timestamps[count + 1])
314 unsigned int end = count;
315 for (
unsigned int k = start; k < end; k++)
317 timestamps[k + 1] = timestamps[k + 1] + tmpDif;
318 double oldDuration = timestamps[k + 1] - timestamps[k];
319 double newDuration = oldDuration * stretch;
320 tmpDif = tmpDif + newDuration - oldDuration;
321 timestamps[k + 1] = timestamps[k] + newDuration;
326 double stretch = t->getUserDuration() / t->getTimeOptimalDuration();
327 unsigned int start = count;
328 unsigned int end = timestamps.size() - 1;
329 for (
unsigned int k = start; k < end; k++)
331 timestamps[k + 1] = timestamps[k + 1] + tmpDif;
332 double oldDuration = timestamps[k + 1] - timestamps[k];
333 double newDuration = (timestamps[k + 1] - timestamps[k]) * stretch;
334 tmpDif = tmpDif + newDuration - oldDuration;
335 timestamps[k + 1] = timestamps[k] + newDuration;
339 interBreakpointTrajectories[0]->getDimensionNames()));
340 setLimitless(traj, rns);
346 return interBreakpointTrajectories[0];
352 std::vector<std::vector<double>> DesignerTrajectory::getDimensionDatas()
354 std::vector<Ice::DoubleSeq> dimensionDatas;
356 if (interBreakpointTrajectories.size() != 0)
359 for (
unsigned int i = 0; i < interBreakpointTrajectories[0]->dim(); i++)
362 dimensionDatas.push_back({interBreakpointTrajectories[0]->getDimensionData(i)[0]});
369 unsigned int dimension = t->dim();
370 for (
unsigned int i = 0; i < dimension; i++)
373 std::vector<double> newDatas = t->getDimensionData(i);
374 dimensionDatas[i].insert(dimensionDatas[i].end(),
375 newDatas.begin() + 1,
379 return dimensionDatas;
383 throw LogicError(
"No inter breakpoint trajectories");
388 std::vector<double> DesignerTrajectory::getAllTimestamps()
390 std::vector<double> timestamps;
392 if (interBreakpointTrajectories.size() != 0)
395 timestamps.push_back(interBreakpointTrajectories[0]->getTimestamps()[0]);
399 double d = timestamps.back();
400 std::vector<double> newTimestamps = t->getTimestamps();
401 for (
unsigned int i = 1; i < newTimestamps.size(); i++)
403 timestamps.push_back(newTimestamps[i] + d);
410 throw LogicError(
"No inter breakpoint trajectories");
414 void DesignerTrajectory::setLimitless(
TrajectoryPtr traj, VirtualRobot::RobotNodeSetPtr rns)
417 LimitlessStateSeq states;
418 for (VirtualRobot::RobotNodePtr node : rns->getAllRobotNodes())
420 LimitlessState state;
421 state.enabled = node->isLimitless();
422 state.limitLo = node->getJointLimitLow();
423 state.limitHi = node->getJointLimitHigh();
424 states.push_back(state);
426 traj->setLimitless(states);