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
defaultCaterpillar.h
Go to the documentation of this file.
1 /************************************************************************/
2 /* originally from: */
3 /* schlange.h */
4 /* Abstract class for Snakes */
5 /* @author Georg Martius */
6 /************************************************************************/
7 /* here: */
8 /* defaultCaterpillar.h */
9 /* Abstract class for Caterpillars */
10 /* @author Frank Guettler */
11 /************************************************************************/
12 /***************************************************************************
13  * Copyright (C) 2005-2011 LpzRobots development team *
14  * Georg Martius <georg dot martius at web dot de> *
15  * Frank Guettler <guettler at informatik dot uni-leipzig dot de *
16  * Frank Hesse <frank at nld dot ds dot mpg dot de> *
17  * Ralf Der <ralfder at mis dot mpg dot de> *
18  * *
19  * This program is free software; you can redistribute it and/or modify *
20  * it under the terms of the GNU General Public License as published by *
21  * the Free Software Foundation; either version 2 of the License, or *
22  * (at your option) any later version. *
23  * *
24  * This program is distributed in the hope that it will be useful, *
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
27  * GNU General Public License for more details. *
28  * *
29  * You should have received a copy of the GNU General Public License *
30  * along with this program; if not, write to the *
31  * Free Software Foundation, Inc., *
32  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
33  * *
34  ***************************************************************************/
35 #ifndef __DEFAULTCATERPILLAR_H
36 #define __DEFAULTCATERPILLAR_H
37 
38 #include<vector>
39 #include<assert.h>
40 
41 #include"primitive.h"
42 #include "joint.h"
43 #include "angularmotor.h"
44 
45 #include "oderobot.h"
46 #include <selforg/configurable.h>
47 
48 namespace lpzrobots {
49 
50 typedef struct {
51 public:
52  int segmNumber; ///< number of snake elements
53  double segmLength; ///< length of one snake element
54  double segmDia; ///< diameter of a snake element
55  double segmMass; ///< mass of one snake element
56  double motorPower; ///< power of the motors / servos
57  double sensorFactor; ///< scale for sensors
58  double frictionGround; ///< friction with ground
59  double frictionJoint; ///< friction within joint
60  double jointLimit; ///< maximal angle for the joints (M_PI/2 = 90 degree)
61  int firstJoint; ///< first joint type to use: 0=sliderJoint, 1=universalJoint
63 
64 
65 /**
66  * This is a class, which models a snake like robot.
67  * It consists of a number of equal elements, each linked
68  * by a joint
69  **/
71 {
72 protected:
73 
74  bool created;
75 
76  std::vector <AngularMotor*> frictionmotors;
78 
79 public:
81  const CaterPillarConf& conf, const std::string& name, const std::string& revision);
82 
85  conf.segmNumber = 6; // number of snake elements
86  conf.segmLength = 0.4; // length of one snake element
87  conf.segmDia = 0.2; // diameter of a snake element
88  conf.segmMass = 0.4; // mass of one snake element
89  conf.motorPower = 1; // power of the servos
90  conf.sensorFactor = 1; // scale for sensors
91  conf.frictionGround = 1.0; // friction with ground
92  conf.frictionJoint = 0.1; // friction within joint
93  conf.jointLimit = M_PI/8;
94  conf.firstJoint=1;
95  return conf;
96  }
97 
98  virtual ~DefaultCaterPillar();
99 
100 
101  /** sets the pose of the vehicle
102  @param pose desired 4x4 pose matrix
103  */
104  virtual void placeIntern(const osg::Matrix& pose);
105 
106  /// update all primitives and joints
107  virtual void update();
108 
109  /**
110  *Reads the actual motor commands from an array,
111  *an sets all motors of the snake to this values.
112  *It is an linear allocation.
113  *@param motors pointer to the array, motor values are scaled to [-1,1]
114  *@param motornumber length of the motor array
115  **/
116  virtual void setMotorsIntern( const double* motors, int motornumber ) = 0;
117 
118  /**
119  *Writes the sensor values to an array in the memory.
120  *@param sensors pointer to the array
121  *@param sensornumber length of the sensor array
122  *@return number of actually written sensors
123  **/
124  virtual int getSensorsIntern( sensor* sensors, int sensornumber ) = 0;
125 
126  /** returns number of sensors
127  */
128  virtual int getSensorNumberIntern() = 0;
129 
130  /** returns number of motors
131  */
132  virtual int getMotorNumberIntern() = 0;
133 
134  /** returns a vector with the positions of all segments of the robot
135  @param poslist vector of positions (of all robot segments)
136  @return length of the list
137  */
138  virtual int getSegmentsPosition(std::vector<Position> &poslist);
139 
140  /******** CONFIGURABLE ***********/
141  virtual void notifyOnChange(const paramkey& key);
142 
143  /** the main object of the robot, which is used for position and speed tracking */
144  virtual Primitive* getMainPrimitive() const {
145  if(!objects.empty()){
146  // int half = objects.size()/2;
147  // return (objects[half]);
148  return (objects[0]);
149  }else return 0;
150  }
151 protected:
152 
153  /** creates vehicle at desired pose
154  @param pose 4x4 pose matrix
155  */
156  virtual void create(const osg::Matrix& pose);
157  virtual void destroy();
158 };
159 
160 }
161 
162 #endif
virtual ~DefaultCaterPillar()
Definition: defaultCaterPillar.cpp:44
Data structure for accessing the ODE.
Definition: odehandle.h:44
Matrixd Matrix
Definition: osgforwarddecl.h:47
CaterPillarConf conf
Definition: defaultCaterpillar.h:77
charArray paramkey
Definition: avrtypes.h:36
double frictionGround
friction with ground
Definition: defaultCaterpillar.h:58
static CaterPillarConf getDefaultConf()
Definition: defaultCaterpillar.h:83
virtual void notifyOnChange(const paramkey &key)
Is called when a parameter was changes via setParam().
Definition: defaultCaterPillar.cpp:65
double jointLimit
maximal angle for the joints (M_PI/2 = 90 degree)
Definition: defaultCaterpillar.h:60
DefaultCaterPillar(const OdeHandle &odeHandle, const OsgHandle &osgHandle, const CaterPillarConf &conf, const std::string &name, const std::string &revision)
Definition: defaultCaterPillar.cpp:32
double sensor
Definition: types.h:29
int firstJoint
first joint type to use: 0=sliderJoint, 1=universalJoint
Definition: defaultCaterpillar.h:61
Data structure for accessing the OpenSceneGraph.
Definition: osghandle.h:79
virtual int getMotorNumberIntern()=0
returns number of motors
double frictionJoint
friction within joint
Definition: defaultCaterpillar.h:59
bool created
Definition: defaultCaterpillar.h:74
double segmLength
length of one snake element
Definition: defaultCaterpillar.h:53
virtual int getSensorsIntern(sensor *sensors, int sensornumber)=0
Writes the sensor values to an array in the memory.
double segmDia
diameter of a snake element
Definition: defaultCaterpillar.h:54
virtual void create(const osg::Matrix &pose)
creates vehicle at desired pose
Definition: defaultCaterPillar.cpp:87
std::vector< AngularMotor * > frictionmotors
Definition: defaultCaterpillar.h:76
Interface class for primitives represented in the physical and graphical world.
Definition: primitive.h:80
double motorPower
power of the motors / servos
Definition: defaultCaterpillar.h:56
virtual void setMotorsIntern(const double *motors, int motornumber)=0
Reads the actual motor commands from an array, an sets all motors of the snake to this values...
std::list< SensorAttachment > sensors
Definition: oderobot.h:269
virtual int getSegmentsPosition(std::vector< Position > &poslist)
returns a vector with the positions of all segments of the robot
Definition: defaultCaterPillar.cpp:74
OsgHandle osgHandle
Definition: oderobot.h:278
OdeHandle odeHandle
Definition: oderobot.h:277
virtual int getSensorNumberIntern()=0
returns number of sensors
virtual void update()
update all primitives and joints
Definition: defaultCaterPillar.cpp:57
virtual Primitive * getMainPrimitive() const
the main object of the robot, which is used for position and speed tracking
Definition: defaultCaterpillar.h:144
Abstract class for ODE robots.
Definition: oderobot.h:64
int segmNumber
number of snake elements
Definition: defaultCaterpillar.h:52
This is a class, which models a snake like robot.
Definition: defaultCaterpillar.h:70
Primitives objects
list of objects (should be populated by subclasses)
Definition: oderobot.h:265
double segmMass
mass of one snake element
Definition: defaultCaterpillar.h:55
double sensorFactor
scale for sensors
Definition: defaultCaterpillar.h:57
std::list< MotorAttachment > motors
Definition: oderobot.h:270
Definition: defaultCaterpillar.h:50
virtual void placeIntern(const osg::Matrix &pose)
sets the pose of the vehicle
Definition: defaultCaterPillar.cpp:50
virtual void destroy()
destroys vehicle and space
Definition: defaultCaterPillar.cpp:112