Klamp't  0.8.1
WorldSimulation.h
1 #ifndef WORLD_SIMULATION_H
2 #define WORLD_SIMULATION_H
3 
5 #include "ODESimulator.h"
6 #include "ControlledSimulator.h"
7 #include <map>
8 
24 {
25  //summary information
26  bool accum;
27  int contactCount,separationCount;
28  bool inContact;
29  Vector3 meanForce,meanTorque,meanPoint;
30 
31  bool penetrating;
33 
34  //full contact information over sub-steps
35  bool accumFull; //set to true if all ODEContactLists should be stored
36  vector<double> times;
37  vector<ODEContactList> contactLists;
38 };
39 
54 {
55  public:
56  WorldSimulationHook() : autokill(false) {}
57  virtual ~WorldSimulationHook() {}
58  virtual void Step(Real dt) {}
59  virtual bool ReadState(File& f) { return true; }
60  virtual bool WriteState(File& f) const { return true; }
61  bool autokill;
62 };
63 
68 {
69 public:
71  void Init(RobotWorld* world);
73  void OnAddModel();
75  void SetController(int robot,shared_ptr<RobotController> c);
77  void Advance(Real dt);
79  void AdvanceFake(Real dt);
81  void UpdateModel();
83  void UpdateRobot(int index);
87  bool ReadState(File& f);
88  bool WriteState(File& f) const;
89  bool ReadState(const string& data);
90  bool WriteState(string& data) const;
91 
92  //contact querying routines
96  void EnableContactFeedback(int aid,int bid,bool accum=true,bool accumFull=false);
101  bool InContact(int aid,int bid=-1);
103  bool HadContact(int aid,int bid=-1);
105  bool HadSeparation(int aid,int bid=-1);
110  bool HadPenetration(int aid,int bid=-1);
112  ContactFeedbackInfo* GetContactFeedback(int aid,int bid);
114  ODEContactList* GetContactList(int aid,int bid);
116  Vector3 ContactForce(int aid,int bid=-1);
118  Vector3 ContactTorque(int aid,int bid=-1);
120  Vector3 MeanContactForce(int aid,int bid=-1);
122  Vector3 MeanContactTorque(int aid,int bid=-1);
123 
124  //helpers to convert indexing schemes
125  int ODEToWorldID(const ODEObjectID& odeid) const;
126  ODEObjectID WorldToODEID(int id) const;
127 
128  RobotWorld* world;
129  ODESimulator odesim;
130  Real time;
131  Real simStep;
132  bool fakeSimulation;
133  vector<ControlledRobotSimulator> controlSimulators;
134  vector<shared_ptr<RobotController> > robotControllers;
135  vector<shared_ptr<WorldSimulationHook> > hooks;
136  typedef map<pair<ODEObjectID,ODEObjectID>,ContactFeedbackInfo> ContactFeedbackMap;
137  ContactFeedbackMap contactFeedback;
140 };
141 
146 {
147  public:
148  ForceHook(dBodyID body,const Vector3& worldpt,const Vector3& f);
149  virtual void Step(Real dt);
150  virtual bool ReadState(File& f);
151  virtual bool WriteState(File& f) const;
152 
153  dBodyID body;
154  Vector3 worldpt,f;
155 };
156 
162 {
163  public:
164  LocalForceHook(dBodyID body,const Vector3& localpt,const Vector3& f);
165  virtual void Step(Real dt);
166  virtual bool ReadState(File& f);
167  virtual bool WriteState(File& f) const;
168 
169  dBodyID body;
170  Vector3 localpt,f;
171 };
172 
173 
179 {
180  public:
181  WrenchHook(dBodyID body,const Vector3& f,const Vector3& m);
182  virtual void Step(Real dt);
183  virtual bool ReadState(File& f);
184  virtual bool WriteState(File& f) const;
185 
186  dBodyID body;
187  Vector3 f,m;
188 };
189 
194 {
195  public:
196  SpringHook(dBodyID body,const Vector3& worldpt,const Vector3& target,Real k);
197  virtual void Step(Real dt);
198  virtual bool ReadState(File& f);
199  virtual bool WriteState(File& f) const;
200 
201  dBodyID body;
202  Vector3 localpt,target;
203  Real k;
204 };
205 
206 #endif
int penetrationCount
the number of sub-steps in which the objects were penetrating during the outer simulation interval ...
Definition: WorldSimulation.h:32
bool inContact
true if contact exists at the end of the outer simulation interval
Definition: WorldSimulation.h:28
Container for information about contacts regarding a certain object. Can be set to accumulate a summa...
Definition: WorldSimulation.h:23
int separationCount
number of sub-steps in which contact was made / object was separated during the outer simulation inte...
Definition: WorldSimulation.h:27
A hook that adds a constant force to a body.
Definition: WorldSimulation.h:145
A hook that acts as a Hookean spring to a given fixed target point.
Definition: WorldSimulation.h:193
The main world class containing multiple robots, objects, and static geometries (terrains). Lights and other viewport information may also be stored here.
Definition: World.h:20
bool accum
set this to true if you want to accumulate summary feedback over sub-steps
Definition: WorldSimulation.h:26
An interface to the ODE simulator.
Definition: ODESimulator.h:93
A hook that adds a constant wrench (force f and moment m) to the body.
Definition: WorldSimulation.h:178
Status
Definition: ODESimulator.h:108
ODESimulator::Status worstStatus
Worst simulation status over the last Advance() call.
Definition: WorldSimulation.h:139
A list of contacts between two objects, returned as feedback from the simulation. ...
Definition: ODESimulator.h:227
Any function that should be run per sub-step of the simulation needs to be a WorldSimulationHook subc...
Definition: WorldSimulation.h:53
bool penetrating
true if the objects are currently penetrating
Definition: WorldSimulation.h:31
An index that identifies some ODE object in the world. Environments, robots, robot bodies...
Definition: ODESimulator.h:191
A physical simulator for a RobotWorld.
Definition: WorldSimulation.h:67
A hook that adds a constant force in world coordinates to a point on a body given in local coordinate...
Definition: WorldSimulation.h:161