Robot Simulator of the Robotics Group for Self-Organization of Control  0.8.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
substance.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2011 LpzRobots development team *
3  * Georg Martius <georg dot martius at web dot de> *
4  * Frank Guettler <guettler at informatik dot uni-leipzig dot de *
5  * Frank Hesse <frank at nld dot ds dot mpg dot de> *
6  * Ralf Der <ralfder at mis dot mpg dot de> *
7  * Guillaume de Chambrier <s0672742 at sms dot ed dot ac dot uk> *
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  * This program is distributed in the hope that it will be useful, *
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
17  * GNU General Public License for more details. *
18  * *
19  * You should have received a copy of the GNU General Public License *
20  * along with this program; if not, write to the *
21  * Free Software Foundation, Inc., *
22  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
23  * *
24  ***************************************************************************/
25 /*
26 This file concerns material implementation in the simulator.
27 
28 Terminology:
29 Since "Material" is used for OpenGL stuff and also in OSG
30  we should use something else for the physical material: substance
31 
32 So how to implement substance to cover all collission cases and requirements.
33 It would be nice to keep the collisioncontrol as it is for compatibility reasons.
34 In general:
35 
36 - every ode geom should get a user data pointer to the primitive
37 - primitive has a certain substance
38 - 2 substance define collision parameters
39 - also an optional callback function for user defined handling
40 - collission detection is done globally.
41 - via joint connected geoms are stored in a set (globally)
42 - spaces are globally registered
43 
44  ***************************************************************************/
45 #ifndef __SUBSTANCE_H
46 #define __SUBSTANCE_H
47 
48 #include<ode-dbl/common.h>
49 #include<ode-dbl/contact.h>
50 
51 namespace lpzrobots {
52 
53  // Todo: maybe add bounce
54 
55  class GlobalData;
56  class Substance;
57  class Axis;
58 
59  /** function to be called at a collision event between the two geoms.
60  @param params surface parameter, which should be changed/calculated by this function
61  @param globaldata global information
62  @param userdata pointer to user data for this callback (stored in substance)
63  @param contacts array of contact information
64  @param numContacts length of contact information array
65  @param o1 geom corresponding to substance of this callback
66  @param o2 other geom
67  @param s1 substance of this callback
68  @param s2 other substance
69  @return 0 if collision should not be treated;
70  1 if collision should be treated otherwise (by other callback or standard methods);
71  2 if collision to be treated and parameters for collision are set in params
72  */
73  typedef int (*CollisionCallback)(dSurfaceParameters& params, GlobalData& globaldata, void *userdata,
74  dContact* contacts, int numContacts,
75  dGeomID o1, dGeomID o2, const Substance& s1, const Substance& s2);
76 
77  /**
78  Physical substance definition, used for collision detection/treatment
79  What we need is mu, slip and kp,kd parameter for the collision
80  Definition of substance parameters:
81  <pre>
82  Parameter interval collision_parameter
83  roughness: [0-] mu = roughness1*roughness2
84  slip: [0-] slip = slip1+slip2
85  hardness: [0-] kp = hardness1 * hardness2 / (hardness1 + hardness2) (two springs serial)
86  elasticity: [0-1] kd = (1-elasticity1) * s2.hardness + (1-elasticity2) * s1.hardness) /
87  (s1.hardness + s2.hardness);
88  </pre>
89  For the calculation of the spring/damping constant we use the following schema:
90  The collision can be considered as 2 springs serially connected.
91  The spring constant of each collision side is given by hardness (here kp). The spring constant of
92  the entire spring is given by \f[ 1/kp = 1/kp_1 + 1/kp_2\f].
93  The damping (kd) is derived from the elasticity (e), but it is more difficult to compute.
94  Consider the damping in form of energy lost.
95  We can write the energy or work done by each spring as: \f[ W_i = F*s_i = F^2/p \f] with \f[s_i=F*kp_i\f].
96  The energy lost though damping is \f[ W_1^D = W_i*(1-e_i) \f].
97  The final damping is now: \f[ kd = (1-e) = W^D/W = \frac{(1-e_1)/kp_1 + (1-e_2)/kp_2}{1/kp_1 + 1/kp_2}
98  = \frac{(1-e_1)kp_2 + (1-e_2)kp_1}{kp_1+kp_2}\f].
99 
100  Note that you cannot add any member variables to derived classes
101  since they do not fit into the substance object in OdeHandle!
102  */
103  class Substance {
104  public:
105  Substance();
106  Substance( float roughness, float slip, float hardness, float elasticity);
107 
108  public:
109 
110  float roughness;
111  float slip;
112  float hardness;
113  float elasticity;
114 
116 
118  void* userdata;
119 
120  public:
121  /// Combination of two surfaces
122  static void getSurfaceParams(dSurfaceParameters& sp, const Substance& s1, const Substance& s2, double stepsize);
123 
124  static void printSurfaceParams(const dSurfaceParameters& surfParams);
125 
126  //// Factory methods
127 
128  /// default substance is plastic with roughness=0.8
130  void toDefaultSubstance();
131 
132  /// very hard and elastic with slip roughness [0.1-1]
133  static Substance getMetal(float roughness);
134  /// very hard and elastic with slip roughness [0.1-1]
135  void toMetal(float roughness);
136 
137  /// high roughness, no slip, very elastic, hardness : [5-50]
138  static Substance getRubber(float hardness);
139  /// high roughness, no slip, very elastic, hardness : [5-50]
140  void toRubber(float hardness);
141 
142  /// medium slip, a bit elastic, medium hardness, roughness [0.5-2]
143  static Substance getPlastic(float roughness);
144  /// medium slip, a bit elastic, medium hardness, roughness [0.5-2]
145  void toPlastic(float roughness);
146 
147  /// large slip, not elastic, low hardness [1-30], high roughness
148  static Substance getFoam(float _hardness);
149  /// large slip, not elastic, low hardness [1-30], high roughness
150  void toFoam(float _hardness);
151 
152  /** variable slip and roughness [0-1], not elastic, high hardness for solid snow
153  slip = 1 <--> roughness=0.0, slip = 0 <--> roughnes=1.0 */
154  static Substance getSnow(float _slip);
155  /** variable slip and roughness, not elastic, high hardness for solid snow
156  slip = 1 <--> roughness=0.0, slip = 0 <--> roughnes=1.0 */
157  void toSnow(float _slip);
158 
159  /// @see toNoContact()
160  static Substance getNoContact();
161  /** set the collsion callback to ignores everything
162  Usually it is better to use the "ignorePairs" from odeHandle but
163  if this particular one substance should not collide with any other, this is easier.
164  WARNING: this sets the collisionCallback. This will not convert to other
165  substances without manually setting the callback to 0
166  */
167  void toNoContact();
168 
169  /** enables anisotrop friction.
170  The friction along the given axis is ratio fold of the friction in the other directions.
171  If ratio = 0.1 and axis=Axis(0,0,1) then the fiction along the z-axis
172  is 1/10th of the normal friction.
173  Useful to mimic scales of snakes or the like.
174  WARNING: this sets the collisionCallback!
175  To disable the collisionCallback has to set to 0 manually
176  */
177  void toAnisotropFriction(double ratio, const Axis& axis);
178  };
179 
180 
181  class DebugSubstance : public Substance {
182  public:
183  DebugSubstance();
184  DebugSubstance( float roughness, float slip, float hardness, float elasticity);
185  protected:
186  static int dbg_output(dSurfaceParameters& params, GlobalData& globaldata, void *userdata,
187  dContact* contacts, int numContacts,
188  dGeomID o1, dGeomID o2, const Substance& s1, const Substance& s2);
189  };
190 
191 }
192 
193 #endif
194 
195 
void * userdata
Definition: substance.h:118
void toNoContact()
set the collsion callback to ignores everything Usually it is better to use the "ignorePairs" from od...
Definition: substance.cpp:209
Definition: axis.h:36
Physical substance definition, used for collision detection/treatment What we need is mu...
Definition: substance.h:103
static Substance getDefaultSubstance()
default substance is plastic with roughness=0.8
Definition: substance.cpp:95
void toMetal(float roughness)
very hard and elastic with slip roughness [0.1-1]
Definition: substance.cpp:112
static int dbg_output(dSurfaceParameters &params, GlobalData &globaldata, void *userdata, dContact *contacts, int numContacts, dGeomID o1, dGeomID o2, const Substance &s1, const Substance &s2)
Definition: substance.cpp:281
void toPlastic(float roughness)
medium slip, a bit elastic, medium hardness, roughness [0.5-2]
Definition: substance.cpp:147
Substance()
Definition: substance.cpp:36
float hardness
Definition: substance.h:112
static Substance getPlastic(float roughness)
medium slip, a bit elastic, medium hardness, roughness [0.5-2]
Definition: substance.cpp:139
void toRubber(float hardness)
high roughness, no slip, very elastic, hardness : [5-50]
Definition: substance.cpp:129
Definition: substance.h:181
float slip
Definition: substance.h:111
static Substance getMetal(float roughness)
very hard and elastic with slip roughness [0.1-1]
Definition: substance.cpp:106
Data structure holding all essential global information.
Definition: globaldata.h:57
DebugSubstance()
Definition: substance.cpp:270
static Substance getSnow(float _slip)
variable slip and roughness [0-1], not elastic, high hardness for solid snow slip = 1 <–> roughness=0...
Definition: substance.cpp:176
int(* CollisionCallback)(dSurfaceParameters &params, GlobalData &globaldata, void *userdata, dContact *contacts, int numContacts, dGeomID o1, dGeomID o2, const Substance &s1, const Substance &s2)
function to be called at a collision event between the two geoms.
Definition: substance.h:73
static Substance getNoContact()
Definition: substance.cpp:195
void toFoam(float _hardness)
large slip, not elastic, low hardness [1-30], high roughness
Definition: substance.cpp:165
void toDefaultSubstance()
Definition: substance.cpp:101
static Substance getFoam(float _hardness)
large slip, not elastic, low hardness [1-30], high roughness
Definition: substance.cpp:157
CollisionCallback callback
Definition: substance.h:117
void toSnow(float _slip)
variable slip and roughness, not elastic, high hardness for solid snow slip = 1 <–> roughness=0...
Definition: substance.cpp:185
void toAnisotropFriction(double ratio, const Axis &axis)
enables anisotrop friction.
Definition: substance.cpp:259
static void printSurfaceParams(const dSurfaceParameters &surfParams)
Definition: substance.cpp:86
float elasticity
Definition: substance.h:113
static void getSurfaceParams(dSurfaceParameters &sp, const Substance &s1, const Substance &s2, double stepsize)
Combination of two surfaces.
Definition: substance.cpp:54
void setCollisionCallback(CollisionCallback func, void *userdata)
Definition: substance.cpp:48
static Substance getRubber(float hardness)
high roughness, no slip, very elastic, hardness : [5-50]
Definition: substance.cpp:122
float roughness
Definition: substance.h:110