node_spline.cc
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 #include <towr/variables/node_spline.h>
00031 
00032 #include <towr/variables/nodes_variables.h>
00033 
00034 namespace towr {
00035 
00036 NodeSpline::NodeSpline(NodeSubjectPtr const node_variables,
00037                        const VecTimes& polynomial_durations)
00038     :   Spline(polynomial_durations, node_variables->GetDim()),
00039         NodesObserver(node_variables)
00040 {
00041   UpdateNodes();
00042   jac_wrt_nodes_structure_ = Jacobian(node_variables->GetDim(), node_variables->GetRows());
00043 }
00044 
00045 void
00046 NodeSpline::UpdateNodes ()
00047 {
00048   for (int i=0; i<cubic_polys_.size(); ++i) {
00049     auto nodes = node_values_->GetBoundaryNodes(i);
00050     cubic_polys_.at(i).SetNodes(nodes.front(), nodes.back());
00051   }
00052 
00053   UpdatePolynomialCoeff();
00054 }
00055 
00056 int
00057 NodeSpline::GetNodeVariablesCount() const
00058 {
00059   return node_values_->GetRows();
00060 }
00061 
00062 NodeSpline::Jacobian
00063 NodeSpline::GetJacobianWrtNodes (double t_global, Dx dxdt) const
00064 {
00065   int id; double t_local;
00066   std::tie(id, t_local) = GetLocalTime(t_global, GetPolyDurations());
00067 
00068   return GetJacobianWrtNodes(id, t_local, dxdt);
00069 }
00070 
00071 NodeSpline::Jacobian
00072 NodeSpline::GetJacobianWrtNodes (int id, double t_local, Dx dxdt) const
00073 {
00074   Jacobian jac = jac_wrt_nodes_structure_;
00075   FillJacobianWrtNodes(id, t_local, dxdt, jac, false);
00076 
00077   // needed to avoid Eigen::assert failure "wrong storage order" triggered
00078   // in dynamic_constraint.cc
00079   jac.makeCompressed();
00080 
00081   return jac;
00082 }
00083 
00084 void
00085 NodeSpline::FillJacobianWrtNodes (int poly_id, double t_local, Dx dxdt,
00086                                   Jacobian& jac, bool fill_with_zeros) const
00087 {
00088   for (int idx=0; idx<jac.cols(); ++idx) {
00089     for (auto nvi : node_values_->GetNodeValuesInfo(idx)) {
00090       for (auto side : {NodesVariables::Side::Start, NodesVariables::Side::End}) { // every jacobian is affected by two nodes
00091         int node = node_values_->GetNodeId(poly_id, side);
00092 
00093         if (node == nvi.id_) {
00094           double val = 0.0;
00095 
00096           if (side == NodesVariables::Side::Start)
00097             val = cubic_polys_.at(poly_id).GetDerivativeWrtStartNode(dxdt, nvi.deriv_, t_local);
00098           else if (side == NodesVariables::Side::End)
00099             val = cubic_polys_.at(poly_id).GetDerivativeWrtEndNode(dxdt, nvi.deriv_, t_local);
00100           else
00101             assert(false); // this shouldn't happen
00102 
00103           // if only want structure
00104           if (fill_with_zeros)
00105             val = 0.0;
00106 
00107           jac.coeffRef(nvi.dim_, idx) += val;
00108         }
00109       }
00110     }
00111   }
00112 }
00113 
00114 } /* namespace towr */


towr
Author(s): Alexander W. Winkler
autogenerated on Mon Apr 15 2019 02:42:32