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
hexapod.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 
27 #ifndef __HEXAPOD_H
28 #define __HEXAPOD_H
29 
30 #include <selforg/inspectable.h>
31 
32 #include <ode_robots/oderobot.h>
33 #include <ode_robots/raysensorbank.h>
34 #include <ode_robots/contactsensor.h>
35 
36 namespace lpzrobots {
37 
38  class Primitive;
39  class Joint;
40  class OneAxisServo;
41  class TwoAxisServo;
42 
43 
44  struct HexapodConf {
45  double size; ///< scaling factor for robot (diameter of body)
46  double legLength; ///< length of the legs in units of size
47  int legNumber; ///< number of snake elements
48  double width; ///< body with in units of size
49  double height; ///< body with in units of size
50  double mass; ///< chassis mass
51  double percentageBodyMass; ///< relation between bodymass(trunk) and rest
52 
53  double coxaPower; ///< maximal force for at hip joint motors
54  double coxaJointLimitV; ///< angle range for vertical direction of legs
55  double coxaJointLimitH; ///< angle range for horizontal direction of legs
56  double coxaDamping; ///< damping of hip joint servos
57  double coxaSpeed; ///< speed of the hip servo
58 
59  bool useTebiaJoints; ///< whether to use joints at the knees
60  bool useTebiaMotors; ///< if true tebia joints are actuated, otherwise springs
61  double tebiaPower; ///< spring strength in the knees
62  double tebiaJointLimit; ///< angle range for knees
63  double tebiaOffset; ///< angle offset for knees
64  double tebiaDamping; ///< damping in the knees
65 
66  double legSpreading; ///< angle at which legs are spread to the front and back
67  double backLegFactor; ///< size factor for back legs
68 
69  bool tarsus; ///< whether to use a tarsus or not
70  int numTarsusSections; ///< the number of sections in the tarsus
71  bool useTarsusJoints; ///< whether to use joints on the tarsus
72  bool useBigBox; ///< whether to use a big invisible box on the back of the robot
73 
74  bool useWhiskers; ///< if true add whiskers to robot
75  bool useActiveWhisker; ///< if true whiskers have motorized joints, otherwise springs
76  double whiskerSpread; ///< angle by which the wiskers are spread
77 
78  double T; ///< T is the for the time for calculating the cost of transport over time
79  double *v;
80 
82 
84 
88  double irSensors;
89  bool irFront;
90  bool irBack;
91  bool irLeft;
92  bool irRight;
93  double irRangeFront;
94  double irRangeBack;
95  double irRangeLeft;
96  double irRangeRight;
97  };
98 
99  struct Leg {
100  int legID;
101  dGeomID geomid;
102  dBodyID bodyID;
103 
104  dJointID joint;
105  };
106 
107 
108  class Hexapod : public OdeRobot, public Inspectable {
109  public:
110 
111  /**
112  * constructor of VierBeiner robot
113  * @param odeHandle data structure for accessing ODE
114  * @param osgHandle ata structure for accessing OSG
115  * @param conf configuration object
116  */
118  const std::string& name);
119 
120  virtual ~Hexapod(){ destroy(); };
121 
123  HexapodConf c;
124  c.size = 1;
125  c.width = 1.0/3.0; //1.0/1.5
126  c.height = 1.0/8.0; //1.0/4.0
127  c.legNumber = 6;
128  c.legLength = 0.6;
129  c.percentageBodyMass = 0.7;
130  c.mass = 1.0;
131  c.v = new double[1];
132  c.coxaPower = 1;
133  c.coxaJointLimitV = M_PI/8.0; ///< angle range for vertical direction of legs
134  c.coxaJointLimitH = M_PI/4.0;
135  c.coxaDamping = 0.0; // Georg: no damping required for new servos
136  c.coxaSpeed = 30; // The speed calculates how it works
137  c.T = 1.0;
138 
139  c.legSpreading = M_PI/12.0;
140  c.backLegFactor = 1.0;
141 
142  c.useTebiaJoints = true;
143  c.useTebiaMotors = false;
144  c.tebiaPower = 1.2;
145  c.tebiaJointLimit = M_PI/4; // +- 45 degree
146  c.tebiaDamping = 0.01; // Georg: the damping reduces the swinging of the system
147  c.tebiaOffset = 0.0;
148 
149  c.tarsus = true;
150  c.numTarsusSections = 2;
151  c.useTarsusJoints = true;
152  c.useBigBox = true;
153 
154  c.whiskerSpread = M_PI/10.0;
155  c.useWhiskers = true;
156  c.useActiveWhisker = false;
157 
158  c.ignoreInternalCollisions = true;
159 
160  c.calculateEnergy = false;
161 
162  c.useContactSensors = false;
163  c.legContacts = new int[6];
164  c.irSensors = false;
165  c.irFront = false;
166  c.irBack = false;
167  c.irLeft = false;
168  c.irRight = false;
169  c.irRangeFront = 3;
170  c.irRangeBack = 2;
171  c.irRangeLeft = 2;
172  c.irRangeRight = 2;
173  // c.elasticity = 10;
174  return c;
175  }
176 
177 
178  /** sets the pose of the vehicle
179  @param pose desired pose matrix
180  */
181  virtual void placeIntern(const osg::Matrix& pose);
182 
183 
184  /** this function is called in each timestep. It should perform robot-internal checks,
185  like space-internal collision detection, sensor resets/update etc.
186  @param globalData structure that contains global data from the simulation environment
187  */
188  virtual void doInternalStuff(GlobalData& globalData);
189 
190 
191  /**
192  * calculates the total energy consumption of all servos.
193  */
194  double round(double,int);
195 
196  virtual double energyConsumption();
197 
198  virtual double energyConsumpThroughtHeatLoss(const dReal *torques);
199 
200  virtual double outwardMechanicalPower(const dReal *torques,const dReal *angularV);
201 
202  virtual double costOfTransport(double E, double W, double V, double T);
203 
204  virtual double getMassOfRobot();
205 
206  virtual double *getPosition(){
207  return position;
208  }
209 
210  /******** CONFIGURABLE ***********/
211  virtual void notifyOnChange(const paramkey& key);
212 
213  virtual void resetMotorPower(double power);
214 
215  virtual double getPower();
216 
217  /** the main object of the robot, which is used for position and speed tracking */
218  virtual Primitive* getMainPrimitive() const { return objects[0]; }
219  protected:
220 
221  /** creates vehicle at desired pose
222  @param pose 4x4 pose matrix
223  */
224  virtual void create(const osg::Matrix& pose);
225 
226  /** destroys vehicle and space
227  */
228  virtual void destroy();
229 
230 public:
232  double legmass; // leg mass
233  bool created; // true if robot was created
234 
235  public:
236  double costOfTran;
237  double* energyOneStep; ///< energy consumption for one time step
238  double E_t; ///< energy consumption over a period t;
240  double *heights;
241  double *angles;
242  private:
243  double hcorrection;
244  bool *dones;
245  bool check;
246  double t;
247  double timeCounter;
248  double *position;
249  std::vector<dReal*> pos_record;
250  dMass *massOfobject;
251  bool getPos1;
252  double speed;
253 
254  std::vector<Leg> legContact;
255  Leg* legContactArray;
256  std::vector<dGeomID> footIDs;
257  protected:
258  // some objects explicitly needed for ignored collision pairs
260  std::vector<Primitive*> legs;
261  std::vector<Primitive*> thorax;
262  std::vector<Pos> thoraxPos;
263 
264  std::vector <std::shared_ptr<TwoAxisServo> > hipservos;
265  std::vector <std::shared_ptr<OneAxisServo> > tebiaservos;
266  std::vector <std::shared_ptr<OneAxisServo> > tarsussprings;
267  };
268 
269 }
270 
271 #endif
double costOfTran
Definition: hexapod.h:236
Matrix type.
Definition: matrix.h:65
double coxaJointLimitH
angle range for horizontal direction of legs
Definition: hexapod.h:55
virtual double * getPosition()
Definition: hexapod.h:206
double tebiaJointLimit
angle range for knees
Definition: hexapod.h:62
Data structure for accessing the ODE.
Definition: odehandle.h:44
virtual Primitive * getMainPrimitive() const
the main object of the robot, which is used for position and speed tracking
Definition: hexapod.h:218
dGeomID geomid
Definition: hexapod.h:101
double E_t
energy consumption over a period t;
Definition: hexapod.h:238
double power(void *c, double x)
returns x the power c (as a double)
Definition: controller_misc.cpp:17
std::vector< std::shared_ptr< OneAxisServo > > tarsussprings
Definition: hexapod.h:266
virtual double getPower()
Definition: hexapod.cpp:678
std::vector< std::shared_ptr< OneAxisServo > > tebiaservos
Definition: hexapod.h:265
Matrixd Matrix
Definition: osgforwarddecl.h:47
charArray paramkey
Definition: avrtypes.h:36
int numTarsusSections
the number of sections in the tarsus
Definition: hexapod.h:70
double height
body with in units of size
Definition: hexapod.h:49
double legmass
Definition: hexapod.h:232
double irRangeRight
Definition: hexapod.h:96
virtual void resetMotorPower(double power)
Definition: hexapod.cpp:682
int legID
Definition: hexapod.h:100
bool recordGait
Definition: hexapod.h:239
iparamkey name
Definition: inspectable.h:251
bool irLeft
Definition: hexapod.h:91
bool ignoreInternalCollisions
Definition: hexapod.h:81
virtual void destroy()
destroys vehicle and space
Definition: hexapod.cpp:667
bool useWhiskers
if true add whiskers to robot
Definition: hexapod.h:74
HexapodConf conf
Definition: hexapod.h:231
bool useActiveWhisker
if true whiskers have motorized joints, otherwise springs
Definition: hexapod.h:75
Data structure for accessing the OpenSceneGraph.
Definition: osghandle.h:79
virtual void create(const osg::Matrix &pose)
creates vehicle at desired pose
Definition: hexapod.cpp:253
bool useBigBox
whether to use a big invisible box on the back of the robot
Definition: hexapod.h:72
bool irRight
Definition: hexapod.h:92
double irRangeBack
Definition: hexapod.h:94
double size
scaling factor for robot (diameter of body)
Definition: hexapod.h:45
double coxaSpeed
speed of the hip servo
Definition: hexapod.h:57
static HexapodConf getDefaultConf()
Definition: hexapod.h:122
virtual void notifyOnChange(const paramkey &key)
Is called when a parameter was changes via setParam().
Definition: hexapod.cpp:689
Primitive * headtrans
Definition: hexapod.h:259
Primitive * bigboxtransform
Definition: hexapod.h:259
double T
T is the for the time for calculating the cost of transport over time.
Definition: hexapod.h:78
virtual ~Hexapod()
Definition: hexapod.h:120
double coxaJointLimitV
angle range for vertical direction of legs
Definition: hexapod.h:54
Primitive * irbox
Definition: hexapod.h:259
double backLegFactor
size factor for back legs
Definition: hexapod.h:67
bool calculateEnergy
Definition: hexapod.h:83
Primitive * trunk
Definition: hexapod.h:259
virtual double outwardMechanicalPower(const dReal *torques, const dReal *angularV)
Definition: hexapod.cpp:121
virtual double getMassOfRobot()
Definition: hexapod.cpp:157
double * heights
Definition: hexapod.h:240
double coxaDamping
damping of hip joint servos
Definition: hexapod.h:56
std::vector< Primitive * > thorax
Definition: hexapod.h:261
double tebiaPower
spring strength in the knees
Definition: hexapod.h:61
bool irFront
Definition: hexapod.h:89
Interface class for primitives represented in the physical and graphical world.
Definition: primitive.h:80
Definition: hexapod.h:99
double legSpreading
angle at which legs are spread to the front and back
Definition: hexapod.h:66
double tebiaOffset
angle offset for knees
Definition: hexapod.h:63
double coxaPower
maximal force for at hip joint motors
Definition: hexapod.h:53
double irSensors
Definition: hexapod.h:88
Hexapod(const OdeHandle &odeHandle, const OsgHandle &osgHandle, const HexapodConf &conf, const std::string &name)
constructor of VierBeiner robot
Definition: hexapod.cpp:60
double irRangeLeft
Definition: hexapod.h:95
Data structure holding all essential global information.
Definition: globaldata.h:57
double legLength
length of the legs in units of size
Definition: hexapod.h:46
dBodyID bodyID
Definition: hexapod.h:102
bool useTarsusJoints
whether to use joints on the tarsus
Definition: hexapod.h:71
bool useTebiaMotors
if true tebia joints are actuated, otherwise springs
Definition: hexapod.h:60
bool created
Definition: hexapod.h:233
Interface for inspectable objects.
Definition: inspectable.h:48
matrix::Matrix m
Definition: hexapod.h:86
double * angles
Definition: hexapod.h:241
double tebiaDamping
damping in the knees
Definition: hexapod.h:64
double irRangeFront
Definition: hexapod.h:93
bool tarsus
whether to use a tarsus or not
Definition: hexapod.h:69
bool useTebiaJoints
whether to use joints at the knees
Definition: hexapod.h:59
OsgHandle osgHandle
Definition: oderobot.h:278
OdeHandle odeHandle
Definition: oderobot.h:277
virtual double costOfTransport(double E, double W, double V, double T)
Definition: hexapod.cpp:168
virtual double energyConsumpThroughtHeatLoss(const dReal *torques)
Definition: hexapod.cpp:136
virtual void doInternalStuff(GlobalData &globalData)
this function is called in each timestep.
Definition: hexapod.cpp:181
virtual void placeIntern(const osg::Matrix &pose)
sets the pose of the vehicle
Definition: hexapod.cpp:112
const int T
integer constant for use with exp function and (^) operator to transpose the matrix ...
Definition: matrix.cpp:21
int legNumber
number of snake elements
Definition: hexapod.h:47
double percentageBodyMass
relation between bodymass(trunk) and rest
Definition: hexapod.h:51
Abstract class for ODE robots.
Definition: oderobot.h:64
int * legContacts
Definition: hexapod.h:87
std::vector< Primitive * > legs
Definition: hexapod.h:260
bool useContactSensors
Definition: hexapod.h:85
double width
body with in units of size
Definition: hexapod.h:48
Definition: hexapod.h:108
Primitives objects
list of objects (should be populated by subclasses)
Definition: oderobot.h:265
double round(double, int)
calculates the total energy consumption of all servos.
Definition: hexapod.cpp:172
std::vector< std::shared_ptr< TwoAxisServo > > hipservos
Definition: hexapod.h:264
virtual double energyConsumption()
Definition: hexapod.cpp:142
dJointID joint
Definition: hexapod.h:104
std::vector< Pos > thoraxPos
Definition: hexapod.h:262
Definition: hexapod.h:44
double whiskerSpread
angle by which the wiskers are spread
Definition: hexapod.h:76
Primitive * stabaliserTransform
Definition: hexapod.h:259
int c
Definition: hexapod.cpp:56
double * energyOneStep
energy consumption for one time step
Definition: hexapod.h:237
bool irBack
Definition: hexapod.h:90
double * v
Definition: hexapod.h:79
double mass
chassis mass
Definition: hexapod.h:50