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.5.4.4 2006/03/30 12:34:59 martius 00024 * documentation updated 00025 * 00026 * Revision 1.5.4.3 2006/01/12 15:14:02 martius 00027 * some fwd decl. 00028 * 00029 * Revision 1.5.4.2 2005/12/14 12:43:07 martius 00030 * moved to osg 00031 * 00032 * Revision 1.5.4.1 2005/12/13 18:11:53 martius 00033 * sensors ported, but not yet finished 00034 * 00035 * Revision 1.5 2005/11/09 13:24:20 martius 00036 * added exponent 00037 * 00038 * Revision 1.4 2005/11/09 09:13:47 fhesse 00039 * geom is only enabled in sense function 00040 * there is no external collision detection anymore 00041 * 00042 * Revision 1.3 2005/09/27 13:59:26 martius 00043 * ir sensors are working now 00044 * 00045 * Revision 1.2 2005/09/27 11:03:34 fhesse 00046 * sensorbank added 00047 * 00048 * Revision 1.1 2005/09/22 12:56:47 martius 00049 * ray based sensors 00050 * 00051 * * 00052 ***************************************************************************/ 00053 #ifndef __IRSENSOR_H 00054 #define __IRSENSOR_H 00055 00056 #include "raysensor.h" 00057 00058 namespace lpzrobots { 00059 00060 class OSGCylinder; 00061 class OSGBox; 00062 00063 /** Class for IR sensors. 00064 IR sensors are based on distance measurements using the ODE geom class Ray. 00065 The sensor value is obtained by collisions. 00066 However of no collision is detected the sensor needs to ajust its output as well. 00067 Therefore a reset function is provided. 00068 */ 00069 class IRSensor : public RaySensor { 00070 public: 00071 /** 00072 @param exponent exponent of the sensor characteritic (default: 1 (linear)) 00073 */ 00074 IRSensor(double exponent = 1); 00075 00076 virtual ~IRSensor(); 00077 00078 /** providing essential informations 00079 */ 00080 virtual void init(const OdeHandle& odeHandle, 00081 const OsgHandle& osgHandle, 00082 Primitive* body, 00083 const osg::Matrix pose, double range, 00084 rayDrawMode drawMode = drawSensor); 00085 00086 /** used for reseting the sensor value to a value of maximal distance. 00087 */ 00088 virtual void reset(); 00089 00090 /** performs sense action by checking collision with the given object 00091 @return true for collision handled (sensed) and false for no interaction 00092 */ 00093 virtual bool sense(dGeomID object); 00094 00095 /** returns the sensor value (usually in the range [-1,1] ) 00096 */ 00097 virtual double get(); 00098 00099 /** draws the sensor ray 00100 */ 00101 virtual void update(); 00102 00103 /** returns the geomID of the ray geom (used for optimisation) 00104 */ 00105 virtual dGeomID getGeomID(); 00106 00107 /// returns the exponent of the sensor characteritic (default: 1 (linear)) 00108 double getExponent () const { return exponent;} 00109 00110 /// sets the exponent of the sensor characteritic (default: 1 (linear)) 00111 void setExponent (double exp) { exponent = exp;} 00112 00113 protected: 00114 /** describes the sensor characteritic 00115 linear curve used here 00116 */ 00117 virtual double characteritic(double len); 00118 00119 protected: 00120 dGeomID transform; 00121 dGeomID ray; 00122 double range; // max length 00123 double len; // last measured length 00124 double value; // actual sensor value 00125 double exponent; // exponent of the sensor characteritic 00126 00127 OSGCylinder* sensorBody; 00128 OSGBox* sensorRay; 00129 OsgHandle osgHandle; 00130 00131 bool initialised; 00132 }; 00133 00134 } 00135 00136 #endif