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: sensor.h,v $ 00023 * Revision 1.4 2007/11/07 13:22:47 martius 00024 * *** empty log message *** 00025 * 00026 * Revision 1.3 2007/08/23 15:39:05 martius 00027 * new IR sensor schema which uses substances and callbacks, very nice 00028 * 00029 * Revision 1.2 2006/12/21 11:42:10 martius 00030 * sensors have dimension to sense 00031 * axissensors have finer settings 00032 * 00033 * Revision 1.1 2006/08/08 11:59:01 martius 00034 * new abstract class for sensors 00035 * 00036 * Revision 1.1 2005/11/22 10:24:04 martius 00037 * abstract class for position sensor 00038 * 00039 * * 00040 ***************************************************************************/ 00041 #ifndef __SENSOR_H 00042 #define __SENSOR_H 00043 00044 #include <list> 00045 #include <selforg/types.h> 00046 #include <selforg/stl_adds.h> 00047 #include <selforg/matrix.h> 00048 #include "globaldata.h" 00049 #include "pos.h" 00050 00051 namespace lpzrobots { 00052 00053 // forward declaration 00054 class Primitive; 00055 00056 /** Abstract class for sensors 00057 that have no specific position at the robots skeleton 00058 */ 00059 class Sensor { 00060 public: 00061 /// defines which dimensions should be sensed. The meaning is sensor specific. 00062 enum Dimensions { X = 1, Y = 2, Z = 4 }; 00063 00064 Sensor() {} 00065 virtual ~Sensor() {} 00066 00067 /** initialises sensor with body of robot. This is usually done by the robot itself. 00068 */ 00069 virtual void init(Primitive* own) = 0; 00070 00071 /** performs sense action 00072 */ 00073 virtual bool sense(const GlobalData& globaldata) = 0; 00074 00075 /** returns the number of sensors values produced by this sensor 00076 */ 00077 virtual int getSensorNumber() const = 0; 00078 00079 /** returns a list of sensor values (usually in the range [0,1] ) 00080 */ 00081 virtual std::list<sensor> get() const = 0; 00082 00083 /** writes the sensor values (usually in the range [0,1] ) 00084 into the giben sensor array and returns the number of sensors written 00085 @param sensors call by refernce array which received the values 00086 @param length capacity of sensors array 00087 @return number of sensor values written 00088 */ 00089 virtual int get(sensor* sensors, int length) const = 0; 00090 00091 /// selects the rows specified by dimensions (X->0, Y->1, Z->2) 00092 static std::list<sensor> selectrows(const matrix::Matrix& m, short dimensions) { 00093 std::list<sensor> l; 00094 for(int i=0; i<2; i++){ 00095 if(( 1 <<i ) & dimensions) l += m.row(i).convertToList(); 00096 } 00097 return l; 00098 } 00099 /// selects the rows specified by dimensions (X->0, Y->1, Z->2) 00100 static int selectrows(sensor* sensors, int length, const matrix::Matrix& m, short dimensions) { 00101 int len=0; 00102 for(int i=0; i<3; i++){ 00103 if(( 1 << i) & dimensions) 00104 len+=m.row(i).convertToBuffer(sensors+len, length-len); 00105 } 00106 return len; 00107 } 00108 00109 }; 00110 00111 } 00112 00113 #endif