Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
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
00078
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}) {
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);
00102
00103
00104 if (fill_with_zeros)
00105 val = 0.0;
00106
00107 jac.coeffRef(nvi.dim_, idx) += val;
00108 }
00109 }
00110 }
00111 }
00112 }
00113
00114 }