Moby
ConstraintStabilization.h
1 /****************************************************************************
2  * Copyright 2015 Evan Drumwright
3  * This library is distributed under the terms of the Apache V2.0
4  * License (obtainable from http://www.apache.org/licenses/LICENSE-2.0).
5  ****************************************************************************/
6 
7 #ifndef _CONSTRAINT_STABILIZATION_H
8 #define _CONSTRAINT_STABILIZATION_H
9 
10 #include <vector>
11 #include <Ravelin/DynamicBodyd.h>
12 #include <Moby/LCP.h>
13 #include <Moby/UnilateralConstraintProblemData.h>
14 #include <Moby/PairwiseDistInfo.h>
15 
16 namespace Moby {
17 
18 class ConstraintSimulator;
19 
22 {
23  public:
25  void stabilize(boost::shared_ptr<ConstraintSimulator> sim);
26 
27  // tolerance to solve unilateral constraints to
28  double eps;
29 
30  // tolerance to solve bilateral constraints to
31  double bilateral_eps;
32 
33  // maximum number of iterations for constraint stabilization
34  unsigned max_iterations;
35 
36  private:
37  void get_body_configurations(Ravelin::VectorNd& q, boost::shared_ptr<ConstraintSimulator> sim);
38  void update_body_configurations(const Ravelin::VectorNd& q, boost::shared_ptr<ConstraintSimulator> sim);
39  bool update_q(const Ravelin::VectorNd& dq, Ravelin::VectorNd& q, boost::shared_ptr<ConstraintSimulator> sim);
40  void compute_problem_data(std::vector<UnilateralConstraintProblemData>& pd, boost::shared_ptr<ConstraintSimulator> sim);
41  void add_contact_constraints(std::vector<UnilateralConstraint>& constraints, CollisionGeometryPtr cg1, CollisionGeometryPtr cg2, boost::shared_ptr<ConstraintSimulator> sim);
42  void add_limit_constraints(const std::vector<ControlledBodyPtr>& bodies, std::vector<UnilateralConstraint>& constraints);
43  void generate_body_index_map(std::map<boost::shared_ptr<Ravelin::DynamicBodyd>, unsigned>& body_index_map, boost::shared_ptr<ConstraintSimulator> sim);
44  static void set_unilateral_constraint_data(UnilateralConstraintProblemData& pd, const std::list<boost::shared_ptr<Ravelin::SingleBodyd> >& single_bodies);
45  static void set_bilateral_only_constraint_data(UnilateralConstraintProblemData& q, const std::vector<boost::shared_ptr<Ravelin::DynamicBodyd> >& island);
46  void determine_dq(UnilateralConstraintProblemData& pd, Ravelin::VectorNd& dqm, const std::map<boost::shared_ptr<Ravelin::DynamicBodyd>, unsigned>& body_index_map);
47  void update_from_stacked(const Ravelin::VectorNd& z, UnilateralConstraintProblemData& pd);
48  void update_velocities(const UnilateralConstraintProblemData& pd);
49  static double get_min_pairwise_dist(const std::vector<PairwiseDistInfo>& pdi);
50  static boost::shared_ptr<Ravelin::DynamicBodyd> get_super_body_from_rigid_body(boost::shared_ptr<Ravelin::RigidBodyd> sb);
51  static boost::shared_ptr<Ravelin::DynamicBodyd> get_super_body(boost::shared_ptr<Ravelin::DynamicBodyd> sb);
52  double ridders_unilateral(double x1, double x2, double fx1, double fx2, unsigned i, const Ravelin::VectorNd& dq, const Ravelin::VectorNd& q, boost::shared_ptr<ConstraintSimulator> sim);
53  double ridders_bilateral(double x1, double x2, double fx1, double fx2, unsigned i, const Ravelin::VectorNd& dq, const Ravelin::VectorNd& q, boost::shared_ptr<ConstraintSimulator> sim);
54  double eval_unilateral(double t, unsigned i, const Ravelin::VectorNd& dq, const Ravelin::VectorNd& q, boost::shared_ptr<ConstraintSimulator> sim);
55  double eval_bilateral(double t, unsigned i, const Ravelin::VectorNd& dq, const Ravelin::VectorNd& q, boost::shared_ptr<ConstraintSimulator> sim);
56  static void save_velocities(boost::shared_ptr<ConstraintSimulator> sim, std::vector<Ravelin::VectorNd>& qd);
57  static void restore_velocities(boost::shared_ptr<ConstraintSimulator> sim, const std::vector<Ravelin::VectorNd>& qd);
58  static void add_contact_to_Jacobian(const UnilateralConstraint& c, SparseJacobian& Cn, const std::map<boost::shared_ptr<Ravelin::DynamicBodyd>, unsigned>& gc_map, unsigned contact_idx);
59  static double evaluate_unilateral_constraints(boost::shared_ptr<ConstraintSimulator> sim, std::vector<double>& uC);
60  static double evaluate_bilateral_constraints(boost::shared_ptr<ConstraintSimulator> sim, std::vector<double>& C);
61 
62  // the LCP solver
63  LCP _lcp;
64 
65  // the unilateral constraints
66  std::vector<UnilateralConstraint> constraints;
67 
69  std::vector<std::pair<CollisionGeometryPtr, CollisionGeometryPtr> > _pairs_to_check;
70 }
71 ;
72 
73 } // end namespace
74 
75 #endif
A Sparse Jacobian representation along with multiplication routines.
Definition: SparseJacobian.h:30
boost::shared_ptr< CollisionGeometry > CollisionGeometryPtr
Collision geometry smart pointer.
Definition: Types.h:77
Projected constraint stabilization mechanism.
Definition: ConstraintStabilization.h:21
void stabilize(boost::shared_ptr< ConstraintSimulator > sim)
Stabilizes the constraints in the simulator.
Definition: ConstraintStabilization.cpp:167
Container class for describing a unilateral constraint in the simulation.
Definition: UnilateralConstraint.h:27