8 VirtualRobot::RobotNodeSetPtr
9 DesignerTrajectory::getRns()
15 DesignerTrajectory::setRns(
const VirtualRobot::RobotNodeSetPtr&
value)
23 throw InvalidArgumentException(
"Can not set VirtualRobot::RobotNodeSetPtr rns = nullptr");
27 std::vector<TrajectoryPtr>
28 DesignerTrajectory::getInterBreakpointTrajectories()
30 return interBreakpointTrajectories;
34 DesignerTrajectory::setInterBreakpointTrajectories(
const std::vector<TrajectoryPtr>&
value)
36 if (
value.size() != 0)
38 interBreakpointTrajectories =
value;
42 throw InvalidArgumentException(
"Can not set std::vector<TrajectoryPtr> "
43 "interBreakpointTrajectories with empty vector ");
48 VirtualRobot::RobotNodeSetPtr newRns)
50 if (newRns !=
nullptr)
56 throw InvalidArgumentException(
"Can not construct DesignerTrajectory with "
57 "VirtualRobot::RobotNodeSetPtr rns = nullptr");
59 if (firstPoint !=
nullptr)
61 addFirstUserWaypoint(firstPoint);
65 throw InvalidArgumentException(
66 "Can not construct DesignerTrajectory with UserWaypointPtr firstPoint = nullptr");
69 std::vector<Ice::DoubleSeq>
data;
70 std::vector<double>
jointAngles = firstPoint->getJointAngles();
74 for (
unsigned int i = 0; i <
jointAngles.size(); i++)
81 throw InvalidArgumentException(
"firstPoint of a DesignerTrajectory must have jointAngles");
84 interBreakpointTrajectories.push_back(
90 std::vector<TrajectoryPtr> trajectoriesTmp;
91 std::vector<UserWaypointPtr> userWaypointsTmp;
92 std::vector<TransitionPtr> transitionsTmp;
105 for (
unsigned int i = 0; i < userWaypointsTmp.size() - 1; i++)
114 userWaypoints = userWaypointsTmp;
115 interBreakpointTrajectories = trajectoriesTmp;
116 transitions = transitionsTmp;
122 if (point !=
nullptr)
124 userWaypoints.insert(userWaypoints.begin(), point);
126 if (userWaypoints.size() > 1)
128 transitions.insert(transitions.begin(),
134 throw InvalidArgumentException(
"Can not add UserWaypoint with point = nullptr");
141 if (point !=
nullptr)
143 userWaypoints.push_back(point);
144 if (userWaypoints.size() > 1)
147 userWaypoints[userWaypoints.size() - 2], userWaypoints[userWaypoints.size() - 1])));
152 throw InvalidArgumentException(
"Can not add UserWaypoint with point = nullptr");
159 if (point !=
nullptr)
161 if (
index != 0 &&
index < userWaypoints.size())
163 userWaypoints.insert(userWaypoints.begin() +
index, point);
165 if (userWaypoints.size() > 1)
168 transitions.begin() +
index - 1,
170 transitions[
index]->setStart(userWaypoints[
index]);
181 throw IndexOutOfBoundsException(
"insertUserWaypoint");
187 throw InvalidArgumentException(
"Can not add UserWaypoint with point = nullptr");
194 if (
index < userWaypoints.size())
196 userWaypoints.erase(userWaypoints.begin() +
index);
200 transitions.erase(transitions.begin());
203 else if (
index == transitions.size())
205 transitions.erase(transitions.begin() +
index - 1);
209 transitions.erase(transitions.begin() +
index);
210 transitions.erase(transitions.begin() +
index - 1);
211 transitions.insert(transitions.begin() +
index - 1,
212 std::shared_ptr<Transition>(
218 throw IndexOutOfBoundsException(
"deleteUserWaypoint");
225 return userWaypoints.size();
231 if (
index < userWaypoints.size())
233 return userWaypoints[
index];
237 throw IndexOutOfBoundsException(
"getUserWaypoint");
244 if (
index < transitions.size())
246 return transitions[
index];
250 throw IndexOutOfBoundsException();
257 std::vector<Ice::DoubleSeq> dimensionDatas = getDimensionDatas();
258 Ice::DoubleSeq timestamps = getAllTimestamps();
260 dimensionDatas, timestamps, interBreakpointTrajectories[0]->getDimensionNames()));
261 setLimitless(tmp, rns);
269 if (
index < interBreakpointTrajectories.size())
271 return interBreakpointTrajectories[
index];
275 throw IndexOutOfBoundsException();
279 std::vector<UserWaypointPtr>
282 std::vector<UserWaypointPtr> tmp;
284 for (
unsigned int i = 0; i < userWaypoints.size(); i++)
291 std::vector<UserWaypointPtr>
294 return userWaypoints;
300 if (userWaypoints.size() > 1)
303 std::vector<Ice::DoubleSeq> dimensionDatas = getDimensionDatas();
304 std::vector<double> timestamps = getAllTimestamps();
307 unsigned int count = 0;
308 for (
unsigned int i = 0; i < transitions.size() - 1; i++)
311 double stretch = t->getUserDuration() / t->getTimeOptimalDuration();
312 unsigned int start = count;
314 double endTime = t->getEnd()->getTimeOptimalTimestamp();
315 while (count + 1 < timestamps.size() && endTime > timestamps[count + 1])
319 unsigned int end = count;
320 for (
unsigned int k = start; k < end; k++)
322 timestamps[k + 1] = timestamps[k + 1] + tmpDif;
323 double oldDuration = timestamps[k + 1] - timestamps[k];
324 double newDuration = oldDuration * stretch;
325 tmpDif = tmpDif + newDuration - oldDuration;
326 timestamps[k + 1] = timestamps[k] + newDuration;
331 double stretch = t->getUserDuration() / t->getTimeOptimalDuration();
332 unsigned int start = count;
333 unsigned int end = timestamps.size() - 1;
334 for (
unsigned int k = start; k < end; k++)
336 timestamps[k + 1] = timestamps[k + 1] + tmpDif;
337 double oldDuration = timestamps[k + 1] - timestamps[k];
338 double newDuration = (timestamps[k + 1] - timestamps[k]) * stretch;
339 tmpDif = tmpDif + newDuration - oldDuration;
340 timestamps[k + 1] = timestamps[k] + newDuration;
343 dimensionDatas, timestamps, interBreakpointTrajectories[0]->getDimensionNames()));
344 setLimitless(traj, rns);
349 return interBreakpointTrajectories[0];
354 std::vector<std::vector<double>>
355 DesignerTrajectory::getDimensionDatas()
357 std::vector<Ice::DoubleSeq> dimensionDatas;
359 if (interBreakpointTrajectories.size() != 0)
362 for (
unsigned int i = 0; i < interBreakpointTrajectories[0]->dim(); i++)
365 dimensionDatas.push_back({interBreakpointTrajectories[0]->getDimensionData(i)[0]});
372 unsigned int dimension = t->dim();
373 for (
unsigned int i = 0; i < dimension; i++)
376 std::vector<double> newDatas = t->getDimensionData(i);
377 dimensionDatas[i].insert(
378 dimensionDatas[i].end(), newDatas.begin() + 1, newDatas.end());
381 return dimensionDatas;
385 throw LogicError(
"No inter breakpoint trajectories");
390 DesignerTrajectory::getAllTimestamps()
392 std::vector<double> timestamps;
394 if (interBreakpointTrajectories.size() != 0)
397 timestamps.push_back(interBreakpointTrajectories[0]->getTimestamps()[0]);
401 double d = timestamps.back();
402 std::vector<double> newTimestamps = t->getTimestamps();
403 for (
unsigned int i = 1; i < newTimestamps.size(); i++)
405 timestamps.push_back(newTimestamps[i] + d);
412 throw LogicError(
"No inter breakpoint trajectories");
417 DesignerTrajectory::setLimitless(
TrajectoryPtr traj, VirtualRobot::RobotNodeSetPtr rns)
420 LimitlessStateSeq states;
421 for (VirtualRobot::RobotNodePtr node : rns->getAllRobotNodes())
423 LimitlessState state;
424 state.enabled = node->isLimitless();
425 state.limitLo = node->getJointLimitLow();
426 state.limitHi = node->getJointLimitHigh();
427 states.push_back(state);
429 traj->setLimitless(states);