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
discus.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 
25 #ifndef __DISCUS_H
26 #define __DISCUS_H
27 
28 #include <ode_robots/primitive.h>
29 #include <ode_robots/joint.h>
30 #include <ode_robots/oneaxisservo.h>
31 #include <ode_robots/oderobot.h>
32 #include <ode_robots/sensor.h>
33 #include <ode_robots/raysensorbank.h>
34 
35 namespace lpzrobots {
36 
37  /// configuration object for the Discus robot.
38 typedef struct {
39 public:
40  double diameter;
41  double relativewidth;
42  double stabdiameter; ///< diameter of capsule relative to diameter of body
43  unsigned int numAxes; ///< number of axes with moving masses
44  double spheremass;
45  double pendulardiameter; ///< automatically set
46  double pendularmass;
47  double motorpowerfactor; ///< power factor for servos w.r.t. pendularmass
48  double pendularrange; ///< fraction of the diameter the pendular masses can move to one side
49  double pendularrangeN; ///< fraction of the diameter the normal pendular masses can move to one side
50  bool motorsensor; ///< motor values as sensors
51  bool irAxis1;
52  bool irAxis2;
53  bool irAxis3;
54  bool irRing; ///< IR sensors in a ring in x,z plane (collides with irAxis1 and irAxis3)
55  bool irSide; ///< 4 IR senors to both side in y direction (collides with irAxis2)
56  bool drawIRs;
57  double irsensorscale; ///< range of the ir sensors in units of diameter
58  double irCharacter; ///< characteristics of sensor (\f[ x^c \f] where x is the range-distance)
59  RaySensor* irSensorTempl; ///< template for creation of the other ir sensors (if 0 then IRSensor(irCharacter))
60  double motor_ir_before_sensors; ///< if true motor sensors and ir sensors are given before additional sensors
61  double brake; ///< if nonzero the robot brakes (deaccelerates actively/magically) (velocity dependend torque)
62 
63  /// function that deletes sensors
64  void destroy();
65  /// list of sensors that are mounted at the robot. (e.g.\ AxisOrientationSensor)
66  std::list<Sensor*> sensors;
67  /// adds a sensor to the list of sensors
68  void addSensor(Sensor* s) { sensors.push_back(s); }
69 } DiscusConf;
70 
71 /**
72  A spherical robot with 3 internal masses, which can slide on their orthogonal axes.
73  This robot was inspired by Julius Popp (http://sphericalrobots.com)
74 */
75 class Discus : public OdeRobot
76 {
77 public:
78  /// enum for the objects of the robot
79  /* typedef */ enum objects { Base, Stabilizer, Pendular1, Pendular2, Pendular3, Last } ;
80 
81 protected:
82  static const int maxservono=3;
83 
84  Primitive* object[Last];
88 
90  RaySensorBank irSensorBank; ///< a collection of ir sensors
91  double transparency;
92  bool created;
93 
94 public:
95 
96  /**
97  *constructor
98  **/
99  Discus ( const OdeHandle& odeHandle, const OsgHandle& osgHandle,
100  const DiscusConf& conf, const std::string& name, double transparency=0.5 );
101 
102 protected:
103  /**
104  *constructor for children
105  **/
106  Discus ( const OdeHandle& odeHandle, const OsgHandle& osgHandle,
107  const DiscusConf& conf,
108  const std::string& name, const std::string& revision, double transparency);
109  /// initialises some internal variables
110  void init();
111 public:
112  virtual ~Discus();
113 
114 
115  /// default configuration
117  DiscusConf c;
118  c.diameter = 1;
119  c.relativewidth= 0.2;
120  c.stabdiameter=0.7;
121  c.numAxes = 3;
122  c.spheremass = 1;// 0.1
123  c.pendularmass = 0.75;
124  c.pendularrange = 0.20; // range of the slider from center in multiple of diameter [-range,range]
125  c.pendularrangeN = 0.25;
126  c.motorpowerfactor = 100;
127  c.motorsensor = true;
128  c.irAxis1=false;
129  c.irAxis2=false;
130  c.irAxis3=false;
131  c.irRing=false;
132  c.irSide=false;
133  c.drawIRs=true;
134  c.irsensorscale=1.5;
135  c.irCharacter=1;
136  c.irSensorTempl=0;
137  c.motor_ir_before_sensors=false;
138  c.brake=0;
139  return c;
140  }
141 
142  virtual void update();
143 
144  virtual void placeIntern(const osg::Matrix& pose);
145 
146  virtual void doInternalStuff(GlobalData& globalData);
147 
148  virtual void sense(GlobalData& globalData) override;
149 
150  virtual int getSensorsIntern( sensor* sensors, int sensornumber );
151 
152  virtual void setMotorsIntern( const double* motors, int motornumber );
153 
154  virtual int getMotorNumberIntern();
155 
156  virtual int getSensorNumberIntern();
157 
158  virtual Primitive* getMainPrimitive() const { return object[Base]; }
159 
160 protected:
161 
162  virtual void create(const osg::Matrix& pose);
163  virtual void destroy();
164 
165 
166 };
167 
168 }
169 
170 #endif
Class for a bank (collection) of ray sensors.
Definition: raysensorbank.h:36
unsigned int numAxes
number of axes with moving masses
Definition: discus.h:43
Data structure for accessing the ODE.
Definition: odehandle.h:44
double transparency
Definition: discus.h:91
virtual int getSensorNumberIntern()
overload this function in a subclass to specific the number of custom sensors
Definition: discus.cpp:183
SliderServo * servo[maxservono]
Definition: discus.h:85
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: discus.cpp:148
static DiscusConf getDefaultConf()
default configuration
Definition: discus.h:116
double irCharacter
characteristics of sensor ( where x is the range-distance)
Definition: discus.h:58
Matrixd Matrix
Definition: osgforwarddecl.h:47
Interface class for graphic primitives like spheres, boxes, and meshes, which can be drawn by OSG...
Definition: osgprimitive.h:62
double stabdiameter
diameter of capsule relative to diameter of body
Definition: discus.h:42
virtual ~Discus()
Definition: discus.cpp:90
double spheremass
Definition: discus.h:44
bool irSide
4 IR senors to both side in y direction (collides with irAxis2)
Definition: discus.h:55
double sensor
Definition: types.h:29
Discus(const OdeHandle &odeHandle, const OsgHandle &osgHandle, const DiscusConf &conf, const std::string &name, double transparency=0.5)
constructor
Definition: discus.cpp:53
Definition: discus.h:79
configuration object for the Discus robot.
Definition: discus.h:38
bool irAxis2
Definition: discus.h:52
Data structure for accessing the OpenSceneGraph.
Definition: osghandle.h:79
virtual void update()
update the OSG notes here, if overwritten, call OdeRobot::update()!
Definition: discus.cpp:96
Abstract class for sensors that can be plugged into a robot.
Definition: sensor.h:43
double motorpowerfactor
power factor for servos w.r.t. pendularmass
Definition: discus.h:47
virtual void sense(GlobalData &globalData) override
this function is called each controlstep before control.
Definition: discus.cpp:162
bool irAxis3
Definition: discus.h:53
bool drawIRs
Definition: discus.h:56
SliderJoint * joint[maxservono]
Definition: discus.h:86
Definition: discus.h:79
double pendularrange
fraction of the diameter the pendular masses can move to one side
Definition: discus.h:48
bool irRing
IR sensors in a ring in x,z plane (collides with irAxis1 and irAxis3)
Definition: discus.h:54
std::list< Sensor * > sensors
list of sensors that are mounted at the robot. (e.g. AxisOrientationSensor)
Definition: discus.h:66
OSGPrimitive * axis[maxservono]
Definition: discus.h:87
Interface class for primitives represented in the physical and graphical world.
Definition: primitive.h:80
RaySensor * irSensorTempl
template for creation of the other ir sensors (if 0 then IRSensor(irCharacter))
Definition: discus.h:59
double motor_ir_before_sensors
if true motor sensors and ir sensors are given before additional sensors
Definition: discus.h:60
Definition: discus.h:79
bool irAxis1
Definition: discus.h:51
Data structure holding all essential global information.
Definition: globaldata.h:57
std::list< SensorAttachment > sensors
Definition: oderobot.h:269
double pendularrangeN
fraction of the diameter the normal pendular masses can move to one side
Definition: discus.h:49
virtual void placeIntern(const osg::Matrix &pose)
wrapper to for
Definition: discus.cpp:156
void addSensor(Sensor *s)
adds a sensor to the list of sensors
Definition: discus.h:68
double irsensorscale
range of the ir sensors in units of diameter
Definition: discus.h:57
double diameter
Definition: discus.h:40
bool motorsensor
motor values as sensors
Definition: discus.h:50
double brake
if nonzero the robot brakes (deaccelerates actively/magically) (velocity dependend torque) ...
Definition: discus.h:61
A spherical robot with 3 internal masses, which can slide on their orthogonal axes.
Definition: discus.h:75
OsgHandle osgHandle
Definition: oderobot.h:278
RaySensorBank irSensorBank
a collection of ir sensors
Definition: discus.h:90
Definition: joint.h:304
OdeHandle odeHandle
Definition: oderobot.h:277
Definition: discus.h:79
double pendulardiameter
automatically set
Definition: discus.h:45
virtual int getSensorsIntern(sensor *sensors, int sensornumber)
Writes the sensor values to an array in the memory.
Definition: discus.cpp:116
Definition: discus.h:79
Abstract class for ODE robots.
Definition: oderobot.h:64
void init()
initialises some internal variables
Definition: discus.cpp:80
virtual Primitive * getMainPrimitive() const
return the primitive of the robot that is used for tracking and camera following
Definition: discus.h:158
double pendularmass
Definition: discus.h:46
objects
enum for the objects of the robot
Definition: discus.h:79
bool created
Definition: discus.h:92
double relativewidth
Definition: discus.h:41
Definition: discus.h:79
static const int maxservono
Definition: discus.h:82
general servo motor to achieve position control
Definition: oneaxisservo.h:38
virtual void doInternalStuff(GlobalData &globalData)
this function is called in each simulation timestep (always after control).
Definition: discus.cpp:168
virtual void create(const osg::Matrix &pose)
creates vehicle at desired position and orientation
Definition: discus.cpp:194
std::list< MotorAttachment > motors
Definition: oderobot.h:270
Class for Ray-based sensors.
Definition: raysensor.h:54
virtual void destroy()
destroys vehicle and space
Definition: discus.cpp:315
int c
Definition: hexapod.cpp:56
DiscusConf conf
Definition: discus.h:89
virtual int getMotorNumberIntern()
overload this function in a subclass to specific the number of custom sensors
Definition: discus.cpp:179