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
sliderwheelie.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  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this program; if not, write to the *
20  * Free Software Foundation, Inc., *
21  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
22  * *
23  ***************************************************************************/
24 #ifndef __SLIDERWHEELIE_H
25 #define __SLIDERWHEELIE_H
26 
27 #include<vector>
28 #include<assert.h>
29 
30 #include "oderobot.h"
31 #include"primitive.h"
32 #include "joint.h"
33 #include "angularmotor.h"
34 
35 #include "oneaxisservo.h"
36 
37 
38 namespace lpzrobots {
39 
40  typedef struct {
41  public:
42  /* typedef */ enum MotorType {Servo, CenteredServo, AngularMotor };
43 
44  int segmNumber; ///< number of snake elements
45  double segmLength; ///< length of one snake element
46  double segmDia; ///< diameter of a snake element
47  double segmMass; ///< mass of one snake element
48  double motorPower; ///< power of the motors / servos
49  double motorDamp; ///< damping of motors
50  double powerRatio; ///< ratio of motorpower for hinge vs. slider
51  double sensorFactor; ///< scale for sensors
52  double frictionGround;///< friction with ground
53  double frictionJoint; ///< friction within joint
54  double jointLimitIn; ///< maximal angle for the joints to the inside (M_PI/2 = 90 degree)
55  double jointLimitOut; ///< maximal angle for the joints to the outside
56  double sliderLength; ///< length of the slider in segmLength (0 for no sliders)
57  MotorType motorType; ///< whether to use servos or angular motors
58  bool showCenter; ///< whether to show the virtual center
59 
60  std::string texture; ///< texture for segments
62 
63 
64  /**
65  * This is a class, which models an annular robot.
66  * It consists of a number of equal elements, each linked
67  * by a joint powered by 1 servo
68  **/
69  class SliderWheelie : public OdeRobot
70  {
71  private:
72  bool created;
73 
74  std::vector <AngularMotor*> angularMotors;
75  SliderWheelieConf conf;
76 
77  std::vector <HingeServo*> hingeServos;
78  std::vector <SliderServo*> sliderServos;
79 
80  Primitive* center; // virtual center object (position updated on setMotors)
81  DummyPrimitive* dummycenter; // virtual center object (here we can also update velocity)
82  public:
84  const SliderWheelieConf& conf, const std::string& name,
85  const std::string& revision = "");
86 
87  virtual ~SliderWheelie();
88 
90  SliderWheelieConf conf;
91  conf.segmNumber = 8; // number of snake elements
92  conf.segmLength = 0.4; // length of one snake element
93  conf.segmDia = 0.2; // diameter of a snake element
94  conf.segmMass = 0.4; // mass of one snake element
95  conf.motorPower = 5; // power of the servos
96  conf.motorDamp = 0.01; // damping of servos
97  conf.powerRatio = 2; // power of the servos
98  conf.sensorFactor = 1; // scale for sensors
99  conf.frictionGround = 0.8; // friction with ground
100  conf.frictionJoint = 0.0; // friction within joint
101  conf.jointLimitIn = M_PI/3;
102  conf.jointLimitOut = -1; // automatically set to 2*M_PI/segm_num
103  conf.sliderLength = 1;
104  conf.motorType = SliderWheelieConf::CenteredServo; // use centered servos
105  conf.showCenter = false;
106  conf.texture = "";
107  return conf;
108  }
109 
110  virtual void placeIntern(const osg::Matrix& pose);
111 
112  virtual void update();
113 
114  void doInternalStuff(GlobalData& global);
115 
116  virtual void setMotorsIntern( const double* motors, int motornumber );
117 
118  virtual int getSensorsIntern( sensor* sensors, int sensornumber );
119 
120  virtual int getSensorNumberIntern() { assert(created);
121  return hingeServos.size()+angularMotors.size()+sliderServos.size(); }
122 
123  virtual int getMotorNumberIntern(){ assert(created);
124  return hingeServos.size()+angularMotors.size()+sliderServos.size(); }
125 
126  virtual Primitive* getMainPrimitive() const {
127  if(dummycenter) return dummycenter;
128  else if(!objects.empty()){
129  return (objects[0]);
130  }else return 0;
131  }
132 
133  virtual std::vector<Primitive*> getAllPrimitives() const { return objects;}
134 
135  /******** CONFIGURABLE ***********/
136  virtual void notifyOnChange(const paramkey& key);
137 
138  private:
139  static void mycallback(void *data, dGeomID o1, dGeomID o2);
140 
141  virtual void create(const osg::Matrix& pose);
142  virtual void destroy();
143  };
144 
145 }
146 
147 #endif
virtual int getSensorsIntern(sensor *sensors, int sensornumber)
overload this function in a subclass to do specific sensor handling, not needed for generic sensors ...
Definition: sliderwheelie.cpp:109
virtual void update()
update the OSG notes here, if overwritten, call OdeRobot::update()!
Definition: sliderwheelie.cpp:59
bool showCenter
whether to show the virtual center
Definition: sliderwheelie.h:58
double segmDia
diameter of a snake element
Definition: sliderwheelie.h:46
double segmLength
length of one snake element
Definition: sliderwheelie.h:45
Data structure for accessing the ODE.
Definition: odehandle.h:44
SliderWheelie(const OdeHandle &odeHandle, const OsgHandle &osgHandle, const SliderWheelieConf &conf, const std::string &name, const std::string &revision="")
Definition: sliderwheelie.cpp:30
double jointLimitOut
maximal angle for the joints to the outside
Definition: sliderwheelie.h:55
Matrixd Matrix
Definition: osgforwarddecl.h:47
MotorType
Definition: sliderwheelie.h:42
charArray paramkey
Definition: avrtypes.h:36
std::string texture
texture for segments
Definition: sliderwheelie.h:60
double sensor
Definition: types.h:29
int segmNumber
number of snake elements
Definition: sliderwheelie.h:44
Data structure for accessing the OpenSceneGraph.
Definition: osghandle.h:79
MotorType motorType
whether to use servos or angular motors
Definition: sliderwheelie.h:57
double segmMass
mass of one snake element
Definition: sliderwheelie.h:47
virtual Primitive * getMainPrimitive() const
return the primitive of the robot that is used for tracking and camera following
Definition: sliderwheelie.h:126
virtual std::vector< Primitive * > getAllPrimitives() const
returns a list of all primitives of the robot (used to store and restore the robot) ...
Definition: sliderwheelie.h:133
virtual int getSensorNumberIntern()
overload this function in a subclass to specific the number of custom sensors
Definition: sliderwheelie.h:120
static SliderWheelieConf getDefaultConf()
Definition: sliderwheelie.h:89
Interface class for primitives represented in the physical and graphical world.
Definition: primitive.h:80
virtual void setMotorsIntern(const double *motors, int motornumber)
overload this function in a subclass to do specific sensor handling, not needed for generic motors ...
Definition: sliderwheelie.cpp:74
Abstract angular motor class.
Definition: angularmotor.h:36
Data structure holding all essential global information.
Definition: globaldata.h:57
virtual void placeIntern(const osg::Matrix &pose)
wrapper to for
Definition: sliderwheelie.cpp:51
double powerRatio
ratio of motorpower for hinge vs. slider
Definition: sliderwheelie.h:50
std::list< SensorAttachment > sensors
Definition: oderobot.h:269
virtual int getMotorNumberIntern()
overload this function in a subclass to specific the number of custom sensors
Definition: sliderwheelie.h:123
double sensorFactor
scale for sensors
Definition: sliderwheelie.h:51
double frictionGround
friction with ground
Definition: sliderwheelie.h:52
OsgHandle osgHandle
Definition: oderobot.h:278
OdeHandle odeHandle
Definition: oderobot.h:277
double jointLimitIn
maximal angle for the joints to the inside (M_PI/2 = 90 degree)
Definition: sliderwheelie.h:54
virtual ~SliderWheelie()
Definition: sliderwheelie.cpp:46
Abstract class for ODE robots.
Definition: oderobot.h:64
Primitives objects
list of objects (should be populated by subclasses)
Definition: oderobot.h:265
Dummy Primitive which returns 0 for geom and body.
Definition: primitive.h:452
double motorPower
power of the motors / servos
Definition: sliderwheelie.h:48
void doInternalStuff(GlobalData &global)
this function is called in each simulation timestep (always after control).
Definition: sliderwheelie.cpp:71
double sliderLength
length of the slider in segmLength (0 for no sliders)
Definition: sliderwheelie.h:56
virtual void notifyOnChange(const paramkey &key)
Is called when a parameter was changes via setParam().
Definition: sliderwheelie.cpp:284
double frictionJoint
friction within joint
Definition: sliderwheelie.h:53
double motorDamp
damping of motors
Definition: sliderwheelie.h:49
std::list< MotorAttachment > motors
Definition: oderobot.h:270
Definition: sliderwheelie.h:40
This is a class, which models an annular robot.
Definition: sliderwheelie.h:69
Definition: sliderwheelie.h:42
Definition: sliderwheelie.h:42