00001 /*************************************************************************** 00002 * Copyright (C) 2005-2012 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 __CONTACTSENSOR_H 00025 #define __CONTACTSENSOR_H 00026 00027 #include <ode_robots/color.h> 00028 00029 namespace lpzrobots { 00030 00031 class Sphere; 00032 class Transform; 00033 00034 /** Class for a contact sensor. 00035 The sensor is on if a collision occurs and stores the penetration depth 00036 (as a crude measure for the colission force). It can be either attached to 00037 an existing primitive (e.g. a leg) or create its own sensor object. The latter 00038 is recommended if you want very localized force sensors. 00039 The information of a collision comes to the sensor via the 00040 collision callback of the substance used for the primitive. 00041 However of no collision is detected the sensor needs to ajust its output as well. 00042 Therefore a reset function is provided. 00043 */ 00044 class ContactSensor { 00045 public: 00046 00047 /** 00048 @param binary if true then the sensor is 0 or 1 (for contact), no force value returned 00049 @param forcescale scale of the measured collision force (default: 1) 00050 @param size size of little box representing the sensor (if it has an own body) (default: 0.05) 00051 */ 00052 ContactSensor(bool binary=true, double forcescale = 1, double radius = 0.05); 00053 00054 virtual ~ContactSensor(); 00055 00056 virtual void init(const OdeHandle& odeHandle, 00057 const OsgHandle& osgHandle, 00058 Primitive* reference, 00059 bool createSphere = false, 00060 const osg::Matrix pose = osg::Matrix(), 00061 bool colorObject = true); 00062 00063 virtual void reset(); 00064 00065 /** returns the sensor value in the range >=0; 00066 0 means nothing no contact 00067 >0 means contact with another object: size is the force in arbitrary unit 00068 @see characteritic() 00069 */ 00070 virtual double get(); 00071 virtual void update(); 00072 00073 // set measued depth (used internally) (stores the maximum until next reset) 00074 virtual void setDepth(float depth); 00075 00076 Transform* getTransformObject(); 00077 00078 protected: 00079 bool binary; ///< if contact sensor is a switch 00080 double forcescale; 00081 double value; ///< actual sensor value 00082 double lastvalue; ///< last value 00083 double size; ///< size of graphical sensor 00084 00085 Primitive* reference; ///< primitive to which the sensor is bound 00086 Sphere* sensorBody; 00087 Transform* transform; 00088 00089 bool colorObject; 00090 Color origColor; 00091 bool initialised; 00092 }; 00093 00094 } 00095 00096 #endif