range_of_motion_constraint.cc
Go to the documentation of this file.
1 /******************************************************************************
2 Copyright (c) 2018, Alexander W. Winkler. All rights reserved.
3 
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions are met:
6 
7 * Redistributions of source code must retain the above copyright notice, this
8  list of conditions and the following disclaimer.
9 
10 * Redistributions in binary form must reproduce the above copyright notice,
11  this list of conditions and the following disclaimer in the documentation
12  and/or other materials provided with the distribution.
13 
14 * Neither the name of the copyright holder nor the names of its
15  contributors may be used to endorse or promote products derived from
16  this software without specific prior written permission.
17 
18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 ******************************************************************************/
29 
32 
33 namespace towr {
34 
36  double T, double dt,
37  const EE& ee,
38  const SplineHolder& spline_holder)
39  :TimeDiscretizationConstraint(T, dt, "rangeofmotion-" + std::to_string(ee))
40 {
41  base_linear_ = spline_holder.base_linear_;
43  ee_motion_ = spline_holder.ee_motion_.at(ee);
44 
45  max_deviation_from_nominal_ = model->GetMaximumDeviationFromNominal();
46  nominal_ee_pos_B_ = model->GetNominalStanceInBase().at(ee);
47  ee_ = ee;
48 
50 }
51 
52 int
53 RangeOfMotionConstraint::GetRow (int node, int dim) const
54 {
55  return node*k3D + dim;
56 }
57 
58 void
60 {
61  Vector3d base_W = base_linear_->GetPoint(t).p();
62  Vector3d pos_ee_W = ee_motion_->GetPoint(t).p();
64 
65  Vector3d vector_base_to_ee_W = pos_ee_W - base_W;
66  Vector3d vector_base_to_ee_B = b_R_w*(vector_base_to_ee_W);
67 
68  g.middleRows(GetRow(k, X), k3D) = vector_base_to_ee_B;
69 }
70 
71 void
73 {
74  for (int dim=0; dim<k3D; ++dim) {
75  ifopt::Bounds b;
76  b += nominal_ee_pos_B_(dim);
79  bounds.at(GetRow(k,dim)) = b;
80  }
81 }
82 
83 void
85  std::string var_set,
86  Jacobian& jac) const
87 {
89  int row_start = GetRow(k,X);
90 
91  if (var_set == id::base_lin_nodes) {
92  jac.middleRows(row_start, k3D) = -1*b_R_w*base_linear_->GetJacobianWrtNodes(t, kPos);
93  }
94 
95  if (var_set == id::base_ang_nodes) {
96  Vector3d base_W = base_linear_->GetPoint(t).p();
97  Vector3d ee_pos_W = ee_motion_->GetPoint(t).p();
98  Vector3d r_W = ee_pos_W - base_W;
99  jac.middleRows(row_start, k3D) = base_angular_.DerivOfRotVecMult(t,r_W, true);
100  }
101 
102  if (var_set == id::EEMotionNodes(ee_)) {
103  jac.middleRows(row_start, k3D) = b_R_w*ee_motion_->GetJacobianWrtNodes(t,kPos);
104  }
105 
106  if (var_set == id::EESchedule(ee_)) {
107  jac.middleRows(row_start, k3D) = b_R_w*ee_motion_->GetJacobianOfPosWrtDurations(t);
108  }
109 }
110 
111 } /* namespace xpp */
112 
Jacobian DerivOfRotVecMult(double t, const Vector3d &v, bool inverse) const
Returns the derivative of result of the linear equation M*v.
Constraints evaluated at discretized times along a trajectory.
NodeSpline::Ptr ee_motion_
the linear position of the endeffectors.
int GetRow(int node, int dimension) const
std::shared_ptr< KinematicModel > Ptr
static std::string EESchedule(uint ee)
Eigen::SparseMatrix< double, Eigen::RowMajor > MatrixSXd
Builds splines from node values (pos/vel) and durations.
Definition: spline_holder.h:47
Converts Euler angles and derivatives to angular quantities.
NodeSpline::Ptr base_linear_
Definition: spline_holder.h:71
void SetRows(int num_rows)
static std::string EEMotionNodes(uint ee)
Eigen::SparseMatrix< double, Eigen::RowMajor > Jacobian
NodeSpline::Ptr base_angular_
Definition: spline_holder.h:72
EulerConverter base_angular_
the orientation of the base.
static constexpr int k3D
RangeOfMotionConstraint(const KinematicModel::Ptr &robot_model, double T, double dt, const EE &ee, const SplineHolder &spline_holder)
Constructs a constraint instance.
void UpdateConstraintAtInstance(double t, int k, VectorXd &g) const override
Sets the constraint value a specific time t, corresponding to node k.
static const std::string base_ang_nodes
MatrixSXd GetRotationMatrixBaseToWorld(double t) const
Converts the Euler angles at time t to a rotation matrix.
NodeSpline::Ptr base_linear_
the linear position of the base.
void UpdateBoundsAtInstance(double t, int k, VecBound &) const override
Sets upper/lower bound a specific time t, corresponding to node k.
std::vector< Bounds > VecBound
void UpdateJacobianAtInstance(double t, int k, std::string, Jacobian &) const override
Sets Jacobian rows at a specific time t, corresponding to node k.
std::vector< NodeSpline::Ptr > ee_motion_
Definition: spline_holder.h:74
static const std::string base_lin_nodes
Eigen::VectorXd VectorXd


towr
Author(s): Alexander W. Winkler
autogenerated on Mon Feb 28 2022 23:54:22