Robot Simulator of the Robotics Group for Self-Organization of Control: irsensor.h Source File

# irsensor.h

Go to the documentation of this file.

    00001 /***************************************************************************
    00002  *   Copyright (C) 2005-2011 LpzRobots development team                    *
    00003  *    Georg Martius  <georg dot martius at web dot de>                     *
    00004  *    Frank Guettler <guettler at informatik dot uni-leipzig dot de        *
    00005  *    Frank Hesse    <frank at nld dot ds dot mpg dot de>                  *
    00006  *    Ralf Der       <ralfder at mis dot mpg dot de>                       *
    00007  *                                                                         *
    00008  *   This program is free software; you can redistribute it and/or modify  *
    00009  *   it under the terms of the GNU General Public License as published by  *
    00010  *   the Free Software Foundation; either version 2 of the License, or     *
    00011  *   (at your option) any later version.                                   *
    00012  *                                                                         *
    00013  *   This program is distributed in the hope that it will be useful,       *
    00014  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
    00015  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
    00016  *   GNU General Public License for more details.                          *
    00017  *                                                                         *
    00018  *   You should have received a copy of the GNU General Public License     *
    00019  *   along with this program; if not, write to the                         *
    00020  *   Free Software Foundation, Inc.,                                       *
    00021  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
    00022  *                                                                         *
    00023  ***************************************************************************/
    00024 #ifndef __IRSENSOR_H
    00025 #define __IRSENSOR_H
    00026
    00027 #include "raysensor.h"
    00028
    00029 namespace lpzrobots {
    00030
    00031   class OSGCylinder;
    00032   class OSGBox;
    00033   class Transform;
    00034   class Ray;
    00035
    00036
    00037   /** Class for IR sensors.
    00038       IR sensors are based on distance measurements using the ODE geom class Ray.
    00039       The sensor value is obtained by collisions, which are handled by the simulation
    00040       environement. The information of a collision comes to the sensor via the
    00041       collision callback of the substance used for the ray (actually for the transform).
    00042       However of no collision is detected the sensor needs to ajust its output as well.
    00043       Therefore a reset function is provided.
    00044   */
    00045   class IRSensor : public RaySensor {
    00046   public:
    00047     /**
    00048        @param exponent exponent of the sensor characteritic (default: 1 (linear))
    00049     */
    00050     IRSensor(float exponent = 1, double size = 0.05);
    00051
    00052     virtual ~IRSensor();
    00053
    00054     virtual void init(const OdeHandle& odeHandle,
    00055                       const OsgHandle& osgHandle,
    00056                       Primitive* body,
    00057                       const osg::Matrix pose, float range,
    00058                       rayDrawMode drawMode = drawSensor);
    00059
    00060     virtual void reset();
    00061
    00062     /** returns the sensor value in the range [0,1];
    00063         0 means nothing no object in the sensor distance range
    00064         1 means contact with another object
    00065         @see characteritic()
    00066      */
    00067     virtual double get();
    00068     virtual void update();
    00069
    00070     virtual void setRange(float range);
    00071
    00072     virtual void setLength(float len);
    00073
    00074     virtual RaySensor* clone() const;
    00075
    00076     /// returns the exponent of the sensor characteritic (default: 1 (linear))
    00077     double getExponent () const { return exponent;}
    00078
    00079     /// sets the exponent of the sensor characteritic (default: 1 (linear))
    00080     void   setExponent (float exp) { exponent = exp;}
    00081
    00082   protected:
    00083     /** describes the sensor characteritic
    00084         An exponential curve is used.
    00085         @see setExponent()
    00086     */
    00087     virtual float characteritic(float len);
    00088
    00089   protected:
    00090     float range; // max length
    00091     float len;   // last measured length
    00092     float value; // actual sensor value
    00093     float lastvalue; // last value
    00094     float exponent; // exponent of the sensor characteritic
    00095
    00096     double size; // size of graphical sensor
    00097
    00098     OSGCylinder* sensorBody;
    00099     //    OSGBox* sensorRay;
    00100     OsgHandle osgHandle;
    00101
    00102     Transform* transform;
    00103     Ray* ray;
    00104     bool initialised;
    00105   };
    00106
    00107 }
    00108
    00109 #endif