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