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