30 #include <VirtualRobot/TimeOptimalTrajectory/TimeOptimalTrajectory.h>
45 dataVec.reserve(
dim());
46 for (
const auto& it : *
this)
48 std::vector< DoubleSeqPtr >&
data = it.data;
49 DoubleSeqSeq new2DVec;
50 new2DVec.reserve(
data.size());
55 new2DVec.emplace_back(*subVec);
59 new2DVec.emplace_back(Ice::DoubleSeq());
62 dataVec.emplace_back(new2DVec);
71 for (DoubleSeqSeq& _2DVec : dataVec)
74 double t = timestamps.at(i);
76 for (
auto& vec : _2DVec)
88 Ice::StringSeq columnContent;
92 for (
int col = 0; col < cols; col++)
96 for (
int row = 0; row < rows; row++)
98 ss << m(row, col) << (row < rows - 1 ?
"," :
"");
101 columnContent.push_back(ss.str());
104 obj->setStringArray(
"dimensionData", columnContent);
105 obj->setStringArray(
"dimensionNames", dimensionNames);
112 Ice::StringSeq rowContent;
113 obj->getStringArray(
"dimensionData", rowContent);
115 Ice::DoubleSeq timestamps;
116 obj->getDoubleArray(
"timestamps", timestamps);
117 for (
const auto& row : rowContent)
120 Ice::DoubleSeq newRow;
121 newRow.reserve(
values.size());
124 newRow.push_back(atof(
v.c_str()));
128 obj->getStringArray(
"dimensionNames", dimensionNames);
147 typename ordered_view::const_iterator itMap = ordv.begin();
149 s <<
"Dimensions names: \n";
150 for (
size_t i = 0; i < dimensionNames.size(); i++)
152 s << dimensionNames.at(i) << (i < limitless.size() && limitless.at(i).enabled ?
" Limitless " :
"") <<
"\n";
155 for (; itMap != ordv.end(); itMap++)
157 s << *itMap << std::endl;
190 if (
data.size() == 0)
195 typename std::map<double, Ice::DoubleSeq >::const_iterator it =
data.begin();
197 for (; it !=
data.end(); it++)
201 const Ice::DoubleSeq& dataVec = it->second;
203 for (
double i : dataVec)
206 dataEntry.
data.push_back(std::make_shared<Ice::DoubleSeq>(1, i));
208 dataMap.insert(std::move(dataEntry));
229 throw LocalException() <<
"dimension is to big: " <<
dim <<
" max: " << this->
dim();
232 typename timestamp_view::iterator it =
dataMap.find(t);
234 if (it ==
dataMap.end() ||
dim >= it->data.size() || !it->data.at(
dim) || it->data.at(
dim)->size() <= derivation)
241 if (it->data.size() <=
dim)
245 throw LocalException() <<
"std::vector ptr is not the correct size!? " <<
VAROUT(
dim) <<
VAROUT(it->data.size());
248 if (!it->data.at(
dim))
251 throw LocalException() <<
"std::vector ptr is NULL!?";
256 std::vector<DoubleSeqPtr>& vec = it->data;
258 if (derivation != 0 && vec.at(
dim)->size() <= derivation)
264 size_t curDeriv = vec.at(
dim)->size();
266 vec.at(
dim)->resize(derivation + 1);
268 while (curDeriv <= derivation)
272 vec.at(
dim)->at(curDeriv) = derivValue;
280 double result = vec.at(
dim)->at(derivation);
290 throw LocalException() <<
"dimension is to big: " <<
dim <<
" max: " << this->
dim();
293 typename timestamp_view::iterator it =
dataMap.find(t);
309 double result = it->data.at(
dim)->at(derivation);
320 std::vector<Ice::DoubleSeq> res;
322 for (
size_t i = 0; i <
dim(); i++)
324 Ice::DoubleSeq curdata;
326 for (
int deri = 0; deri <= maxDeriv; deri++)
328 curdata.push_back(
getState(t, i, deri));
331 res.push_back(curdata);
339 if (dimension >=
dim())
341 throw LocalException() <<
"Dimension out of bounds: requested: " << dimension <<
" available: " <<
dim();
344 Ice::DoubleSeq result;
346 for (
size_t i = 0; i <= derivations; i++)
348 result.push_back(
getState(t, dimension, i));
356 return dimensionNames.at(
dim);
361 return dimensionNames;
372 if (dimension >=
dim())
374 throw LocalException(
"dimension is out of range: ") << dimension <<
" actual dimensions: " <<
dim();
377 Ice::DoubleSeq result;
380 typename ordered_view::const_iterator itMap = ordv.begin();
382 for (; itMap != ordv.end(); itMap++)
385 result.push_back(itMap->getDeriv(dimension, derivation));
402 if (dimension >=
dim())
404 throw LocalException(
"dimension is out of range: ") << dimension <<
" actual dimensions: " <<
dim();
407 Ice::DoubleSeq result;
410 ordered_view::iterator itO = ordv.lower_bound(startTime);
411 ordered_view::iterator itOEnd = ordv.upper_bound(endTime);
415 for (; itO != itOEnd && i <
size(); itO++, i++)
418 result.push_back(itO->getDeriv(dimension, derivation));
423 Eigen::VectorXd resultVec(result.size());
424 for (
size_t i = 0; i < result.size(); i++)
426 resultVec(i) = result[i];
433 Eigen::MatrixXd result(
size(),
dim());
436 ordered_view::iterator itO = ordv.lower_bound(startTime);
437 ordered_view::iterator itOEnd = ordv.upper_bound(endTime);
441 for (; itO != itOEnd; itO++, i++)
444 for (
size_t d = 0; d < itO->data.size(); d++)
446 result(i, d) = (itO->getDeriv(d, derivation));
457 return Eigen::MatrixXd();
467 ordered_view::iterator itO = ordv.lower_bound(startTime);
468 ordered_view::iterator itOEnd = ordv.upper_bound(endTime);
472 for (; itO != itOEnd; itO++, i++)
475 for (
size_t d = 0; d < itO->data.size(); d++)
477 Ice::DoubleSeq derivs;
478 for (
size_t i = 0; i < numberOfDerivations + 1; i++)
480 derivs.push_back(itO->getDeriv(d, i));
483 result->addDerivationsToDimension(d, itO->getTimestamp(), derivs);
499 return dataMap.begin()->data.size();
514 if (ordView.begin() != ordView.end())
516 return ordView.rbegin()->timestamp - ordView.begin()->timestamp;
537 ordered_view::const_iterator itO = ordv.lower_bound(startTime);
538 ordered_view::const_iterator itOEnd = ordv.upper_bound(endTime);
539 if (itO == ordv.end())
543 size_t dimensions =
dim();
544 Ice::DoubleSeq prevValue(dimensions);
545 for (
size_t d = 0; d < dimensions; ++d)
547 prevValue[d] =
getState(startTime, d, derivation);
552 double segmentLength = 0;
554 itO != itOEnd && itO != ordv.end();
558 if (itO->getTimestamp() >= endTime)
564 for (
size_t d = 0; d < dimensions; ++d)
566 value = itO->getDeriv(d, derivation);
567 double diff =
value - prevValue[d];
568 segmentLength += diff * diff;
569 prevValue[d] =
value;
571 length +=
sqrt(segmentLength);
576 for (
size_t d = 0; d < dimensions; ++d)
579 double diff =
value - prevValue[d];
580 segmentLength += diff * diff;
581 prevValue[d] =
value;
583 length +=
sqrt(segmentLength);
600 ordered_view::iterator itO = ordv.lower_bound(startTime);
601 ordered_view::iterator itOEnd = ordv.upper_bound(endTime);
602 if (itO == ordv.end())
606 double prevValue =
getState(startTime, dimension, derivation);
609 itO != itOEnd && itO != ordv.end();
613 if (itO->getTimestamp() >= endTime)
617 length += fabs(prevValue - itO->getDeriv(dimension, derivation));
618 prevValue = itO->getDeriv(dimension, derivation);
620 length += fabs(prevValue -
getState(endTime, dimension, derivation));
633 ordered_view::iterator itO = ordv.lower_bound(startTime);
634 ordered_view::iterator itOEnd = ordv.upper_bound(endTime);
635 if (itO == ordv.end())
640 double prevValue = itO->getDeriv(dimension, derivation);
647 length += fabs(pow(prevValue, 2.0) - pow(itO->getDeriv(dimension, derivation), 2.0));
648 prevValue = itO->getDeriv(dimension, derivation);
654 double Trajectory::getMax(
size_t dimension,
size_t derivation,
double startTime,
double endTime)
const
659 double Trajectory::getMin(
size_t dimension,
size_t derivation,
double startTime,
double endTime)
const
664 double Trajectory::getWithFunc(
const double & (*foo)(
const double&,
const double&),
double initValue,
size_t dimension,
size_t derivation,
double startTime,
double endTime)
const
666 double bestValue = initValue;
668 ordered_view::iterator itO = ordv.lower_bound(startTime);
669 ordered_view::iterator itOEnd = ordv.upper_bound(endTime);
671 if (itO == ordv.end())
680 bestValue = foo(bestValue, itO->getDeriv(dimension, derivation));
688 return getMax(dimension, derivation, startTime, endTime) -
getMin(dimension, derivation, startTime, endTime);
693 Ice::DoubleSeq result;
695 ordered_view::iterator itO = ordv.lower_bound(startTime);
696 ordered_view::iterator itOEnd = ordv.upper_bound(endTime);
698 if (itO == ordv.end())
702 double preValue = itO->getDeriv(dimension, derivation);
709 double cur = itO->getDeriv(dimension, derivation);
711 if (itO == ordv.end())
715 double next = itO->getDeriv(dimension, derivation);
716 if (cur <= preValue && cur <= next)
718 result.push_back(cur);
728 Ice::DoubleSeq result;
730 ordered_view::iterator itO = ordv.lower_bound(startTime);
731 ordered_view::iterator itOEnd = ordv.upper_bound(endTime);
733 if (itO == ordv.end())
737 double preValue = itO->getDeriv(dimension, derivation);
744 double cur = itO->getDeriv(dimension, derivation);
746 if (itO == ordv.end())
750 double next = itO->getDeriv(dimension, derivation);
751 if (cur <= preValue && cur <= next)
753 result.push_back(itO->getTimestamp());
763 Ice::DoubleSeq result;
765 ordered_view::iterator itO = ordv.lower_bound(startTime);
766 ordered_view::iterator itOEnd = ordv.upper_bound(endTime);
768 if (itO == ordv.end())
772 double preValue = itO->getDeriv(dimension, derivation);
778 double cur = itO->getDeriv(dimension, derivation);
780 if (itO == ordv.end())
784 double next = itO->getDeriv(dimension, derivation);
785 if (cur >= preValue && cur >= next)
787 result.push_back(cur);
797 Ice::DoubleSeq result;
799 ordered_view::iterator itO = ordv.lower_bound(startTime);
800 ordered_view::iterator itOEnd = ordv.upper_bound(endTime);
802 if (itO == ordv.end())
806 double preValue = itO->getDeriv(dimension, derivation);
812 double cur = itO->getDeriv(dimension, derivation);
814 if (itO == ordv.end())
818 double next = itO->getDeriv(dimension, derivation);
820 if (cur >= preValue && cur >= next)
822 result.push_back(itO->getTimestamp());
837 std::vector<DoubleSeqPtr> result;
839 for (
size_t dimension = 0; dimension <
dim(); dimension++)
843 result.push_back(std::make_shared<Ice::DoubleSeq>(1, newValue));
852 typename timestamp_view::iterator it =
dataMap.find(t);
854 if (it ==
dataMap.end() || !it->data.at(dimension) || it->data.at(dimension)->size() <= derivation)
867 typename timestamp_view::const_iterator it =
dataMap.find(t);
869 if (it !=
dataMap.end() && it->data.size() ==
dim())
871 bool foundEmpty =
false;
873 for (
auto& i : it->data)
875 if (!i || i->empty())
905 typename timestamp_view::const_iterator it =
dataMap.find(t);
919 typename timestamp_view::const_iterator it =
dataMap.find(t);
935 size_t dimensions =
dim();
936 Ice::DoubleSeq result;
937 result.reserve(dimensions);
938 for (
size_t i = 0; i < dimensions; i++)
940 result.push_back(
getState(t, i, derivation));
949 std::map<double, Ice::DoubleSeq> res;
950 typename timestamp_view::iterator itMap =
dataMap.find(t);
954 for (
size_t i = 0; i <
dim(); i++)
956 res.insert(std::pair<double, Ice::DoubleSeq>(t, {itMap->data[i]->at(derivation)}));
964 typename ordered_view::iterator itNext = ordv.upper_bound(t);
966 typename ordered_view::iterator itPrev = itNext;
970 if (itPrev == ordv.end())
973 throw LocalException(
"Cannot find value at timestamp ") << t;
976 for (
size_t i = 0; i < extend; i++)
978 Ice::DoubleSeq preData =
getStates(itPrev->timestamp, derivation);
979 Ice::DoubleSeq nexData =
getStates(itNext->timestamp, derivation);
981 res.insert(std::pair<double, Ice::DoubleSeq>(itPrev->timestamp, preData));
982 res.insert(std::pair<double, Ice::DoubleSeq>(itNext->timestamp, nexData));
984 if (itPrev == ordv.begin() || itNext == ordv.end())
986 std::cout <<
"Warning: the timestamp is out of the range. " <<
987 "The current result will be returned" << std::endl;
1001 size_t dims = traj.
dim();
1004 for (
size_t d = 0; d < dims; ++d)
1015 size_t newDim =
dim() + 1;
1017 typename timestamp_view::iterator itMap =
dataMap.begin();
1019 for (; itMap !=
dataMap.end(); itMap++)
1021 itMap->data.resize(newDim);
1027 typename timestamp_view::iterator itMap =
dataMap.find(t);
1035 newData.
data[dimIndex] = std::make_shared<Ice::DoubleSeq>(y);
1036 dataMap.insert(std::move(newData));
1042 while (
dim() <= dimIndex)
1047 itMap->data.resize(
dim());
1049 itMap->data.at(dimIndex) = std::make_shared<Ice::DoubleSeq>(y);
1057 typename timestamp_view::iterator itMap =
dataMap.find(t);
1064 newData.
data[dimIndex] = std::make_shared<Ice::DoubleSeq>(1, y);
1071 while (
dim() <= dimIndex)
1076 itMap->data.resize(
dim());
1077 itMap->data.at(dimIndex) = std::make_shared<Ice::DoubleSeq>(1, y);
1086 typename ordered_view::const_iterator itMap = ordv.begin();
1088 for (; itMap != ordv.end(); itMap++)
1090 for (
size_t dimension = 0; dimension <
dim(); dimension++)
1092 if (!itMap->data[dimension])
1094 itMap->data[dimension] = std::make_shared<Ice::DoubleSeq>(
__interpolate(itMap, dimension, 0));
1105 Ice::DoubleSeq result;
1106 result.reserve(
size());
1108 typename ordered_view::const_iterator itMap = ordv.begin();
1110 for (; itMap != ordv.end(); itMap++)
1112 result.push_back(itMap->timestamp);
1120 Ice::FloatSeq result;
1121 result.reserve(
size());
1123 typename ordered_view::const_iterator itMap = ordv.begin();
1125 for (; itMap != ordv.end(); itMap++)
1127 result.push_back(itMap->timestamp);
1138 if (trajDimension >=
dim())
1140 throw LocalException(
"dimension is out of range: ") << trajDimension <<
" actual dimensions: " <<
dim();
1145 typename ordered_view::const_iterator itPrev = ordv.begin();
1147 typename ordered_view::const_iterator itCurrent = itPrev;
1149 typename ordered_view::const_iterator itNext = itCurrent;
1152 Ice::DoubleSeq result;
1154 for (; itCurrent != ordv.end();)
1156 if (itNext == ordv.end())
1163 DoubleSeqPtr prevStatePtr = itPrev->data[trajDimension];
1164 DoubleSeqPtr nextStatePtr = itNext->data[trajDimension];
1166 result.push_back((nextStatePtr->at(derivation) - prevStatePtr->at(derivation)) /
1167 (itNext->timestamp - itPrev->timestamp));
1171 itCurrent++, itPrev++, itNext++;
1173 if (itPrev == itCurrent)
1187 if (derivationCount < 0)
1189 throw LocalException(
"Negative derivation value is not allowed!");
1192 if (derivationCount == 0)
1197 Ice::DoubleSeq result;
1205 result.resize(
size);
1208 result[0] = (
values.at(1) -
values.at(0)) / (timestamps.at(1) - timestamps.at(0)) ;
1212 for (
int i = 1; i <
size - 1; ++i)
1214 result[i] = (
values.at(i + 1) -
values.at(i - 1)) / (timestamps.at(i + 1) - timestamps.at(i - 1)) ;
1218 if (derivationCount > 1)
1230 if (derivation == 0)
1232 return getState(t, trajDimension, derivation);
1235 typename timestamp_view::iterator it =
dataMap.find(t);
1238 typename ordered_view::iterator itCurrent = ordV.end();
1242 itCurrent = ordV.iterator_to(*it);
1245 typename ordered_view::iterator itNext = ordV.upper_bound(t);
1247 if (it !=
dataMap.end() && itNext == ordV.end())
1251 else if (itNext == ordV.end() && it ==
dataMap.end())
1253 throw LocalException() <<
"Cannot interpolate for t " << t <<
" no data in trajectory";
1256 typename ordered_view::iterator itPrev = itNext;
1259 if (itCurrent != ordV.end())
1264 if (itPrev == ordV.end())
1267 if (itCurrent != ordV.end())
1273 throw LocalException() <<
"Cannot interpolate for t " << t;
1277 if (itNext == ordV.end())
1280 if (itCurrent != ordV.end())
1286 throw LocalException() <<
"Cannot interpolate for t " << t;
1290 if (itNext == itPrev)
1292 throw LocalException() <<
"Interpolation failed: the next data and the previous are missing.\nInfo:\n" <<
VAROUT(t) <<
VAROUT(trajDimension) << (
getDimensionName(trajDimension)) <<
" " <<
VAROUT(
size());
1298 if (
dataExists(itNext->timestamp, trajDimension, derivation - 1) || derivation > 1)
1300 tNext = itNext->timestamp;
1307 double next =
getState(tNext, trajDimension, derivation - 1);
1311 if (
dataExists(itPrev->timestamp, trajDimension, derivation - 1) || derivation > 1)
1313 tBefore = itPrev->timestamp;
1320 double before =
getState(tBefore, trajDimension, derivation - 1);
1322 if (fabs(tNext - tBefore) < 1e-10)
1327 double duration = tNext - tBefore;
1330 if (trajDimension < limitless.size() && limitless.at(trajDimension).enabled)
1332 double range = limitless.at(trajDimension).limitHi - limitless.at(trajDimension).limitLo;
1334 double dist1 = next - before;
1335 double dist2 = next - (before + range);
1336 double dist3 = next - (before - range);
1338 if (fabs(dist1) <= fabs(dist2) && fabs(dist1) <= fabs(dist3))
1344 else if (fabs(dist2) <= fabs(dist3) && fabs(dist2) <= fabs(dist3))
1362 delta = next - before;
1365 delta = delta / duration;
1374 for (
size_t d = 0; d <
dim(); d++)
1383 typename ordered_view::iterator itOrd =
begin();
1385 for (; itOrd !=
end(); itOrd++)
1387 getState(itOrd->timestamp, trajDimension, derivation);
1395 typename ordered_view::iterator it = ordv.begin();
1397 if (it == ordv.end())
1402 it->data[trajDimension]->at(targetDimOfSystemState) = valueAtFirstTimestamp;
1403 double previousValue = valueAtFirstTimestamp;
1404 double previousTimestamp = it->timestamp;
1407 for (it++; it != ordv.end(); it++)
1410 if (it->data[trajDimension]->size() > sourceDimOfSystemState)
1412 slope = it->data[trajDimension]->at(sourceDimOfSystemState);
1419 double diff = it->timestamp - previousTimestamp;
1420 it->data[trajDimension]->at(targetDimOfSystemState) = previousValue + diff * slope;
1421 previousTimestamp = it->timestamp;
1422 previousValue = it->data[trajDimension]->at(targetDimOfSystemState);
1430 if (trajDimension >=
dim())
1432 throw LocalException(
"dimension is out of range: ") << trajDimension <<
" actual dimensions: " <<
dim();
1439 for (
const auto& it : ordv)
1441 (*it.data.at(trajDimension)) *= -1;
1452 typename timestamp_view::const_iterator it =
dataMap.find(t);
1454 if (it !=
dataMap.end() && it->data.size() > dimension && it->data.at(dimension) && it->data.at(dimension)->size() > derivation)
1456 return it->data.at(dimension)->at(derivation);
1461 typename ordered_view::iterator itNext = ordv.upper_bound(t);
1463 typename ordered_view::iterator itPrev = itNext;
1467 double result =
__interpolate(t, itPrev, itNext, dimension, derivation);
1477 typename ordered_view::iterator itPrev = itMap;
1479 typename ordered_view::iterator itNext = itMap;
1481 return __interpolate(itMap->timestamp, itPrev, itNext, dimension, derivation);
1485 Trajectory::__interpolate(
double t,
typename ordered_view::const_iterator itPrev,
typename ordered_view::const_iterator itNext,
size_t dimension,
size_t derivation)
const
1488 double previous = 0;
1492 while (itPrev != ordView.end() && (itPrev->data.at(dimension) ==
nullptr || itPrev->data.at(dimension)->size() <= derivation))
1497 if (itPrev != ordView.end())
1501 previous =
getState(itPrev->timestamp, dimension, derivation);
1505 while (itNext != ordView.end() && (!itNext->data.at(dimension) || itNext->data.at(dimension)->size() <= derivation))
1510 if (itNext != ordView.end())
1514 next =
getState(itNext->timestamp, dimension, derivation);
1519 if (itNext == ordView.end() && itPrev == ordView.end())
1521 throw LocalException() <<
"Cannot find next or prev values in dim " << dimension <<
" at timestamp " << t;
1524 if (itNext == ordView.end())
1527 return getState(itPrev->timestamp, dimension, derivation) +
getState(itPrev->timestamp, dimension, derivation + 1) * (t - itPrev->timestamp);
1529 else if (itPrev == ordView.end())
1532 return getState(itNext->timestamp, dimension, derivation) -
getState(itNext->timestamp, dimension, derivation + 1) * (itNext->timestamp - t);
1540 if (dimension < limitless.size() && limitless.at(dimension).enabled)
1559 for (
size_t d = 0; d <
dim(); d++)
1561 Ice::DoubleSeq entries;
1563 for (
typename ordered_view::iterator it = ordv.begin(); it != ordv.end(); it++)
1568 filteredTraj.addDimension(entries, timestamps);
1578 const double sigma = filterRadiusInTime / 2.5;
1580 double weightedSum = 0;
1581 double sumOfWeight = 0;
1582 ordered_view::iterator start = centerIt;
1584 const double sqrt2PI =
sqrt(2 *
M_PI);
1588 for (ordered_view::iterator it = start;
1590 && fabs(it->timestamp - centerIt->timestamp) <= fabs(filterRadiusInTime * 2);
1594 value = it->getDeriv(trajNum,
dim);
1595 double diff = (it->timestamp - centerIt->timestamp);
1596 double squared = diff * diff;
1597 const double gaussValue = exp(-squared / (2 * sigma * sigma)) / (sigma * sqrt2PI);
1598 sumOfWeight += gaussValue;
1599 weightedSum += gaussValue *
value;
1617 result = weightedSum / sumOfWeight;
1626 if (&
source == &destination)
1631 destination.
clear();
1633 Ice::DoubleSeq timestamps =
source.getTimestamps();
1656 dimensionNames.clear();
1665 if (startTime >= endTime)
1667 throw LocalException(
"startTime must be smaller than endTime.");
1670 Ice::DoubleSeq result;
1671 size_t size = std::round((endTime - startTime) / stepSize) + 1;
1672 stepSize = (endTime - startTime) / (
size - 1);
1673 result.reserve(
size);
1675 double currentTimestamp = startTime;
1680 result.push_back(currentTimestamp);
1681 currentTimestamp += stepSize;
1691 Ice::DoubleSeq normTimestamps;
1692 normTimestamps.resize(timestamps.size());
1693 const double minValue = *timestamps.
begin();
1694 const double maxValue = *timestamps.rbegin();
1695 const double duration = maxValue - minValue;
1697 for (
size_t i = 0; i < timestamps.size(); i++)
1699 normTimestamps[i] = startTime + (timestamps.at(i) - minValue) / duration * (endTime - startTime);
1702 return normTimestamps;
1709 if (traj.
size() <= 1 || (traj.
begin()->timestamp == startTime && traj.
rbegin()->timestamp == endTime))
1724 normExampleTraj.
addDimension(dimensionData, normTimestamps);
1728 return normExampleTraj;
1742 Eigen::VectorXd maxVelocities = Eigen::VectorXd::Constant(
dim(), maxVelocity);
1743 Eigen::VectorXd maxAccelerations = Eigen::VectorXd::Constant(
dim(), maxAcceleration);
1750 bool hasLimitlessDimension =
false;
1751 for (
auto l : limitless)
1753 hasLimitlessDimension |= l.enabled;
1757 if (hasLimitlessDimension)
1764 auto timestepValue = timestep.toSecondsDouble();
1765 std::list<Eigen::VectorXd> waypointList;
1766 auto dimensions =
dim();
1767 for (
auto& waypoint : hasLimitlessDimension ? *unfoldedTraj : *
this)
1769 auto positions = waypoint.getPositions();
1770 waypointList.push_back(Eigen::Map<Eigen::VectorXd>(positions.data(), dimensions));
1773 VirtualRobot::TimeOptimalTrajectory timeOptimalTraj(
VirtualRobot::Path(waypointList, maxDeviation),
1775 maxAccelerations, timestepValue);
1781 Ice::DoubleSeq newTimestamps;
1782 double duration = timeOptimalTraj.getDuration();
1783 newTimestamps.reserve(duration / timestepValue + 1);
1784 for (
double t = 0.0; t < duration; t += timestepValue)
1786 newTimestamps.push_back(t);
1788 newTimestamps.push_back(duration);
1790 for (
size_t d = 0; d < dimensionNames.size(); d++)
1792 Ice::DoubleSeq position;
1793 position.reserve(newTimestamps.size());
1794 for (
double t = 0.0; t < duration; t += timestepValue)
1796 position.push_back(timeOptimalTraj.getPosition(t)[d]);
1798 position.push_back(timeOptimalTraj.getPosition(duration)[d]);
1799 newTraj->addDimension(position, newTimestamps, dimensionNames.at(d));
1801 Ice::DoubleSeq derivs;
1802 derivs.reserve(newTimestamps.size());
1804 for (
double t = 0.0; t < duration; t += timestepValue)
1807 derivs.push_back(timeOptimalTraj.getPosition(t)[d]);
1808 derivs.push_back(timeOptimalTraj.getVelocity(t)[d]);
1809 newTraj->addDerivationsToDimension(d, t, derivs);
1812 derivs.push_back(timeOptimalTraj.getPosition(duration)[d]);
1813 derivs.push_back(timeOptimalTraj.getVelocity(duration)[d]);
1814 newTraj->addDerivationsToDimension(d, duration, derivs);
1816 newTraj->setLimitless(limitless);
1817 if (hasLimitlessDimension)
1836 size_t newDimIndex =
dim();
1841 if (newDimIndex < dimensionNames.size())
1843 dimensionNames.at(newDimIndex) = name;
1847 dimensionNames.push_back(name);
1854 typename timestamp_view::iterator itMap =
dataMap.begin();
1856 for (; itMap !=
dataMap.end(); itMap++)
1858 std::vector< DoubleSeqPtr >&
data = itMap->data;
1860 if (dimension <
data.size())
1862 data.erase(
data.begin() + dimension);
1865 if (dimension < dimensionNames.size())
1867 dimensionNames.erase(dimensionNames.begin() + dimension);
1873 typename timestamp_view::iterator itMap =
dataMap.begin();
1875 for (; itMap !=
dataMap.end(); itMap++)
1877 std::vector< DoubleSeqPtr >&
data = itMap->data;
1879 for (
auto& vec :
data)
1881 if (derivation + 1 < vec->size())
1883 vec->resize(derivation);
1891 typename timestamp_view::iterator itMap =
dataMap.begin();
1893 for (; itMap !=
dataMap.end(); itMap++)
1895 std::vector< DoubleSeqPtr >&
data = itMap->data;
1897 if (
data.size() > dimension && derivation + 1 <
data.at(dimension)->size())
1899 data.at(dimension)->resize(derivation);
1933 if (dimension >=
dim() &&
dim() > 0)
1941 for (
size_t i = 0; i < timestamps.size(); ++i)
1973 return getDeriv(
dim, 0);
1980 throw LocalException(
"Ptr to trajectory is NULL");
1982 size_t numDim = trajectory->dim();
1983 Eigen::VectorXf result(numDim);
1984 for (std::size_t i = 0; i < numDim; ++i)
1986 result(i) = getPosition(i);
1995 throw LocalException(
"Ptr to trajectory is NULL");
1997 size_t numDim = trajectory->dim();
1998 Eigen::VectorXd result(numDim);
1999 for (std::size_t i = 0; i < numDim; ++i)
2001 result(i) = getPosition(i);
2010 throw LocalException(
"Ptr to trajectory is NULL");
2012 return trajectory->getState(timestamp,
dim, derivation);
2026 typename ordered_view::const_iterator itMap = ordv.begin();
2030 for (; itMap != ordv.end(); itMap++)
2032 for (
size_t i = 0; i < d; ++i)
2034 shiftedTraj.
setEntries(itMap->timestamp + shift, i, *itMap->getData().at(i));
2038 *
this = shiftedTraj;
2043 if (shift.size() >
dim())
2045 throw LocalException(
"dimension is out of range: ") << shift.size() <<
" actual dimensions: " <<
dim();
2049 for (
size_t dimension = 0; dimension <
dim(); dimension++)
2052 typename ordered_view::const_iterator itMap = ordv.begin();
2054 for (; itMap != ordv.end(); itMap++)
2056 itMap->data[dimension]->at(0) += shift[dimension];
2064 if (factor.size() >
dim())
2066 throw LocalException(
"dimension is out of range: ") << factor.size() <<
" actual dimensions: " <<
dim();
2070 for (
size_t dimension = 0; dimension <
dim(); dimension++)
2073 typename ordered_view::const_iterator itMap = ordv.begin();
2075 for (; itMap != ordv.end(); itMap++)
2077 itMap->data[dimension]->at(0) *= factor[dimension];
2086 limitless = limitlessStates;