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
raysensor.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 __RAYSENSOR_H
25 #define __RAYSENSOR_H
26 
27 #include <ode-dbl/common.h>
28 #include <ode-dbl/ode.h>
29 #include <cmath>
30 #include <assert.h>
31 #include <selforg/position.h>
32 #include <osg/Matrix>
33 #include <osg/Vec3>
34 
35 #include "primitive.h"
36 #include "osgprimitive.h"
37 #include "osgforwarddecl.h"
38 #include "odehandle.h"
39 #include "physicalsensor.h"
40 
41 
42 namespace lpzrobots {
43 
44  class OSGCylinder;
45  class OSGBox;
46  class Transform;
47  class Ray;
48 
49 /** Class for Ray-based sensors.
50  This are sensors which are based on distance measurements using the ODE geom class Ray.
51  The sensor value is obtained by collisions.
52  See also RaySensorBank, which is an object for managing multiple ray sensors.
53  */
54  class RaySensor : public PhysicalSensor {
55  public:
57 
58  RaySensor();
59 
60  /**
61  * @param size size of sensor in simulation
62  * @param range maximum range of the Ray sensor
63  * @param drawMode draw mode of the sensor
64  */
65  RaySensor(double size , double range, rayDrawMode drawMode);
66 
67  ~RaySensor();
68 
69  ///Create a copy of this without initialization
70  virtual RaySensor* clone() const;
71 
72  void setPose(const osg::Matrix& pose) override;
73 
74  void init(Primitive* own, Joint* joint = 0) override;
75 
76  bool sense(const GlobalData& globaldata) override;
77 
78  int get(sensor* sensors, int length) const override;
79 
80  std::list<sensor> getList() const override;
81 
82  virtual int getSensorNumber() const override;
83 
84  virtual void update() override;
85 
86  ///Set maximum range of ray
87  virtual void setRange(double range);
88 
89  ///Set draw mode of ray
90  virtual void setDrawMode(rayDrawMode drawMode);
91 
92  ///Set length of ray (needed for callback)
93  void setLength(double len, long int time);
94 
95  protected:
96  //Initialize variables of ray sensor. Should be called
97  //by every constructor
98  void defaultInit();
99 
100  double size; // size of graphical sensor
101  double range; // max length
103 
104  double len; // measured length
105  double lastlen; //last measured length
106  double detection; // detected length (internally used)
107  long lasttimeasked; // used to make sense return the same number if called two times in one timestep
108 
113 
114  };
115 
116 }
117 
118 #endif
double len
Definition: raysensor.h:104
virtual void setRange(double range)
Set maximum range of ray.
Definition: raysensor.cpp:114
Matrixd Matrix
Definition: osgforwarddecl.h:47
Definition: raysensor.h:56
Definition: joint.h:41
Definition: raysensor.h:56
rayDrawMode
Definition: raysensor.h:56
double sensor
Definition: types.h:29
void init(Primitive *own, Joint *joint=0) override
initialises sensor with a body of robot and optionally with a joint.
Definition: raysensor.cpp:87
double lastlen
Definition: raysensor.h:105
virtual void update() override
to update any visual appearance
Definition: raysensor.cpp:145
Ray * ray
Definition: raysensor.h:111
double detection
Definition: raysensor.h:106
void defaultInit()
Definition: raysensor.cpp:39
Interface class for primitives represented in the physical and graphical world.
Definition: primitive.h:80
void setLength(double len, long int time)
Set length of ray (needed for callback)
Definition: raysensor.cpp:110
Data structure holding all essential global information.
Definition: globaldata.h:57
bool sense(const GlobalData &globaldata) override
performs sense action
Definition: raysensor.cpp:125
Ray primitive The actual visual representation can have different length than the ray object...
Definition: primitive.h:347
rayDrawMode drawMode
Definition: raysensor.h:102
osg::Matrix pose
Definition: physicalsensor.h:64
void setPose(const osg::Matrix &pose) override
changes the relative pose of the sensor
Definition: raysensor.cpp:79
double size
Definition: raysensor.h:100
long lasttimeasked
Definition: raysensor.h:107
virtual int getSensorNumber() const override
returns the number of sensors values produced by this sensor
Definition: raysensor.cpp:75
Abstract class for sensors that have a physical representation.
Definition: physicalsensor.h:35
double range
Definition: raysensor.h:101
Transform * transform
Definition: raysensor.h:110
Graphical cylinder.
Definition: osgprimitive.h:215
Primitive for transforming a geom (primitive without body) in respect to a body (primitive with body)...
Definition: primitive.h:410
Definition: raysensor.h:56
virtual RaySensor * clone() const
Create a copy of this without initialization.
Definition: raysensor.cpp:69
std::list< sensor > getList() const override
returns a list of sensor values (usually in the range [-1,1] ) This function should be overloaded...
Definition: raysensor.cpp:140
bool initialised
Definition: raysensor.h:112
Class for Ray-based sensors.
Definition: raysensor.h:54
~RaySensor()
Definition: raysensor.cpp:62
Definition: raysensor.h:56
RaySensor()
Definition: raysensor.cpp:52
OSGCylinder * sensorBody
Definition: raysensor.h:109
virtual void setDrawMode(rayDrawMode drawMode)
Set draw mode of ray.
Definition: raysensor.cpp:119