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/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;
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;
00054 node_bounds_.at(LZ) = Bounds(z_init-0.02, z_init+0.1);
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 }