32 #include "../exceptions/ControlPointsInterpolationMatchException.h"
33 #include "../exceptions/InterpolationNotDefinedException.h"
34 #include "../exceptions/NoInterpolationPossibleException.h"
39 std::vector<AbstractInterpolationPtr>
41 std::vector<PoseBasePtr> controlPoints,
42 std::vector<InterpolationType> interpolations)
44 if (controlPoints.size() != interpolations.size() + 1)
47 controlPoints.size(), interpolations.size());
50 std::vector<AbstractInterpolationPtr> producedInterpolations =
51 std::vector<AbstractInterpolationPtr>();
53 std::vector<int> interPolationChangePoints = std::vector<int>();
54 interPolationChangePoints.push_back(0);
62 int splineCounter = 0;
68 for (
unsigned int i = 1; i < interpolations.size(); i++)
74 if (current != interpolations.at(i))
78 if (splineCounter < 2)
84 interPolationChangePoints.push_back(i);
90 interPolationChangePoints.push_back(i);
92 current = interpolations[i];
95 if (interpolations.size() >= 2 &&
99 interpolations.pop_back();
119 for (
unsigned int j = 1; j < interPolationChangePoints.size(); j++)
121 std::vector<PoseBasePtr> currentCP = std::vector<PoseBasePtr>();
122 for (
int i = interPolationChangePoints.at(j - 1); i <= interPolationChangePoints.at(j); i++)
124 currentCP.push_back(controlPoints.at(i));
126 std::vector<AbstractInterpolationPtr> temp;
127 switch (interpolations.at(interPolationChangePoints.at(j - 1)))
130 temp = produceLinearInterpolationSegments(currentCP);
133 temp = produceSplineInterpolationSegments(currentCP);
136 producedInterpolations.insert(producedInterpolations.end(), temp.begin(), temp.end());
139 std::vector<PoseBasePtr> currentCP = std::vector<PoseBasePtr>();
140 for (
unsigned int i = interPolationChangePoints.at(interPolationChangePoints.size() - 1);
141 i < controlPoints.size();
144 currentCP.push_back(controlPoints.at(i));
146 std::vector<AbstractInterpolationPtr> temp;
147 switch (interpolations.at(interpolations.size() - 1))
150 temp = produceLinearInterpolationSegments(currentCP);
153 temp = produceSplineInterpolationSegments(currentCP);
156 producedInterpolations.insert(producedInterpolations.end(), temp.begin(), temp.end());
157 return producedInterpolations;
160 std::vector<AbstractInterpolationPtr>
162 std::vector<PoseBasePtr> controlPoints)
164 std::vector<AbstractInterpolationPtr> producedInterpolations =
165 std::vector<AbstractInterpolationPtr>();
166 for (
unsigned int i = 0; i < controlPoints.size() - 1; i++)
168 std::vector<PoseBasePtr> currentCP = std::vector<PoseBasePtr>();
169 currentCP.push_back(controlPoints.at(i));
170 currentCP.push_back(controlPoints.at(i + 1));
173 producedInterpolations.push_back(interpolation);
175 return producedInterpolations;
178 std::vector<AbstractInterpolationPtr>
180 std::vector<PoseBasePtr> controlPoints)
182 std::vector<AbstractInterpolationPtr> producedInterpolations =
183 std::vector<AbstractInterpolationPtr>();
187 for (
unsigned int i = 0; i < controlPoints.size() - 1; i++)
190 std::shared_ptr<AbstractInterpolation>(parent->getInterPolationSegment(i));
191 producedInterpolations.push_back(interpolation);
193 return producedInterpolations;
198 std::vector<PoseBasePtr> controlPoints,
199 PoseBasePtr segmentStart)
205 std::shared_ptr<AbstractInterpolation>(parent->getInterPolationSegment(segmentStart));
207 return interpolation;
217 std::vector<PoseBasePtr>& controlPoints,
218 std::vector<IKSolver::CartesianSelection>& selections)
227 for (
unsigned int i = 0; i < selections.size() - 1; i++)
232 std::vector<IKSolver::CartesianSelection> followingDominations =
233 std::vector<IKSolver::CartesianSelection>();
234 followingDominations.push_back(selections[i + 1]);
235 int followingDominationsStart = i;
240 for (
int j = i; j >= 0; j--)
243 selections[i + 1]) &&
246 selections[i + 1] == selections[j])
250 followingDominationsStart = j + 1;
252 int dominanceIntervalSize = i + 1 - j;
253 PoseBasePtr dominanceIntervalStart = controlPoints[j];
254 PoseBasePtr dominanceIntervalEnd = controlPoints[i + 1];
255 std::vector<AbstractInterpolationPtr> li =
256 produceLinearInterpolationSegments(
257 {dominanceIntervalStart, dominanceIntervalEnd});
259 for (
unsigned int k = j + 1; k < i + 1; k++)
261 controlPoints[k] = optimizePose(
263 li[0]->getPoseAt(
double(1.0 / dominanceIntervalSize) * counter),
271 followingDominations.push_back(selections[j]);
274 if (i + 2 < selections.size() &&
275 isDominantOver(selections[i + 2], selections[i + 1]))
279 followingDominations.push_back(selections[i + 1]);
286 }
while (!isBreaking);
293 getSmallestDominating(followingDominations);
294 for (
unsigned int m = followingDominationsStart; m <= i + 1; m++)
297 selections[m] = dominatingSelection;
317 for (
unsigned int i = 0; i < selections.size() - 1; i++)
332 if (other == IKSolver::CartesianSelection::X || other == IKSolver::CartesianSelection::Y ||
333 other == IKSolver::CartesianSelection::Z ||
336 return current != other;
341 current == IKSolver::CartesianSelection::All);
348 std::vector<VirtualRobot::IKSolver::CartesianSelection> selections)
350 bool isInhomogenous =
false;
360 if (
max != 0 && current !=
max)
362 isInhomogenous =
true;
365 if (
max <= 4 && isInhomogenous)
379 return IKSolver::CartesianSelection::All;
395 PoseBasePtr corrected,
401 PoseBasePtr firstStep;
402 switch (selectionCorrecting)
404 case (IKSolver::CartesianSelection::X):
405 firstStep = PoseBasePtr(
407 corrected->position->x, original->position->y, original->position->z)),
408 original->orientation));
409 case (IKSolver::CartesianSelection::Y):
410 firstStep = PoseBasePtr(
412 original->position->x, corrected->position->y, original->position->z)),
413 original->orientation));
414 case (IKSolver::CartesianSelection::Z):
415 firstStep = PoseBasePtr(
417 original->position->x, original->position->y, corrected->position->z)),
418 original->orientation));
420 firstStep = PoseBasePtr(
new Pose(corrected->position, original->orientation));
422 firstStep = PoseBasePtr(
new Pose(original->position, corrected->orientation));
423 case (IKSolver::CartesianSelection::All):
425 firstStep = corrected;
427 switch (selectionOriginal)
429 case (IKSolver::CartesianSelection::X):
430 return PoseBasePtr(
new Pose(Vector3BasePtr(
new Vector3(original->position->x,
431 firstStep->position->y,
432 firstStep->position->z)),
433 firstStep->orientation));
434 case (IKSolver::CartesianSelection::Y):
435 return PoseBasePtr(
new Pose(Vector3BasePtr(
new Vector3(firstStep->position->x,
436 original->position->y,
437 firstStep->position->z)),
438 firstStep->orientation));
439 case (IKSolver::CartesianSelection::Z):
440 return PoseBasePtr(
new Pose(Vector3BasePtr(
new Vector3(firstStep->position->x,
441 firstStep->position->y,
442 original->position->z)),
443 firstStep->orientation));
445 return PoseBasePtr(
new Pose(original->position, firstStep->orientation));
447 return PoseBasePtr(
new Pose(firstStep->position, original->orientation));
448 case (IKSolver::CartesianSelection::All):