AbstractInterpolation.cpp
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package ArmarXGuiPlugins::RobotTrajectoryDesigner::Interpolation
17 * @author Timo Birr
18 * @date 2018
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22
24
25
26///ARMARX-INCLUDES
29
32
33
34using namespace armarx;
35
36const QuaternionBasePtr
38{
39 if (time < 0 || time > 1)
40 {
42 }
43 int segment = time * (getNumberOfControlPoints() - 1);
44 double segmentRelativeTime =
45 (time - (1.0 / (controlPoints.size() - 1.0)) * segment) * (controlPoints.size() - 1);
46 PoseBasePtr current = this->controlPoints.at(segment);
47 PoseBasePtr next = this->controlPoints.at(segment + 1);
48
49 Eigen::Quaternion<double> ori1 = OrientationConversion::toEigen(current->orientation);
50 Eigen::Quaternion<double> ori2 = OrientationConversion::toEigen(next->orientation);
51 QuaternionBasePtr temp = OrientationConversion::toArmarX(ori1.slerp(segmentRelativeTime, ori2));
52 return temp;
53}
54
55int
60
61void
62AbstractInterpolation::init(const std::vector<PoseBasePtr> cp)
63{
64 for (unsigned int i = 0; i < cp.size(); i++)
65 {
66 this->controlPoints.push_back(deepCopy(cp[i]));
67 }
68}
69
70PoseBasePtr
72
73{
75 org->orientation->qw, org->orientation->qx, org->orientation->qy, org->orientation->qz));
76 Vector3BasePtr tempPos =
77 Vector3BasePtr(new Vector3(org->position->x, org->position->y, org->position->z));
78 return *new PoseBasePtr(new Pose(tempPos, tempOri));
79}
virtual const QuaternionBasePtr calculateOrientationAt(double time)
calculateOrientationAt calculates the rotation/orientation of the pose at a certain time
int getNumberOfControlPoints()
getNumberOfControlPoints returns number of controlPoints
static PoseBasePtr deepCopy(PoseBasePtr org)
deepCopy creates a real, independent copy of a PoseBasePtr
void init(const std::vector< PoseBasePtr > cp)
init convinience method to construct the basic parts of the interpolation (copying all controlPoints)
std::vector< PoseBasePtr > controlPoints
controlPoints the controlPoints that are interpolated between
static Eigen::Quaternion< double > toEigen(QuaternionBasePtr q)
static QuaternionBasePtr toArmarX(Eigen::Quaternion< double > q)
The Pose class.
Definition Pose.h:243
The Quaternion class.
Definition Pose.h:174
The Vector3 class.
Definition Pose.h:113
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< Quaternion > QuaternionPtr
Definition Pose.h:234