Moby
ConstraintSimulator.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_SIMULATOR_H
8 #define _CONSTRAINT_SIMULATOR_H
9 
10 #include <map>
11 #include <Ravelin/sorted_pair>
12 #include <Moby/Simulator.h>
13 #include <Moby/ImpactConstraintHandler.h>
14 #include <Moby/PenaltyConstraintHandler.h>
15 #include <Moby/SustainedUnilateralConstraintHandler.h>
16 #include <Moby/PairwiseDistInfo.h>
17 #include <Moby/CCD.h>
18 #include <Moby/UnilateralConstraint.h>
19 #include <Moby/ConstraintStabilization.h>
20 
21 namespace Moby {
22 
23 class Dissipation;
24 class ContactParameters;
25 class CollisionDetection;
26 class CollisionGeometry;
27 
30 {
31  friend class CollisionDetection;
32  friend class ConstraintStabilization;
33 
34  public:
36  virtual void load_from_xml(boost::shared_ptr<const XMLTree> node, std::map<std::string, BasePtr>& id_map);
37  virtual void save_to_xml(XMLTreePtr node, std::list<boost::shared_ptr<const Base> >& shared_objects) const;
38  boost::shared_ptr<ContactParameters> get_contact_parameters(CollisionGeometryPtr geom1, CollisionGeometryPtr geom2) const;
39  const std::vector<PairwiseDistInfo>& get_pairwise_distances() const { return _pairwise_distances; }
40 
43 
45  std::set<Ravelin::sorted_pair<CollisionGeometryPtr> > unchecked_pairs;
46 
48  std::vector<std::pair<ControlledBodyPtr, Ravelin::VectorNd> > _x0, _x1;
49 
51  boost::shared_ptr<ContactParameters> (*get_contact_parameters_callback_fn)(CollisionGeometryPtr g1, CollisionGeometryPtr g2);
52 
55 
57 
62  void (*constraint_callback_fn)(std::vector<UnilateralConstraint>&, boost::shared_ptr<void>);
63 
65  void (*constraint_post_callback_fn)(const std::vector<UnilateralConstraint>&, boost::shared_ptr<void>);
66 
68  boost::shared_ptr<void> constraint_callback_data;
69 
71  boost::shared_ptr<void> constraint_post_callback_data;
72 
74  std::vector<UnilateralConstraint>& get_compliant_constraints() { return _compliant_constraints; }
75 
77  std::vector<UnilateralConstraint>& get_rigid_constraints() { return _rigid_constraints; }
78 
80  std::map<Ravelin::sorted_pair<BasePtr>, boost::shared_ptr<ContactParameters> > contact_params;
81 
84 
86  boost::shared_ptr<CollisionDetection> get_collision_detection() const { return _coldet; }
87 
88  protected:
93  void determine_geometries();
94  void broad_phase(double dt);
96  void visualize_contact( UnilateralConstraint& constraint );
97 
100 
103 
105  std::vector<UnilateralConstraint> _rigid_constraints;
106 
108  std::vector<UnilateralConstraint> _compliant_constraints;
109 
110  protected:
111 
112  double calc_CA_step();
113  double calc_next_CA_Euler_step(double contact_dist_thresh) const;
114 
116  std::vector<PairwiseDistInfo> _pairwise_distances;
117 
119  Ravelin::VectorNd _workV;
120 
122  boost::shared_ptr<CollisionDetection> _coldet;
123 
125  std::vector<CollisionGeometryPtr> _geometries;
126 
128  std::vector<std::pair<CollisionGeometryPtr, CollisionGeometryPtr> > _pairs_to_check;
129 }; // end class
130 
131 } // end namespace
132 
133 #endif
134 
135 
std::vector< std::pair< ControlledBodyPtr, Ravelin::VectorNd > > _x0
Vectors set and passed to collision detection.
Definition: ConstraintSimulator.h:48
ConstraintStabilization cstab
The constraint stabilization mechanism.
Definition: ConstraintSimulator.h:42
Defines an abstract collision detection mechanism.
Definition: CollisionDetection.h:38
std::vector< UnilateralConstraint > _rigid_constraints
The vector of rigid constraints.
Definition: ConstraintSimulator.h:105
void visualize_contact(UnilateralConstraint &constraint)
Draws a ray directed from a contact point along the contact normal.
Definition: ConstraintSimulator.cpp:156
std::vector< CollisionGeometryPtr > _geometries
The geometries in the simulator.
Definition: ConstraintSimulator.h:125
void(* constraint_callback_fn)(std::vector< UnilateralConstraint > &, boost::shared_ptr< void >)
The callback function (called when constraints have been determined)
Definition: ConstraintSimulator.h:62
Defines the mechanism for handling Penalty constraints.
Definition: PenaltyConstraintHandler.h:22
std::vector< UnilateralConstraint > & get_compliant_constraints()
Gets the (sorted) compliant constraint data.
Definition: ConstraintSimulator.h:74
void preprocess_constraint(UnilateralConstraint &e)
Performs necessary preprocessing on an constraint.
Definition: ConstraintSimulator.cpp:393
ImpactConstraintHandler _impact_constraint_handler
Object for handling impact constraints.
Definition: ConstraintSimulator.h:99
boost::shared_ptr< void > constraint_post_callback_data
Data passed to post-constraint callback.
Definition: ConstraintSimulator.h:71
An virtual class for simulation with constraints.
Definition: ConstraintSimulator.h:29
std::vector< std::pair< CollisionGeometryPtr, CollisionGeometryPtr > > _pairs_to_check
Geometric pairs that should be checked for unilateral constraints (according to broad phase collision...
Definition: ConstraintSimulator.h:128
void(* post_mini_step_callback_fn)(ConstraintSimulator *s)
Callback function after a mini-step is completed.
Definition: ConstraintSimulator.h:54
std::set< Ravelin::sorted_pair< CollisionGeometryPtr > > unchecked_pairs
Determines whether two geometries are not checked.
Definition: ConstraintSimulator.h:45
boost::shared_ptr< void > constraint_callback_data
Data passed to unilateral constraint callback.
Definition: ConstraintSimulator.h:68
std::map< Ravelin::sorted_pair< BasePtr >, boost::shared_ptr< ContactParameters > > contact_params
Mapping from objects to contact parameters.
Definition: ConstraintSimulator.h:80
virtual void save_to_xml(XMLTreePtr node, std::list< boost::shared_ptr< const Base > > &shared_objects) const
Implements Base::save_to_xml()
Definition: ConstraintSimulator.cpp:717
Defines the mechanism for handling impact constraints.
Definition: ImpactConstraintHandler.h:37
void(* constraint_post_callback_fn)(const std::vector< UnilateralConstraint > &, boost::shared_ptr< void >)
The callback function (called after forces/impulses are applied)
Definition: ConstraintSimulator.h:65
boost::shared_ptr< CollisionGeometry > CollisionGeometryPtr
Collision geometry smart pointer.
Definition: Types.h:77
boost::shared_ptr< XMLTree > XMLTreePtr
XML tree smart pointer.
Definition: Types.h:104
void find_unilateral_constraints()
Finds the set of unilateral constraints.
Definition: ConstraintSimulator.cpp:491
virtual void load_from_xml(boost::shared_ptr< const XMLTree > node, std::map< std::string, BasePtr > &id_map)
Implements Base::load_from_xml()
Definition: ConstraintSimulator.cpp:561
boost::shared_ptr< CollisionDetection > get_collision_detection() const
Gets the collision detection mechanism.
Definition: ConstraintSimulator.h:86
std::vector< UnilateralConstraint > & get_rigid_constraints()
Gets the (sorted) rigid constraint data.
Definition: ConstraintSimulator.h:77
void calc_impacting_unilateral_constraint_forces(double dt)
Handles constraints.
Definition: ConstraintSimulator.cpp:296
void calc_compliant_unilateral_constraint_forces()
Computes compliant contact forces.
Definition: ConstraintSimulator.cpp:361
PenaltyConstraintHandler _penalty_constraint_handler
Object for handling penalty constraints.
Definition: ConstraintSimulator.h:102
Simulator for both unarticulated and articulated rigid bodies without contact.
Definition: Simulator.h:40
Projected constraint stabilization mechanism.
Definition: ConstraintStabilization.h:21
bool render_contact_points
If set to 'true' simulator will process contact points for rendering.
Definition: ConstraintSimulator.h:83
std::vector< UnilateralConstraint > _compliant_constraints
The vector of compliant constraints.
Definition: ConstraintSimulator.h:108
boost::shared_ptr< CollisionDetection > _coldet
The collision detection mechanism.
Definition: ConstraintSimulator.h:122
Container class for describing a unilateral constraint in the simulation.
Definition: UnilateralConstraint.h:27
std::vector< PairwiseDistInfo > _pairwise_distances
Pairwise distances at bodies' current configurations.
Definition: ConstraintSimulator.h:116
void calc_pairwise_distances()
Computes pairwise distances of geometries at their current poses, using broad phase results to determ...
Definition: ConstraintSimulator.cpp:453
Ravelin::VectorNd _workV
Work vector.
Definition: ConstraintSimulator.h:119
ConstraintSimulator()
Default constructor.
Definition: ConstraintSimulator.cpp:48
void determine_geometries()
Sets up the list of collision geometries.
Definition: ConstraintSimulator.cpp:422
boost::shared_ptr< ContactParameters > get_contact_parameters(CollisionGeometryPtr geom1, CollisionGeometryPtr geom2) const
Gets the contact data between a pair of geometries (if any)
Definition: ConstraintSimulator.cpp:80
void broad_phase(double dt)
Does broad phase collision detection, identifying which pairs of geometries may come into contact ove...
Definition: ConstraintSimulator.cpp:474