base_motion_constraint.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/constraints/base_motion_constraint.h>
00031 #include <towr/variables/variable_names.h>
00032 #include <towr/variables/cartesian_dimensions.h>
00033 #include <towr/variables/spline_holder.h>
00034 
00035 namespace towr {
00036 
00037 
00038 BaseMotionConstraint::BaseMotionConstraint (double T, double dt,
00039                                             const SplineHolder& spline_holder)
00040     :TimeDiscretizationConstraint(T, dt, "baseMotion")
00041 {
00042   base_linear_  = spline_holder.base_linear_;
00043   base_angular_ = spline_holder.base_angular_;
00044 
00045   double dev_rad = 0.05;
00046   node_bounds_.resize(k6D);
00047   node_bounds_.at(AX) = Bounds(-dev_rad, dev_rad);
00048   node_bounds_.at(AY) = Bounds(-dev_rad, dev_rad);
00049   node_bounds_.at(AZ) = ifopt::NoBound;//Bounds(-dev_rad, dev_rad);
00050 
00051   double z_init = base_linear_->GetPoint(0.0).p().z();
00052   node_bounds_.at(LX) = ifopt::NoBound;
00053   node_bounds_.at(LY) = ifopt::NoBound;//Bounds(-0.05, 0.05);
00054   node_bounds_.at(LZ) = Bounds(z_init-0.02, z_init+0.1); // allow to move dev_z cm up and down
00055 
00056   int n_constraints_per_node = node_bounds_.size();
00057   SetRows(GetNumberOfNodes()*n_constraints_per_node);
00058 }
00059 
00060 void
00061 BaseMotionConstraint::UpdateConstraintAtInstance (double t, int k,
00062                                                   VectorXd& g) const
00063 {
00064   g.middleRows(GetRow(k, LX), k3D) = base_linear_->GetPoint(t).p();
00065   g.middleRows(GetRow(k, AX), k3D) = base_angular_->GetPoint(t).p();
00066 }
00067 
00068 void
00069 BaseMotionConstraint::UpdateBoundsAtInstance (double t, int k, VecBound& bounds) const
00070 {
00071   for (int dim=0; dim<node_bounds_.size(); ++dim)
00072     bounds.at(GetRow(k,dim)) = node_bounds_.at(dim);
00073 }
00074 
00075 void
00076 BaseMotionConstraint::UpdateJacobianAtInstance (double t, int k,
00077                                                 std::string var_set,
00078                                                 Jacobian& jac) const
00079 {
00080   if (var_set == id::base_ang_nodes)
00081     jac.middleRows(GetRow(k,AX), k3D) = base_angular_->GetJacobianWrtNodes(t, kPos);
00082 
00083   if (var_set == id::base_lin_nodes)
00084     jac.middleRows(GetRow(k,LX), k3D) = base_linear_->GetJacobianWrtNodes(t, kPos);
00085 }
00086 
00087 int
00088 BaseMotionConstraint::GetRow (int node, int dim) const
00089 {
00090   return node*node_bounds_.size() + dim;
00091 }
00092 
00093 } /* namespace towr */


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