enki/interactions/IRSensor.h

Go to the documentation of this file.
00001 /*
00002     Enki - a fast 2D robot simulator
00003     Copyright (C) 1999-2008 Stephane Magnenat <stephane at magnenat dot net>
00004     Copyright (C) 2004-2005 Markus Waibel <markus dot waibel at epfl dot ch>
00005     Copyright (c) 2004-2005 Antoine Beyeler <abeyeler at ab-ware dot com>
00006     Copyright (C) 2005-2006 Laboratory of Intelligent Systems, EPFL, Lausanne
00007     Copyright (C) 2006-2008 Laboratory of Robotics Systems, EPFL, Lausanne
00008     See AUTHORS for details
00009 
00010     This program is free software; the authors of any publication 
00011     arising from research using this software are asked to add the 
00012     following reference:
00013     Enki - a fast 2D robot simulator
00014     http://lis.epfl.ch/enki
00015     Stephane Magnenat <stephane at magnenat dot net>,
00016     Markus Waibel <markus dot waibel at epfl dot ch>
00017     Laboratory of Intelligent Systems, EPFL, Lausanne.
00018 
00019     You can redistribute this program and/or modify
00020     it under the terms of the GNU General Public License as published by
00021     the Free Software Foundation; either version 2 of the License, or
00022     (at your option) any later version.
00023 
00024     This program is distributed in the hope that it will be useful,
00025     but WITHOUT ANY WARRANTY; without even the implied warranty of
00026     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00027     GNU General Public License for more details.
00028 
00029     You should have received a copy of the GNU General Public License
00030     along with this program; if not, write to the Free Software
00031     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00032 */
00033 
00034 #ifndef __ENKI_IRSENSOR_H
00035 #define __ENKI_IRSENSOR_H
00036 
00037 #include <enki/PhysicalEngine.h>
00038 #include <enki/Interaction.h>
00039 
00040 #include <valarray>
00041 #undef min
00042 
00047 namespace Enki
00048 {
00053 
00054 
00055     struct SensorResponseFunctor
00056     {
00058         virtual ~SensorResponseFunctor() {}
00060         virtual double operator()(double, const Color &) = 0;
00061     };
00062     
00064 
00065     class IRSensor : public LocalInteraction
00066     {
00067     protected:
00069         Vector absPos;
00071         double absOrientation;
00073         Vector pos;
00075         double height;
00077         double orientation;
00079         double range;
00081         double aperture;
00083         unsigned rayCount;
00085 
00088         std::valarray<SensorResponseFunctor *> sensorResponseKernel;
00089         
00091         double smartRadius;
00093         Point smartPos;
00095         Vector absSmartPos;
00097         std::valarray<double> rayValues;
00099         std::valarray<Color> rayColors;
00101         std::valarray<double> rayAngles;
00103         std::valarray<double> absRayAngles;
00104     
00105     public:
00107         double finalValue;
00108         
00109     public:
00113         IRSensor(Robot *owner, Vector pos, double height, double orientation, double range, double aperture, unsigned rayCount, SensorResponseFunctor **sensorResponseKernel);
00115         void init(double dt, World* w);
00117         void objectStep(double dt, World *w, PhysicalObject *po);
00119         void wallsStep(double dt, World* w);
00121         void finalize(double dt, World* w);
00122         
00124         Point getAbsolutePosition(void) { return absPos; }
00126         double getAbsoluteOrientation(void) { return absOrientation; }
00128         unsigned getRayCount(void) { return rayCount; }
00130         double getAperture(void) { return aperture; }
00132         double getRange(void) { return range; }
00134         double getSmartRadius(void) { return smartRadius; }
00136         Point getAbsSmartPos(void) { return absSmartPos; }
00138         double getDist(void) { double val = rayValues[rayValues.size() / 2]; return std::min(val, range); }
00139     
00140     private:
00143         double distanceToPolygon(double rayAngle, const Polygone &p) const;
00144     };
00145 }
00146 
00147 #endif

Generated on Sun Mar 1 03:10:09 2009 for Enki by  doxygen 1.5.1