sensor.h

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

Generated on Tue Jan 16 02:14:38 2007 for Robotsystem of the Robot Group Leipzig by doxygen 1.3.8