Robot Dynamics Library
Contacts.hpp
Go to the documentation of this file.
1 // Copyright (c) 2017 Jordan Lack <jlack1987@gmail.com>
2 // Copyright (c) 2011-2016 Martin Felis <martin.felis@iwr.uni-heidelberg.de>
3 // RDL - Robot Dynamics Library
4 // Licensed under the zlib license. See LICENSE for more details.
5 
6 #ifndef RDL_CONTACTS_HPP
7 #define RDL_CONTACTS_HPP
8 
16 
17 namespace RobotDynamics
18 {
152 struct Model;
153 
164 {
166  {
167  }
168 
180  unsigned int addConstraint(unsigned int body_id, const Math::Vector3d& body_point, const Math::Vector3d& world_normal, const char* constraint_name = NULL,
181  double normal_acceleration = 0.);
182 
187  {
188  ConstraintSet result(*this);
189 
190  result.bound = false;
191 
192  return result;
193  }
194 
198  {
199  linear_solver = solver;
200  }
201 
213  bool bind(const Model& model);
214 
216  size_t size() const
217  {
218  return acceleration.size();
219  }
220 
222  void clear();
223 
226 
228  bool bound;
229 
230  std::vector<std::string> name;
231  std::vector<unsigned int> body;
232  std::vector<Math::Vector3d> point;
233  std::vector<Math::Vector3d> normal;
234 
238 
241 
244 
248 
249  // Variables used by the Lagrangian methods
250 
253 
256 
260 
263 
266 
269 
271  Eigen::HouseholderQR<Math::MatrixNd> GT_qr;
272 
278 
279  // Variables used by the IABI methods
280 
283 
286 
289 
292 
295 
298 
300  std::vector<Math::Vector3d> point_accel_0;
301 
304 
306  std::vector<Math::SpatialVector> d_a;
308 
310  std::vector<Math::SpatialMatrix> d_IA;
311 
313  std::vector<Math::SpatialVector> d_U;
314 
317 
318  std::vector<Math::Vector3d> d_multdof3_u;
319 };
320 
329 void calcContactJacobian(Model& model, const Math::VectorNd& Q, const ConstraintSet& CS, Math::MatrixNd& G, bool update_kinematics = true);
330 
331 void calcContactSystemVariables(Model& model, const Math::VectorNd& Q, const Math::VectorNd& QDot, const Math::VectorNd& Tau, ConstraintSet& CS);
332 
383 void forwardDynamicsContactsDirect(Model& model, const Math::VectorNd& Q, const Math::VectorNd& QDot, const Math::VectorNd& Tau, ConstraintSet& CS,
384  Math::VectorNd& QDDot);
385 
387  Math::VectorNd& QDDot);
388 
389 void forwardDynamicsContactsNullSpace(Model& model, const Math::VectorNd& Q, const Math::VectorNd& QDot, const Math::VectorNd& Tau, ConstraintSet& CS,
390  Math::VectorNd& QDDot);
391 
454 void forwardDynamicsContactsKokkevis(Model& model, const Math::VectorNd& Q, const Math::VectorNd& QDot, const Math::VectorNd& Tau, ConstraintSet& CS,
455  Math::VectorNd& QDDot);
456 
503 void computeContactImpulsesDirect(Model& model, const Math::VectorNd& Q, const Math::VectorNd& QDotMinus, ConstraintSet& CS, Math::VectorNd& QDotPlus);
504 
507 void computeContactImpulsesRangeSpaceSparse(Model& model, const Math::VectorNd& Q, const Math::VectorNd& QDotMinus, ConstraintSet& CS, Math::VectorNd& QDotPlus);
508 
511 void computeContactImpulsesNullSpace(Model& model, const Math::VectorNd& Q, const Math::VectorNd& QDotMinus, ConstraintSet& CS, Math::VectorNd& QDotPlus);
512 
531 
550  Math::VectorNd& qddot, Math::VectorNd& lambda, Math::MatrixNd& K, Math::VectorNd& a, Math::LinearSolver linear_solver);
551 
572  Math::VectorNd& lambda, Math::MatrixNd& Y, Math::MatrixNd& Z, Math::VectorNd& qddot_y, Math::VectorNd& qddot_z,
573  Math::LinearSolver& linear_solver);
574 
576 } /* namespace RobotDynamics */
577 
578 /* RDL_CONTACTS_H */
579 #endif // ifndef RDL_CONTACTS_H
Definition: rdl_eigenmath.hpp:54
void computeContactImpulsesNullSpace(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDotMinus, ConstraintSet &CS, Math::VectorNd &QDotPlus)
Resolves contact gain using solveContactSystemNullSpace()
Definition: Contacts.cpp:418
void forwardDynamicsContactsNullSpace(Model &model, const VectorNd &Q, const VectorNd &QDot, const VectorNd &Tau, ConstraintSet &CS, VectorNd &QDDot)
Definition: Contacts.cpp:369
void forwardDynamicsContactsKokkevis(Model &model, const VectorNd &Q, const VectorNd &QDot, const VectorNd &Tau, ConstraintSet &CS, VectorNd &QDDot)
Computes forward dynamics that accounts for active contacts in ConstraintSet.
Definition: Contacts.cpp:681
void computeContactImpulsesRangeSpaceSparse(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDotMinus, ConstraintSet &CS, Math::VectorNd &QDotPlus)
Resolves contact gain using solveContactSystemRangeSpaceSparse()
Definition: Contacts.cpp:406
void forwardDynamicsContactsRangeSpaceSparse(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, const Math::VectorNd &Tau, ConstraintSet &CS, Math::VectorNd &QDDot)
Definition: Contacts.cpp:361
void solveContactSystemDirect(Math::MatrixNd &H, const Math::MatrixNd &G, const Math::VectorNd &c, const Math::VectorNd &gamma, Math::VectorNd &qddot, Math::VectorNd &lambda, Math::MatrixNd &A, Math::VectorNd &b, Math::VectorNd &x, Math::LinearSolver &linear_solver)
Solves the full contact system directly, i.e. simultaneously for contact forces and joint acceleratio...
Definition: Contacts.cpp:170
void calcContactSystemVariables(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDot, const Math::VectorNd &Tau, ConstraintSet &CS)
Definition: Contacts.cpp:306
void solveContactSystemNullSpace(Math::MatrixNd &H, const Math::MatrixNd &G, const Math::VectorNd &c, const Math::VectorNd &gamma, Math::VectorNd &qddot, Math::VectorNd &lambda, Math::MatrixNd &Y, Math::MatrixNd &Z, Math::VectorNd &qddot_y, Math::VectorNd &qddot_z, Math::LinearSolver &linear_solver)
Solves the contact system by first solving for the joint accelerations and then for the constraint fo...
Definition: Contacts.cpp:232
void solveContactSystemRangeSpaceSparse(Model &model, Math::MatrixNd &H, const Math::MatrixNd &G, const Math::VectorNd &c, const Math::VectorNd &gamma, Math::VectorNd &qddot, Math::VectorNd &lambda, Math::MatrixNd &K, Math::VectorNd &a, Math::LinearSolver linear_solver)
Solves the contact system by first solving for the the joint accelerations and then the contact force...
Definition: Contacts.cpp:203
void forwardDynamicsContactsDirect(Model &model, const VectorNd &Q, const VectorNd &QDot, const VectorNd &Tau, ConstraintSet &CS, VectorNd &QDDot)
Computes forward dynamics with contact by constructing and solving the full lagrangian equation.
Definition: Contacts.cpp:342
void computeContactImpulsesDirect(Model &model, const Math::VectorNd &Q, const Math::VectorNd &QDotMinus, ConstraintSet &CS, Math::VectorNd &QDotPlus)
Computes contact gain by constructing and solving the full lagrangian equation.
Definition: Contacts.cpp:382
void calcContactJacobian(Model &model, const Math::VectorNd &Q, const ConstraintSet &CS, Math::MatrixNd &G, bool update_kinematics)
Computes the Jacobian for the given ConstraintSet.
Definition: Contacts.cpp:273
LinearSolver
Available solver methods for the linear systems.
Definition: rdl_mathutils.hpp:29
@ LinearSolverColPivHouseholderQR
Definition: rdl_mathutils.hpp:32
std::vector< SpatialForce, Eigen::aligned_allocator< SpatialForce > > SpatialForceV
Definition: SpatialForce.hpp:252
Eigen::VectorXd VectorNd
Definition: rdl_eigenmath.hpp:20
Eigen::MatrixXd MatrixNd
Definition: rdl_eigenmath.hpp:21
Namespace for all structures of the RobotDynamics library.
Definition: examples.hpp:19
Structure that contains both constraint information and workspace memory.
Definition: Contacts.hpp:164
Math::MatrixNd H
Workspace for the joint space inertia matrix.
Definition: Contacts.hpp:252
std::vector< std::string > name
Definition: Contacts.hpp:230
std::vector< Math::SpatialMatrix > d_IA
Workspace for the inertia when applying constraint forces.
Definition: Contacts.hpp:310
Math::MatrixNd K
Workspace for the Inverse Articulated-Body Inertia.
Definition: Contacts.hpp:282
std::vector< Math::SpatialVector > d_a
Workspace for the acceleration due to the test force.
Definition: Contacts.hpp:306
Math::VectorNd qddot_z
Definition: Contacts.hpp:277
Math::VectorNd a
Workspace for the accelerations of due to the test forces.
Definition: Contacts.hpp:285
std::vector< Math::Vector3d > normal
Definition: Contacts.hpp:233
Math::MatrixNd GT_qr_Q
Definition: Contacts.hpp:273
Eigen::HouseholderQR< Math::MatrixNd > GT_qr
Workspace for the QR decomposition of the null-space method.
Definition: Contacts.hpp:271
Math::MatrixNd G
Definition: Contacts.hpp:259
Math::MatrixNd Z
Definition: Contacts.hpp:275
Math::VectorNd QDDot_0
Workspace for the default accelerations.
Definition: Contacts.hpp:291
Math::VectorNd d_u
Definition: Contacts.hpp:307
size_t size() const
Returns the number of constraints.
Definition: Contacts.hpp:216
std::vector< Math::Vector3d > d_multdof3_u
Definition: Contacts.hpp:318
Math::VectorNd b
Workspace for the Lagrangian right-hand-side.
Definition: Contacts.hpp:265
Math::VectorNd qddot_y
Definition: Contacts.hpp:276
std::vector< Math::Vector3d > point_accel_0
Workspace for the default point accelerations.
Definition: Contacts.hpp:300
Math::MatrixNd Y
Definition: Contacts.hpp:274
void setSolver(Math::LinearSolver solver)
Specifies which method should be used for solving undelying linear systems.
Definition: Contacts.hpp:197
bool bind(const Model &model)
Initializes and allocates memory for the constraint set.
Definition: Contacts.cpp:57
Math::SpatialForceV d_pA
Workspace for the bias force due to the test force.
Definition: Contacts.hpp:303
ConstraintSet Copy()
Copies the constraints and resets its ConstraintSet::bound flag.
Definition: Contacts.hpp:186
ConstraintSet()
Definition: Contacts.hpp:165
Math::VectorNd gamma
Workspace of the lower part of b.
Definition: Contacts.hpp:258
Math::VectorNd force
Definition: Contacts.hpp:240
Math::VectorNd v_plus
Definition: Contacts.hpp:247
Math::MatrixNd A
Workspace for the Lagrangian left-hand-side matrix.
Definition: Contacts.hpp:262
Math::VectorNd d_d
Workspace when applying constraint forces.
Definition: Contacts.hpp:316
Math::LinearSolver linear_solver
Method that should be used to solve internal linear systems.
Definition: Contacts.hpp:225
Math::SpatialForceV f_ext_constraints
Workspace for the actual spatial forces.
Definition: Contacts.hpp:297
Math::VectorNd QDDot_t
Workspace for the test accelerations.
Definition: Contacts.hpp:288
std::vector< Math::SpatialVector > d_U
Workspace when applying constraint forces.
Definition: Contacts.hpp:313
Math::SpatialForceV f_t
Workspace for the test forces.
Definition: Contacts.hpp:294
unsigned int addConstraint(unsigned int body_id, const Math::Vector3d &body_point, const Math::Vector3d &world_normal, const char *constraint_name=NULL, double normal_acceleration=0.)
Adds a constraint to the constraint set.
Definition: Contacts.cpp:22
Math::VectorNd acceleration
Definition: Contacts.hpp:237
std::vector< Math::Vector3d > point
Definition: Contacts.hpp:232
std::vector< unsigned int > body
Definition: Contacts.hpp:231
Math::VectorNd x
Workspace for the Lagrangian solution.
Definition: Contacts.hpp:268
Math::VectorNd C
Workspace for the coriolis forces.
Definition: Contacts.hpp:255
bool bound
Whether the constraint set was bound to a model (mandatory!).
Definition: Contacts.hpp:228
void clear()
Clears all variables in the constraint set.
Definition: Contacts.cpp:122
Math::VectorNd impulse
Definition: Contacts.hpp:243
Contains all information about the rigid body model.
Definition: Model.hpp:112