Enki  1.9
IRSensor.h
Go to the documentation of this file.
1 /*
2  Enki - a fast 2D robot simulator
3  Copyright (C) 1999-2016 Stephane Magnenat <stephane at magnenat dot net>
4  Copyright (C) 2004-2005 Markus Waibel <markus dot waibel at epfl dot ch>
5  Copyright (c) 2004-2005 Antoine Beyeler <abeyeler at ab-ware dot com>
6  Copyright (C) 2005-2006 Laboratory of Intelligent Systems, EPFL, Lausanne
7  Copyright (C) 2006-2008 Laboratory of Robotics Systems, EPFL, Lausanne
8  See AUTHORS for details
9 
10  This program is free software; the authors of any publication
11  arising from research using this software are asked to add the
12  following reference:
13  Enki - a fast 2D robot simulator
14  http://home.gna.org/enki
15  Stephane Magnenat <stephane at magnenat dot net>,
16  Markus Waibel <markus dot waibel at epfl dot ch>
17  Laboratory of Intelligent Systems, EPFL, Lausanne.
18 
19  You can redistribute this program 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 Free Software
31  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 */
33 
34 #ifndef __ENKI_IRSENSOR_H
35 #define __ENKI_IRSENSOR_H
36 
37 #include <enki/PhysicalEngine.h>
38 #include <enki/Interaction.h>
39 
40 #include <valarray>
41 #undef min
42 
47 namespace Enki
48 {
50 
86  class IRSensor : public LocalInteraction
87  {
88  protected:
94  const Vector pos;
96  const double height;
98  const double orientation;
100  const double range;
102  const double aperture;
104  const double alpha;
106  const unsigned rayCount;
108  const double m;
110  const double x0;
112  const double c;
114  const double noiseSd;
115 
117  double smartRadius;
123  std::vector<double> rayDists;
125  std::vector<double> rayValues;
127  std::vector<double> rayAngles;
129  std::vector<double> absRayAngles;
130 
132  double finalValue;
134  double finalDist;
135 
136  public:
138 
149  IRSensor(Robot *owner, Vector pos, double height, double orientation, double range, double m, double x0, double c, double noiseSd = 0.);
151  void init(double dt, World* w);
153  void objectStep(double dt, World *w, PhysicalObject *po);
155  void wallsStep(double dt, World* w);
157  void finalize(double dt, World* w);
158 
160  double getValue(void) const { return finalValue; }
162  double getDist(void) const { return finalDist; }
164  double getRayValue(unsigned i) const { return rayValues.at(i); }
166  double getRayDist(unsigned i) const { return rayDists.at(i); }
167 
169  Point getAbsolutePosition(void) const { return absPos; }
171  double getAbsoluteOrientation(void) const { return absOrientation; }
173  unsigned getRayCount(void) const { return rayCount; }
175  double getAperture(void) const { return aperture; }
177  double getRange(void) const { return range; }
179  double getSmartRadius(void) const { return smartRadius; }
181  Point getAbsSmartPos(void) const { return absSmartPos; }
182 
183  protected:
185  void updateRay(size_t i, double dist);
187  double responseFunction(double x) const;
189  double inverseResponseFunction(double v) const;
192  double distanceToPolygon(double rayAngle, const Polygone &p) const;
193  };
194 }
195 
196 #endif
A vector in a 2D space.
Definition: Geometry.h:68
Point getAbsolutePosition(void) const
Return the absolute position of the IR sensor, updated at each time step on init() ...
Definition: IRSensor.h:169
A situated object in the world with mass, geometry properties, physical properties, ...
Definition: PhysicalEngine.h:131
double getSmartRadius(void) const
Return the radius for the smallest circle enclosing all rays.
Definition: IRSensor.h:179
double getAperture(void) const
Return the aperture of the sensor.
Definition: IRSensor.h:175
IRSensor(Robot *owner, Vector pos, double height, double orientation, double range, double m, double x0, double c, double noiseSd=0.)
Constructor.
Definition: IRSensor.cpp:49
double getRayDist(unsigned i) const
Return the distance of a ray.
Definition: IRSensor.h:166
double finalDist
Final computed distance.
Definition: IRSensor.h:134
const double c
Third parameter of response function.
Definition: IRSensor.h:112
const unsigned rayCount
Number of rays used, each ray has an aperture of aperture/rayCount to the next one. Rays are assembled from right to left (i.e. counterclockwise)
Definition: IRSensor.h:106
double absOrientation
Absolute orientation in the world, updated on init()
Definition: IRSensor.h:92
Point smartPos
Current position of the center of the smartRadius, i.e. center of the smallest circle enclosing all r...
Definition: IRSensor.h:119
Enki is the namespace of the Enki simulator. All Enki functions and classes excepted the math one are...
Definition: BluetoothBase.cpp:44
Vector absPos
Absolute position in the world, updated on init()
Definition: IRSensor.h:90
double getDist(void) const
Return the distance through the inverse response of the final sensor value.
Definition: IRSensor.h:162
std::vector< double > absRayAngles
The angle for each ray relative to the sensor orientation in absolute (world) coordinates.
Definition: IRSensor.h:129
Robot * owner
The physical object that owns the interaction.
Definition: Interaction.h:62
const double range
Actual detection range.
Definition: IRSensor.h:100
The interfaces for the interactions.
void init(double dt, World *w)
Reset distance values.
Definition: IRSensor.cpp:87
double getValue(void) const
Return the final sensor value.
Definition: IRSensor.h:160
const double alpha
1/cos(aperture)
Definition: IRSensor.h:104
const Vector pos
Relative position on the robot.
Definition: IRSensor.h:94
unsigned getRayCount(void) const
Return the number of rays.
Definition: IRSensor.h:173
double responseFunction(double x) const
Return the response for a given distance.
Definition: IRSensor.cpp:280
double inverseResponseFunction(double v) const
Return the inverse response for a given distance.
Definition: IRSensor.cpp:292
void objectStep(double dt, World *w, PhysicalObject *po)
Check for all potential intersections using smartRadius of sensor and calculate and find closest dist...
Definition: IRSensor.cpp:107
const double m
Maximum possible response value, might be inside the robot if x0<0, first parameter of response funct...
Definition: IRSensor.h:108
const double x0
Position of the maximum of response (might be negative, inside the robot), second parametere of respo...
Definition: IRSensor.h:110
double getRange(void) const
Return the range of the sensor.
Definition: IRSensor.h:177
void wallsStep(double dt, World *w)
Separated from objectStep because it is much simpler.
Definition: IRSensor.cpp:180
The world is the container of all objects and robots.
Definition: PhysicalEngine.h:411
A generic infrared sensor.
Definition: IRSensor.h:86
const double height
Height above ground, the sensor will not see any object of smaller height.
Definition: IRSensor.h:96
std::vector< double > rayDists
Temporary ray values containing the lowest distance found up to now.
Definition: IRSensor.h:123
double finalValue
Final sensor value.
Definition: IRSensor.h:132
double getAbsoluteOrientation(void) const
Return the absolute orientation of the IR sensor, updated at each time step on init() ...
Definition: IRSensor.h:171
void finalize(double dt, World *w)
Applies the SensorResponseFunction to each ray and combines all rays using weights defined in the ray...
Definition: IRSensor.cpp:261
void updateRay(size_t i, double dist)
If dist is smaller than current ray distance, update distance and response value. ...
Definition: IRSensor.cpp:268
Polygone, which is a vector of points. Anti-clockwise, standard trigonometric orientation.
Definition: Geometry.h:238
std::vector< double > rayValues
Temporary ray values containing the response value of the closest object found up to now...
Definition: IRSensor.h:125
const double orientation
Relative orientation on the robot.
Definition: IRSensor.h:98
Interacts with another object or wall only up to a certain distance.
Definition: Interaction.h:53
const double aperture
Aperture angle.
Definition: IRSensor.h:102
Vector absSmartPos
Current position of the center of the smartRadius in absolute (world) coordinates, updated on init()
Definition: IRSensor.h:121
The core of Enki.
double smartRadius
Radius for the smallest circle enclosing all rays.
Definition: IRSensor.h:117
double distanceToPolygon(double rayAngle, const Polygone &p) const
Returns distance to PhysicalObject po for angle rayAngle.
Definition: IRSensor.cpp:323
double getRayValue(unsigned i) const
Return the value of a ray.
Definition: IRSensor.h:164
std::vector< double > rayAngles
The angle for each ray relative to the sensor orientation in relative (robot) coordinates.
Definition: IRSensor.h:127
A robot is a PhysicalObject that has additional interactions and a controller.
Definition: PhysicalEngine.h:379
Point getAbsSmartPos(void) const
Return current position of the center of the smartRadius, i.e. center of the smallest circle enclosin...
Definition: IRSensor.h:181
const double noiseSd
Standard deviation of Gaussian noise in the response space.
Definition: IRSensor.h:114