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 AbstractInterpolation::calculateOrientationAt(double time)
37 {
38  if (time < 0 || time > 1)
39  {
41  }
42  int segment = time * (getNumberOfControlPoints() - 1);
43  double segmentRelativeTime = (time - (1.0 / (controlPoints.size() - 1.0)) * segment) * (controlPoints.size() - 1);
44  PoseBasePtr current = this->controlPoints.at(segment);
45  PoseBasePtr next = this->controlPoints.at(segment + 1);
46 
47  Eigen::Quaternion<double> ori1 = OrientationConversion::toEigen(current->orientation);
48  Eigen::Quaternion<double> ori2 = OrientationConversion::toEigen(next->orientation);
49  QuaternionBasePtr temp = OrientationConversion::toArmarX(ori1.slerp(segmentRelativeTime, ori2));
50  return temp;
51 }
52 
54 {
55  return controlPoints.size();
56 }
57 
58 void AbstractInterpolation::init(const std::vector<PoseBasePtr> cp)
59 {
60  for (unsigned int i = 0; i < cp.size(); i++)
61  {
62  this->controlPoints.push_back(deepCopy(cp[i]));
63 
64  }
65 }
66 
67 PoseBasePtr AbstractInterpolation::deepCopy(PoseBasePtr org)
68 
69 {
70  QuaternionPtr tempOri = QuaternionPtr(new Quaternion(org->orientation->qw, org->orientation->qx, org->orientation->qy, org->orientation->qz));
71  Vector3BasePtr tempPos = Vector3BasePtr(new Vector3(org->position->x, org->position->y, org->position->z));
72  return *new PoseBasePtr(new Pose(tempPos, tempOri));
73 }
74 
armarx::AbstractInterpolation::calculateOrientationAt
virtual const QuaternionBasePtr calculateOrientationAt(double time)
calculateOrientationAt calculates the rotation/orientation of the pose at a certain time
Definition: AbstractInterpolation.cpp:36
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:58
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:53
FramedPose.h
armarx::exceptions::local::InterpolationNotDefinedException
Definition: InterpolationNotDefinedException.h:42
armarx::QuaternionPtr
IceInternal::Handle< Quaternion > QuaternionPtr
Definition: Pose.h:234
armarx::OrientationConversion::toArmarX
static QuaternionBasePtr toArmarX(Eigen::Quaternion< double > q)
Definition: OrientationConversion.cpp:79
armarx::AbstractInterpolation::controlPoints
std::vector< PoseBasePtr > controlPoints
controlPoints the controlPoints that are interpolated between
Definition: AbstractInterpolation.h:57
memoryx::KBM::Vector3
Eigen::Vector3d Vector3
Definition: kbm.h:41
armarx::AbstractInterpolation::deepCopy
static PoseBasePtr deepCopy(PoseBasePtr org)
deepCopy creates a real, independent copy of a PoseBasePtr
Definition: AbstractInterpolation.cpp:67
armarx::OrientationConversion::toEigen
static Eigen::Quaternion< double > toEigen(QuaternionBasePtr q)
Definition: OrientationConversion.cpp:74
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28