SplineInterpolation.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 "SplineInterpolation.h"
24 
25 ///ARMARX-INCLUDES
27 ///EXCEPTIONS
28 #include "../exceptions/InterpolationNotDefinedException.h"
29 #include "../exceptions/NoInterpolationPossibleException.h"
30 
31 using namespace armarx;
32 using namespace alglib;
33 
34 SplineInterpolation::SplineInterpolation(std::vector<PoseBasePtr> controlPoints)
35 {
36  if (controlPoints.size() < static_cast<unsigned>(3))
37  {
38  throw exceptions::local::NoInterpolationPossibleException(2, controlPoints.size());
39  }
40  init(controlPoints);
41 
42  //Creating the Interpolation Functions for all parametric Splines (x,y,z -Coordinate)
43  alglib::pspline2build(getCoordinateArray(0), controlPoints.size(), 2, 0, xInterpolation);
44  alglib::pspline2build(getCoordinateArray(1), controlPoints.size(), 2, 0, yInterpolation);
45  alglib::pspline2build(getCoordinateArray(2), controlPoints.size(), 2, 0, zInterpolation);
46 }
47 PoseBasePtr SplineInterpolation::getPoseAt(double time)
48 {
49  if (time < 0 || time > 1)
50  {
52  }
53  if (time == 1)
54  {
55  return SplineInterpolation::deepCopy(controlPoints[controlPoints.size() - 1]);
56  }
57  double x = 0;
58  double y = 0;
59  double z = 0;
60  double temp = 0;
61  alglib::pspline2calc(xInterpolation, time, x, temp);
62  alglib::pspline2calc(yInterpolation, time, y, temp);
63  alglib::pspline2calc(zInterpolation, time, z, temp);
64 
65  Vector3BasePtr position = new Vector3(x, y, z);
66  QuaternionBasePtr base = this->calculateOrientationAt(time);
67  return *new PoseBasePtr(new Pose(position, base));
68 
69 }
70 
72 {
73  int number = 0;
74  for (unsigned int i = 0; i < controlPoints.size(); i++)
75  {
76  if (controlPoints.at(i) == start)
77  {
78  number = i;
79  break;
80  }
81  }
83 }
84 
86 {
88 }
89 
90 
91 
92 alglib::real_2d_array SplineInterpolation::getCoordinateArray(int coordinate)
93 {
94  std::string transformation = "[";
95  unsigned int i = 0;
96  for (PoseBasePtr current : controlPoints)
97  {
98  int temp;
99  switch (coordinate)
100  {
101  case (0):
102  temp = current->position->x;
103  break;
104  case (1):
105  temp = current->position->y;
106  break;
107  case (2):
108  temp = current->position->z;
109  break;
110  }
111  transformation = transformation + "[" + std::to_string(temp) + "," + std::to_string(i / this->controlPoints.size()) + "]";
112  if (i != controlPoints.size() - 1)
113  {
114  transformation += ",";
115  }
116  i++;
117  }
118  transformation += "]";
119  const char* c = transformation.c_str();
120  real_2d_array input = *new real_2d_array(c);//TODO implement
121  return input;
122 }
123 
armarx::navigation::core::Pose
Eigen::Isometry3f Pose
Definition: basic_types.h:31
Pose.h
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
armarx::exceptions::local::NoInterpolationPossibleException
Definition: NoInterpolationPossibleException.h:40
armarx::SplineInterpolation::getInterPolationSegment
AbstractInterpolationPtr getInterPolationSegment(PoseBasePtr start)
getInterPolationSegment returns a segment of the current interpolation
Definition: SplineInterpolation.cpp:71
armarx::SplineInterpolation::getPoseAt
PoseBasePtr getPoseAt(double time) override
getPoseAt returns the Pose defined by f(time)
Definition: SplineInterpolation.cpp:47
armarx::AbstractInterpolationPtr
std::shared_ptr< AbstractInterpolation > AbstractInterpolationPtr
Definition: AbstractInterpolation.h:77
SplineInterpolation.h
armarx::aron::input
ReaderT::InputType & input
Definition: rw.h:19
armarx::exceptions::local::InterpolationNotDefinedException
Definition: InterpolationNotDefinedException.h:42
armarx::SplineInterpolationSegment
The SplineInterpolationSegment class represents the segment of a parent SplineInterpolation between t...
Definition: SplineInterpolationSegment.h:33
armarx::to_string
const std::string & to_string(const std::string &s)
Definition: StringHelpers.h:40
armarx::SplineInterpolation::SplineInterpolation
SplineInterpolation(std::vector< PoseBasePtr > controlPoints)
SplineInterpolation creates a new SplineInterpolation through a series of conntrol points.
Definition: SplineInterpolation.cpp:34
SplineInterpolationSegment.h
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