10 #include <eigen3/Eigen/Dense> 11 #include <boost/numeric/odeint.hpp> 16 using Eigen::Vector3f;
17 namespace pl = std::placeholders;
30 const std::vector<Eigen::Vector3f> &positions,
31 const std::vector<Eigen::Vector3f> &orientations,
41 const std::vector<Eigen::Vector3f> &positions,
42 const std::vector<Eigen::Vector3f> &orientations)
44 if (positions.size() != orientations.size())
45 cout <<
"[Spline] Not the same number of specified positions and orientations" << endl;
46 if (positions.size() == 0)
47 cout <<
"[Spline] No specified position" << endl;
51 n_ = positions.size() - 1;
65 Eigen::Vector3f &position,
66 Eigen::Vector3f &orientation,
73 cout <<
"[Spline] Evaluating at t<0 (t=" << t <<
")" << endl;
103 a_.resize(
n_, vector<Vector3f>(4));
105 for (
int k = 0; k <
n_; k++) {
108 a_[k][2] = 3*(
p_[k+1] -
p_[k]) - 2*
o_[k] -
o_[k+1];
109 a_[k][3] = 2*(
p_[k] -
p_[k+1]) +
o_[k] +
o_[k+1];
123 return a_[k][0] + (s-k)*
a_[k][1] + pow(s-k, 2)*
a_[k][2] + pow(s-k, 3)*
a_[k][3];
136 Vector3f orientation =
a_[k][1] + 2*(s-k)*
a_[k][2] + 3*pow(s-k, 2)*
a_[k][3];
142 const std::vector<double> &s,
143 std::vector<double> &dsdt,
154 vector<double> state(1, s0);
157 size_t steps = boost::numeric::odeint::integrate(
159 state, t0, t,
float(t-t0)/2
float last_t_
Time instant of the last evaluated point.
float compute_abscissa(float t)
Computes the curvilinear abscissa corresponding to a time instant.
void compute_parameters()
Computes the spline parameters.
float speed_
Constant speed to adopt on the path.
std::vector< Eigen::Vector3f > o_
Corresponding orientations.
void evaluate(float t, Eigen::Vector3f &position, Eigen::Vector3f &orientation, bool &last_reached)
Evaluates the spline at a specific time instant (assuming constant speed)
std::vector< Eigen::Vector3f > p_
Positions to interpolate.
Eigen::Vector3f compute_orientation(float s)
Computes the orientation at a specific curvilinear abscissa.
void set_poses(const std::vector< Eigen::Vector3f > &positions, const std::vector< Eigen::Vector3f > &orientations)
Sets the poses to interpolate.
int n_
Number of poses to interpolate.
std::vector< std::vector< Eigen::Vector3f > > a_
Spline parameters for each segment (ie between each pose)
Declaration of a class for 3D spline interpolation.
float last_s_
Curvilinear abscissa of the last evaluated point.
void deriv_abscissa(const std::vector< double > &s, std::vector< double > &dsdt, const double t)
Computes the derivative of the curvilinear abscissa wrt time.
void set_speed(float speed)
Set the desired speed on the path.
bool prepared_
Whether the class is ready for interpolation.
Eigen::Vector3f evaluate_position(float s)
Evaluates the spline at a specific curvilinear abscissa.
Spline()
Default constructor.
void prepare()
Prepares the class for interpolation.