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 
23 #include "AbstractInterpolation.h"
24 
25 
26 ///ARMARX-INCLUDES
29 
30 #include "../Util/OrientationConversion.h"
31 #include "../exceptions/InterpolationNotDefinedException.h"
32 
33 
34 using namespace armarx;
35 
36 const 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 
55 int
57 {
58  return controlPoints.size();
59 }
60 
61 void
62 AbstractInterpolation::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 
70 PoseBasePtr
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 }
armarx::AbstractInterpolation::calculateOrientationAt
virtual const QuaternionBasePtr calculateOrientationAt(double time)
calculateOrientationAt calculates the rotation/orientation of the pose at a certain time
Definition: AbstractInterpolation.cpp:37
MathUtils.h
armarx::navigation::core::Pose
Eigen::Isometry3f Pose
Definition: basic_types.h:31
armarx::AbstractInterpolation::init
void init(const std::vector< PoseBasePtr > cp)
init convinience method to construct the basic parts of the interpolation (copying all controlPoints)
Definition: AbstractInterpolation.cpp:62
armarx::VariantType::Quaternion
const VariantTypeId Quaternion
Definition: Pose.h:39
IceInternal::Handle< Quaternion >
AbstractInterpolation.h
armarx::AbstractInterpolation::getNumberOfControlPoints
int getNumberOfControlPoints()
getNumberOfControlPoints returns number of controlPoints
Definition: AbstractInterpolation.cpp:56
FramedPose.h
armarx::exceptions::local::InterpolationNotDefinedException
Definition: InterpolationNotDefinedException.h:40
armarx::QuaternionPtr
IceInternal::Handle< Quaternion > QuaternionPtr
Definition: Pose.h:234
armarx::OrientationConversion::toArmarX
static QuaternionBasePtr toArmarX(Eigen::Quaternion< double > q)
Definition: OrientationConversion.cpp:82
armarx::AbstractInterpolation::controlPoints
std::vector< PoseBasePtr > controlPoints
controlPoints the controlPoints that are interpolated between
Definition: AbstractInterpolation.h:56
memoryx::KBM::Vector3
Eigen::Vector3d Vector3
Definition: kbm.h:43
armarx::AbstractInterpolation::deepCopy
static PoseBasePtr deepCopy(PoseBasePtr org)
deepCopy creates a real, independent copy of a PoseBasePtr
Definition: AbstractInterpolation.cpp:71
armarx::OrientationConversion::toEigen
static Eigen::Quaternion< double > toEigen(QuaternionBasePtr q)
Definition: OrientationConversion.cpp:76
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27