dynamic_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 
31 
34 
35 namespace towr {
36 
38  const Parameters& params,
39  const SplineHolder& spline_holder)
40  :TimeDiscretizationConstraint(params.t_total_,
41  params.dt_constraint_dynamic_,
42  "DynamicConstraint")
43 {
44  model_ = m;
45 
46  // link with up-to-date spline variables
47  base_linear_ = spline_holder.base_linear_;
49  ee_forces_ = spline_holder.ee_force_;
50  ee_motion_ = spline_holder.ee_motion_;
51 
52  SetRows(GetNumberOfNodes()*k6D);
53 }
54 
55 int
56 DynamicConstraint::GetRow (int k, Dim6D dimension) const
57 {
58  return k6D*k + dimension;
59 }
60 
61 void
63 {
64  UpdateModel(t);
65  g.segment(GetRow(k,AX), k6D) = model_->GetDynamicViolation();
66 }
67 
68 void
69 DynamicConstraint::UpdateBoundsAtInstance(double t, int k, VecBound& bounds) const
70 {
71  for (auto dim : AllDim6D)
72  bounds.at(GetRow(k,dim)) = ifopt::BoundZero;
73 }
74 
75 void
76 DynamicConstraint::UpdateJacobianAtInstance(double t, int k, std::string var_set,
77  Jacobian& jac) const
78 {
79  UpdateModel(t);
80 
81  int n = jac.cols();
82  Jacobian jac_model(k6D,n);
83 
84  // sensitivity of dynamic constraint w.r.t base variables.
85  if (var_set == id::base_lin_nodes) {
86  Jacobian jac_base_lin_pos = base_linear_->GetJacobianWrtNodes(t,kPos);
87  Jacobian jac_base_lin_acc = base_linear_->GetJacobianWrtNodes(t,kAcc);
88 
89  jac_model = model_->GetJacobianWrtBaseLin(jac_base_lin_pos,
90  jac_base_lin_acc);
91  }
92 
93  if (var_set == id::base_ang_nodes) {
94  jac_model = model_->GetJacobianWrtBaseAng(base_angular_, t);
95  }
96 
97 
98  // sensitivity of dynamic constraint w.r.t. endeffector variables
99  for (int ee=0; ee<model_->GetEECount(); ++ee) {
100 
101  if (var_set == id::EEForceNodes(ee)) {
102  Jacobian jac_ee_force = ee_forces_.at(ee)->GetJacobianWrtNodes(t,kPos);
103  jac_model = model_->GetJacobianWrtForce(jac_ee_force, ee);
104  }
105 
106  if (var_set == id::EEMotionNodes(ee)) {
107  Jacobian jac_ee_pos = ee_motion_.at(ee)->GetJacobianWrtNodes(t,kPos);
108  jac_model = model_->GetJacobianWrtEEPos(jac_ee_pos, ee);
109  }
110 
111  if (var_set == id::EESchedule(ee)) {
112  Jacobian jac_f_dT = ee_forces_.at(ee)->GetJacobianOfPosWrtDurations(t);
113  jac_model += model_->GetJacobianWrtForce(jac_f_dT, ee);
114 
115  Jacobian jac_x_dT = ee_motion_.at(ee)->GetJacobianOfPosWrtDurations(t);
116  jac_model += model_->GetJacobianWrtEEPos(jac_x_dT, ee);
117  }
118  }
119 
120  jac.middleRows(GetRow(k,AX), k6D) = jac_model;
121 }
122 
123 void
125 {
126  auto com = base_linear_->GetPoint(t);
127 
128  Eigen::Matrix3d w_R_b = base_angular_.GetRotationMatrixBaseToWorld(t);
129  Eigen::Vector3d omega = base_angular_.GetAngularVelocityInWorld(t);
130  Eigen::Vector3d omega_dot = base_angular_.GetAngularAccelerationInWorld(t);
131 
132  int n_ee = model_->GetEECount();
133  std::vector<Eigen::Vector3d> ee_pos;
134  std::vector<Eigen::Vector3d> ee_force;
135  for (int ee=0; ee<n_ee; ++ee) {
136  ee_force.push_back(ee_forces_.at(ee)->GetPoint(t).p());
137  ee_pos.push_back(ee_motion_.at(ee)->GetPoint(t).p());
138  }
139 
140  model_->SetCurrent(com.p(), com.a(), w_R_b, omega, omega_dot, ee_force, ee_pos);
141 }
142 
143 } /* namespace towr */
DynamicConstraint(const DynamicModel::Ptr &model, const Parameters &params, const SplineHolder &spline_holder)
Construct a Dynamic constraint.
Constraints evaluated at discretized times along a trajectory.
static constexpr int k6D
void UpdateModel(double t) const
Updates the model with the current state and forces.
virtual void UpdateConstraintAtInstance(double t, int k, VectorXd &g) const override
Sets the constraint value a specific time t, corresponding to node k.
EulerConverter base_angular_
angular base state
NodeSpline::Ptr base_linear_
lin. base pos/vel/acc in world frame
Eigen::VectorXd VectorXd
static std::string EESchedule(uint ee)
virtual void UpdateJacobianAtInstance(double t, int k, std::string, Jacobian &) const override
Sets Jacobian rows at a specific time t, corresponding to node k.
static const Dim6D AllDim6D[]
Vector3d GetAngularAccelerationInWorld(double t) const
Converts Euler angles, rates and rate derivatives o angular accelerations.
Holds pointers to fully constructed splines, that are linked to the optimization variables.
Definition: spline_holder.h:46
Converts Euler angles and derivatives to angular quantities.
NodeSpline::Ptr base_linear_
Definition: spline_holder.h:68
std::shared_ptr< DynamicModel > Ptr
Definition: dynamic_model.h:60
static std::string EEMotionNodes(uint ee)
std::vector< NodeSpline::Ptr > ee_force_
Definition: spline_holder.h:72
NodeSpline::Ptr base_angular_
Definition: spline_holder.h:69
std::vector< NodeSpline::Ptr > ee_forces_
endeffector forces in world frame.
Vector3d GetAngularVelocityInWorld(double t) const
Converts Euler angles and Euler rates to angular velocities.
virtual void UpdateBoundsAtInstance(double t, int k, VecBound &bounds) const override
Sets upper/lower bound a specific time t, corresponding to node k.
std::vector< NodeSpline::Ptr > ee_motion_
endeffector position in world frame.
Holds the parameters to tune the optimization problem.
Definition: parameters.h:45
MatrixSXd GetRotationMatrixBaseToWorld(double t) const
Converts the Euler angles at time t to a rotation matrix.
static std::string EEForceNodes(uint ee)
static const std::string base_ang_nodes
DynamicModel::Ptr model_
the dynamic model (e.g. Centroidal)
std::vector< NodeSpline::Ptr > ee_motion_
Definition: spline_holder.h:71
static const std::string base_lin_nodes
int GetRow(int k, Dim6D dimension) const
The row in the overall constraint for this evaluation time.


towr_core
Author(s): Alexander W. Winkler
autogenerated on Sat Apr 7 2018 02:15:57