LinearInterpolation.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 #include "LinearInterpolation.h"
23 
24 #include "../Util/OrientationConversion.h"
25 
26 ///EXCEPTIONS
27 #include "../exceptions/InterpolationNotDefinedException.h"
28 #include "../exceptions/NoInterpolationPossibleException.h"
29 ///ARMARX-INCLUDES
31 
32 using namespace armarx;
33 
34 LinearInterpolation::LinearInterpolation(std::vector<PoseBasePtr> controlPoints)
35 {
36  if (controlPoints.size() < 2)
37  {
39  }
41  for (unsigned int i = 0; i < this->controlPoints.size() - 1; i++)
42  {
43  PoseBasePtr current = this->controlPoints.at(i);
44  PoseBasePtr next = this->controlPoints.at(i + 1);
45  int deltaX = next->position->x - current->position->x;
46  int deltaY = next->position->y - current->position->y;
47  int deltaZ = next->position->z - current->position->z;
48  connectingVector.push_back(*new Eigen::Vector3f(deltaX, deltaY, deltaZ));
49  }
50 }
51 
52 PoseBasePtr
54 {
55  if (time < 0 || time > 1)
56  {
58  }
59 
60  int segment = time * (controlPoints.size() - 1);
61  if (time == 1)
62  {
64  }
65  double segmentRelativeTime =
66  (time - (1.0 / (controlPoints.size() - 1.0)) * segment) * (controlPoints.size() - 1);
67  PoseBasePtr current = controlPoints[segment];
68 
69  Eigen::Vector3f start =
70  Eigen::Vector3f(current->position->x, current->position->y, current->position->z);
71  Eigen::Vector3f transition = connectingVector[segment];
72  transition *= segmentRelativeTime;
73  Eigen::Vector3f position = start + transition;
74  return *new PoseBasePtr(
75  new Pose(*new Vector3BasePtr(new Vector3(position)), calculateOrientationAt(time)));
76 }
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
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::exceptions::local::NoInterpolationPossibleException
Definition: NoInterpolationPossibleException.h:39
FramedPose.h
armarx::LinearInterpolation::getPoseAt
PoseBasePtr getPoseAt(double time) override
getPoseAt returns the Pose defined by f(time)
Definition: LinearInterpolation.cpp:53
armarx::exceptions::local::InterpolationNotDefinedException
Definition: InterpolationNotDefinedException.h:40
LinearInterpolation.h
armarx::LinearInterpolation::LinearInterpolation
LinearInterpolation(std::vector< PoseBasePtr > controlPoints)
LinearInterpolation creates a new LinearInterPolation defined by controlPoints.
Definition: LinearInterpolation.cpp:34
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
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27