polynomial.h
Go to the documentation of this file.
00001 /******************************************************************************
00002 Copyright (c) 2018, Alexander W. Winkler. All rights reserved.
00003 
00004 Redistribution and use in source and binary forms, with or without
00005 modification, are permitted provided that the following conditions are met:
00006 
00007 * Redistributions of source code must retain the above copyright notice, this
00008   list of conditions and the following disclaimer.
00009 
00010 * Redistributions in binary form must reproduce the above copyright notice,
00011   this list of conditions and the following disclaimer in the documentation
00012   and/or other materials provided with the distribution.
00013 
00014 * Neither the name of the copyright holder nor the names of its
00015   contributors may be used to endorse or promote products derived from
00016   this software without specific prior written permission.
00017 
00018 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00019 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00021 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00022 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00023 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00024 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00025 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00026 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00027 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00028 ******************************************************************************/
00029 
00030 #ifndef TOWR_VARIABLES_POLYNOMIAL_H_
00031 #define TOWR_VARIABLES_POLYNOMIAL_H_
00032 
00033 #include <string>
00034 #include <vector>
00035 
00036 #include <Eigen/Dense>
00037 
00038 #include "state.h"
00039 
00040 namespace towr {
00041 
00053 class Polynomial {
00054 public:
00055   enum Coefficients { A=0, B, C, D, E, F, G, H, I, J};
00056   using CoeffIDVec = std::vector<Coefficients>;
00057   using VectorXd   = Eigen::VectorXd;
00058 
00059 public:
00065   explicit Polynomial(int poly_order, int poly_dim);
00066   virtual ~Polynomial() = default;
00067 
00071   State GetPoint(double t) const;
00072 
00080   double GetDerivativeWrtCoeff(double t, Dx poly_deriv, Coefficients coeff) const;
00081 
00082 protected:
00083   std::vector<VectorXd> coeff_;
00084 
00085 private:
00086   CoeffIDVec coeff_ids_;
00087 };
00088 
00089 
00105 class CubicHermitePolynomial : public Polynomial {
00106 public:
00107   CubicHermitePolynomial(int dim);
00108   virtual ~CubicHermitePolynomial() = default;
00109 
00110 
00114   void SetDuration(double duration);
00115 
00121   void SetNodes(const Node& n0, const Node& n1);
00122 
00126   void UpdateCoeff();
00127 
00132   VectorXd GetDerivativeOfPosWrtDuration(double t) const;
00133 
00140   double GetDerivativeWrtStartNode(Dx dfdt, Dx node_deriv, double t) const;
00141 
00148   double GetDerivativeWrtEndNode(Dx dfdt, Dx node_deriv, double t) const;
00149 
00153   const double GetDuration() const { return T_; };
00154 
00155 private:
00156   double T_;     
00157   Node n0_, n1_; 
00158 
00159   // see matlab/cubic_hermite_polynomial.m script for derivation
00160   double GetDerivativeOfPosWrtStartNode(Dx node_deriv, double t_local) const;
00161   double GetDerivativeOfVelWrtStartNode(Dx node_deriv, double t_local) const;
00162   double GetDerivativeOfAccWrtStartNode(Dx node_deriv, double t_local) const;
00163 
00164   double GetDerivativeOfPosWrtEndNode(Dx node_deriv, double t_local) const;
00165   double GetDerivativeOfVelWrtEndNode(Dx node_deriv, double t_local) const;
00166   double GetDerivativeOfAccWrtEndNode(Dx node_deriv, double t_local) const;
00167 };
00168 
00169 } // namespace towr
00170 
00171 #endif // TOWR_VARIABLES_POLYNOMIAL_H_


towr_core
Author(s): Alexander W. Winkler
autogenerated on Mon Apr 9 2018 03:12:44