NASA Astrobee Robot Software  0.19.1
Flight software for the Astrobee robots operating inside the International Space Station.
polynomials.h
Go to the documentation of this file.
1 /* Copyright (c) 2017, United States Government, as represented by the
2  * Administrator of the National Aeronautics and Space Administration.
3  *
4  * All rights reserved.
5  *
6  * The Astrobee platform is licensed under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with the
8  * License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15  * License for the specific language governing permissions and limitations
16  * under the License.
17  */
18 
19 #ifndef MAPPER_POLYNOMIALS_H_
20 #define MAPPER_POLYNOMIALS_H_
21 
22 #include <pcl/point_cloud.h>
23 #include <pcl/point_types.h>
24 #include <ros/ros.h>
25 #include <Eigen/Dense>
26 
27 #include <complex>
28 #include <iostream>
29 #include <vector>
30 
31 #include "ff_msgs/ControlState.h"
32 #include "ff_msgs/Segment.h"
33 
34 namespace polynomials {
35 
36 // Coefficients go from higher order to lower order
37 // e.g.: (t-t0)^2 + 2(t-t0) + 3 ==> coeff = [1 2 3]
38 class Polynomial {
39  public:
40  double t0_; // Initial time for definition of polynomial
41  double tf_; // Ginal time for definition of polynomial
42  int order_; // Polynomial order
43  Eigen::VectorXd coeff_; // Coefficients
44 
45  // Constructor
46  Polynomial(const double t0, const double tf, const int coeff_size);
47  Polynomial();
48 
49  // Methods
50  Polynomial &operator=(const Polynomial &other) {
51  t0_ = other.t0_;
52  tf_ = other.tf_;
53  order_ = other.order_;
54  coeff_ = other.coeff_;
55  return *this;
56  }
57  void PrintPolyCoeff(); // Print all coefficients
58  void PolyConv(const Polynomial *poly2,
59  Polynomial *poly_out); // Convolute with another polynomial
60  void PolySquare(Polynomial *poly_out); // Square a polynomial
61  void PolyDiff(Polynomial *poly_out); // Get the derivative of a polynomial
62  void PolyAtTime(
63  const double time,
64  double *result) const; // Return polynomial value at given time
65  std::vector<std::complex<double>> Roots2ndOrderPoly();
66  std::vector<std::complex<double>> Roots3rdOrderPoly();
67 };
68 
69 // 3D trajectories characterized by three polynomials
70 class Poly3D {
71  public:
75  double t0_; // Initial time for definition of polynomials
76  double tf_; // Final time for definition of polynomials
77  int order_; // Polynomial order
78 
79  // Constructor: define a polynomial from a "ControlState" msg type (2nd order
80  // polynomials only)
81  Poly3D(const double t0_in, const double tf_in,
82  const ff_msgs::ControlState segment);
83  Poly3D();
84 
85  // Methods
86  void PrintSegmentCoeff(); // Print all coefficients
87  void SegmentAtTime(const double time,
88  Eigen::Vector3d *result)
89  const; // Return 3d value for polynomials at a given time
90  void SegmentAtTime(const double time, pcl::PointXYZ *result) const;
91 };
92 
93 // 3D trajectories characterized by a set of 3D polynomials
94 class Trajectory3D {
95  public:
96  std::vector<Poly3D> segments_poly_;
97  double t0_; // Initial time for the first segment
98  double tf_; // Final time for the last segment
100 
101  // Constructor
102  explicit Trajectory3D(const ff_msgs::Segment segments);
103 
104  // Methods
105  void PrintTrajCoeff(); // Print coefficients from all segments
106  void TrajectoryAtTime(const double time,
107  Eigen::Vector3d *result)
108  const; // Return 3d value for polynomials at a given time
109  void TrajectoryAtTime(const double time,
110  pcl::PointXYZ *result)
111  const; // Return 3d value for polynomials at a given time
112 };
113 
114 } // namespace polynomials
115 
116 #endif // MAPPER_POLYNOMIALS_H_
polynomials::Poly3D::SegmentAtTime
void SegmentAtTime(const double time, Eigen::Vector3d *result) const
Definition: polynomials.cc:234
polynomials::Poly3D::poly_z_
Polynomial poly_z_
Definition: polynomials.h:74
polynomials::Poly3D
Definition: polynomials.h:70
polynomials::Trajectory3D::Trajectory3D
Trajectory3D(const ff_msgs::Segment segments)
Definition: polynomials.cc:254
polynomials::Polynomial::PolyAtTime
void PolyAtTime(const double time, double *result) const
Definition: polynomials.cc:91
polynomials::Polynomial::tf_
double tf_
Definition: polynomials.h:41
polynomials::Polynomial::coeff_
Eigen::VectorXd coeff_
Definition: polynomials.h:43
polynomials::Poly3D::Poly3D
Poly3D()
Definition: polynomials.cc:213
polynomials::Poly3D::tf_
double tf_
Definition: polynomials.h:76
polynomials::Trajectory3D::PrintTrajCoeff
void PrintTrajCoeff()
Definition: polynomials.cc:278
ff_util::Segment
std::vector< Setpoint > Segment
Definition: ff_flight.h:47
polynomials::Polynomial::Roots3rdOrderPoly
std::vector< std::complex< double > > Roots3rdOrderPoly()
Definition: polynomials.cc:136
polynomials::Poly3D::t0_
double t0_
Definition: polynomials.h:75
polynomials::Trajectory3D::tf_
double tf_
Definition: polynomials.h:98
polynomials::Trajectory3D::t0_
double t0_
Definition: polynomials.h:97
polynomials::Poly3D::order_
int order_
Definition: polynomials.h:77
polynomials::Trajectory3D::n_segments_
int n_segments_
Definition: polynomials.h:99
polynomials::Polynomial::PolyConv
void PolyConv(const Polynomial *poly2, Polynomial *poly_out)
Definition: polynomials.cc:51
polynomials::Poly3D::poly_y_
Polynomial poly_y_
Definition: polynomials.h:73
polynomials
Definition: polynomials.h:34
polynomials::Poly3D::PrintSegmentCoeff
void PrintSegmentCoeff()
Definition: polynomials.cc:227
point_cloud_common::Vector3d
Eigen::Vector3d Vector3d(const PointType &point)
Definition: utilities.h:328
polynomials::Polynomial::PrintPolyCoeff
void PrintPolyCoeff()
Definition: polynomials.cc:43
polynomials::Trajectory3D::segments_poly_
std::vector< Poly3D > segments_poly_
Definition: polynomials.h:96
polynomials::Trajectory3D::TrajectoryAtTime
void TrajectoryAtTime(const double time, Eigen::Vector3d *result) const
Definition: polynomials.cc:288
polynomials::Polynomial::operator=
Polynomial & operator=(const Polynomial &other)
Definition: polynomials.h:50
polynomials::Polynomial::t0_
double t0_
Definition: polynomials.h:40
polynomials::Polynomial
Definition: polynomials.h:38
polynomials::Polynomial::Roots2ndOrderPoly
std::vector< std::complex< double > > Roots2ndOrderPoly()
Definition: polynomials.cc:109
polynomials::Polynomial::order_
int order_
Definition: polynomials.h:42
polynomials::Polynomial::PolyDiff
void PolyDiff(Polynomial *poly_out)
Definition: polynomials.cc:82
polynomials::Polynomial::Polynomial
Polynomial()
Definition: polynomials.cc:35
polynomials::Polynomial::PolySquare
void PolySquare(Polynomial *poly_out)
Definition: polynomials.cc:67
polynomials::Trajectory3D
Definition: polynomials.h:94
polynomials::Poly3D::poly_x_
Polynomial poly_x_
Definition: polynomials.h:72