00001 /*************************************************************************** 00002 * Copyright (C) 2005 by Robot Group Leipzig * 00003 * martius@informatik.uni-leipzig.de * 00004 * fhesse@informatik.uni-leipzig.de * 00005 * der@informatik.uni-leipzig.de * 00006 * * 00007 * This program is free software; you can redistribute it and/or modify * 00008 * it under the terms of the GNU General Public License as published by * 00009 * the Free Software Foundation; either version 2 of the License, or * 00010 * (at your option) any later version. * 00011 * * 00012 * This program is distributed in the hope that it will be useful, * 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00015 * GNU General Public License for more details. * 00016 * * 00017 * You should have received a copy of the GNU General Public License * 00018 * along with this program; if not, write to the * 00019 * Free Software Foundation, Inc., * 00020 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 00021 * * 00022 * $Log: irsensor.h,v $ 00023 * Revision 1.13 2007/09/06 18:48:29 martius 00024 * clone function (a bit like a factory) 00025 * 00026 * Revision 1.12 2007/08/24 11:57:48 martius 00027 * some forward declaration 00028 * 00029 * Revision 1.11 2007/08/23 15:39:05 martius 00030 * new IR sensor schema which uses substances and callbacks, very nice 00031 * 00032 * Revision 1.10 2006/09/20 12:56:28 martius 00033 * setRange 00034 * 00035 * Revision 1.9 2006/09/11 12:01:31 martius 00036 * *** empty log message *** 00037 * 00038 * Revision 1.8 2006/08/28 12:18:31 martius 00039 * documentation 00040 * 00041 * Revision 1.7 2006/08/08 17:03:27 martius 00042 * new sensors model 00043 * 00044 * Revision 1.6 2006/07/14 12:23:43 martius 00045 * selforg becomes HEAD 00046 * 00047 * Revision 1.5.4.4 2006/03/30 12:34:59 martius 00048 * documentation updated 00049 * 00050 * Revision 1.5.4.3 2006/01/12 15:14:02 martius 00051 * some fwd decl. 00052 * 00053 * Revision 1.5.4.2 2005/12/14 12:43:07 martius 00054 * moved to osg 00055 * 00056 * Revision 1.5.4.1 2005/12/13 18:11:53 martius 00057 * sensors ported, but not yet finished 00058 * 00059 * Revision 1.5 2005/11/09 13:24:20 martius 00060 * added exponent 00061 * 00062 * Revision 1.4 2005/11/09 09:13:47 fhesse 00063 * geom is only enabled in sense function 00064 * there is no external collision detection anymore 00065 * 00066 * Revision 1.3 2005/09/27 13:59:26 martius 00067 * ir sensors are working now 00068 * 00069 * Revision 1.2 2005/09/27 11:03:34 fhesse 00070 * sensorbank added 00071 * 00072 * Revision 1.1 2005/09/22 12:56:47 martius 00073 * ray based sensors 00074 * 00075 * * 00076 ***************************************************************************/ 00077 #ifndef __IRSENSOR_H 00078 #define __IRSENSOR_H 00079 00080 #include "raysensor.h" 00081 00082 namespace lpzrobots { 00083 00084 class OSGCylinder; 00085 class OSGBox; 00086 class Transform; 00087 class Ray; 00088 00089 00090 /** Class for IR sensors. 00091 IR sensors are based on distance measurements using the ODE geom class Ray. 00092 The sensor value is obtained by collisions, which are handled by the simulation 00093 environement. The information of a collision comes to the sensor via the 00094 collision callback of the substance used for the ray (actually for the transform). 00095 However of no collision is detected the sensor needs to ajust its output as well. 00096 Therefore a reset function is provided. 00097 */ 00098 class IRSensor : public RaySensor { 00099 public: 00100 /** 00101 @param exponent exponent of the sensor characteritic (default: 1 (linear)) 00102 */ 00103 IRSensor(float exponent = 1); 00104 00105 virtual ~IRSensor(); 00106 00107 virtual void init(const OdeHandle& odeHandle, 00108 const OsgHandle& osgHandle, 00109 Primitive* body, 00110 const osg::Matrix pose, float range, 00111 rayDrawMode drawMode = drawSensor); 00112 00113 virtual void reset(); 00114 00115 /** returns the sensor value in the range [0,1]; 00116 0 means nothing no object in the sensor distance range 00117 1 means contact with another object 00118 @see characteritic() 00119 */ 00120 virtual double get(); 00121 virtual void update(); 00122 00123 virtual void setRange(float range); 00124 00125 virtual void setLength(float len); 00126 00127 virtual RaySensor* clone() const; 00128 00129 /// returns the exponent of the sensor characteritic (default: 1 (linear)) 00130 double getExponent () const { return exponent;} 00131 00132 /// sets the exponent of the sensor characteritic (default: 1 (linear)) 00133 void setExponent (float exp) { exponent = exp;} 00134 00135 protected: 00136 /** describes the sensor characteritic 00137 An exponential curve is used. 00138 @see setExponent() 00139 */ 00140 virtual float characteritic(float len); 00141 00142 protected: 00143 float range; // max length 00144 float len; // last measured length 00145 float value; // actual sensor value 00146 float exponent; // exponent of the sensor characteritic 00147 00148 OSGCylinder* sensorBody; 00149 // OSGBox* sensorRay; 00150 OsgHandle osgHandle; 00151 00152 Transform* transform; 00153 Ray* ray; 00154 bool initialised; 00155 }; 00156 00157 } 00158 00159 #endif