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/dynamic_constraint.h>
00031
00032 #include <towr/variables/variable_names.h>
00033 #include <towr/variables/cartesian_dimensions.h>
00034
00035 namespace towr {
00036
00037 DynamicConstraint::DynamicConstraint (const DynamicModel::Ptr& m,
00038 double T, double dt,
00039 const SplineHolder& spline_holder)
00040 :TimeDiscretizationConstraint(T, dt, "dynamic")
00041 {
00042 model_ = m;
00043
00044
00045 base_linear_ = spline_holder.base_linear_;
00046 base_angular_ = EulerConverter(spline_holder.base_angular_);
00047 ee_forces_ = spline_holder.ee_force_;
00048 ee_motion_ = spline_holder.ee_motion_;
00049
00050 SetRows(GetNumberOfNodes()*k6D);
00051 }
00052
00053 int
00054 DynamicConstraint::GetRow (int k, Dim6D dimension) const
00055 {
00056 return k6D*k + dimension;
00057 }
00058
00059 void
00060 DynamicConstraint::UpdateConstraintAtInstance(double t, int k, VectorXd& g) const
00061 {
00062 UpdateModel(t);
00063 g.segment(GetRow(k,AX), k6D) = model_->GetDynamicViolation();
00064 }
00065
00066 void
00067 DynamicConstraint::UpdateBoundsAtInstance(double t, int k, VecBound& bounds) const
00068 {
00069 for (auto dim : AllDim6D)
00070 bounds.at(GetRow(k,dim)) = ifopt::BoundZero;
00071 }
00072
00073 void
00074 DynamicConstraint::UpdateJacobianAtInstance(double t, int k, std::string var_set,
00075 Jacobian& jac) const
00076 {
00077 UpdateModel(t);
00078
00079 int n = jac.cols();
00080 Jacobian jac_model(k6D,n);
00081
00082
00083 if (var_set == id::base_lin_nodes) {
00084 Jacobian jac_base_lin_pos = base_linear_->GetJacobianWrtNodes(t,kPos);
00085 Jacobian jac_base_lin_acc = base_linear_->GetJacobianWrtNodes(t,kAcc);
00086
00087 jac_model = model_->GetJacobianWrtBaseLin(jac_base_lin_pos,
00088 jac_base_lin_acc);
00089 }
00090
00091 if (var_set == id::base_ang_nodes) {
00092 jac_model = model_->GetJacobianWrtBaseAng(base_angular_, t);
00093 }
00094
00095
00096 for (int ee=0; ee<model_->GetEECount(); ++ee) {
00097 if (var_set == id::EEForceNodes(ee)) {
00098 Jacobian jac_ee_force = ee_forces_.at(ee)->GetJacobianWrtNodes(t,kPos);
00099 jac_model = model_->GetJacobianWrtForce(jac_ee_force, ee);
00100 }
00101
00102 if (var_set == id::EEMotionNodes(ee)) {
00103 Jacobian jac_ee_pos = ee_motion_.at(ee)->GetJacobianWrtNodes(t,kPos);
00104 jac_model = model_->GetJacobianWrtEEPos(jac_ee_pos, ee);
00105 }
00106
00107 if (var_set == id::EESchedule(ee)) {
00108 Jacobian jac_f_dT = ee_forces_.at(ee)->GetJacobianOfPosWrtDurations(t);
00109 jac_model += model_->GetJacobianWrtForce(jac_f_dT, ee);
00110
00111 Jacobian jac_x_dT = ee_motion_.at(ee)->GetJacobianOfPosWrtDurations(t);
00112 jac_model += model_->GetJacobianWrtEEPos(jac_x_dT, ee);
00113 }
00114 }
00115
00116 jac.middleRows(GetRow(k,AX), k6D) = jac_model;
00117 }
00118
00119 void
00120 DynamicConstraint::UpdateModel (double t) const
00121 {
00122 auto com = base_linear_->GetPoint(t);
00123
00124 Eigen::Matrix3d w_R_b = base_angular_.GetRotationMatrixBaseToWorld(t);
00125 Eigen::Vector3d omega = base_angular_.GetAngularVelocityInWorld(t);
00126 Eigen::Vector3d omega_dot = base_angular_.GetAngularAccelerationInWorld(t);
00127
00128 int n_ee = model_->GetEECount();
00129 std::vector<Eigen::Vector3d> ee_pos;
00130 std::vector<Eigen::Vector3d> ee_force;
00131 for (int ee=0; ee<n_ee; ++ee) {
00132 ee_force.push_back(ee_forces_.at(ee)->GetPoint(t).p());
00133 ee_pos.push_back(ee_motion_.at(ee)->GetPoint(t).p());
00134 }
00135
00136 model_->SetCurrent(com.p(), com.a(), w_R_b, omega, omega_dot, ee_force, ee_pos);
00137 }
00138
00139 }