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.6  2010/03/21 21:48:59  martius
00024  *   camera sensor bugfixing (reference to osghandle)
00025  *   twowheeled robot added (nimm2 with camera)
00026  *   sense function added to robots (before control): sensors (type Sensor) are checked here
00027  *   position and optical flow camera sensors added
00028  *
00029  *   Revision 1.5  2010/03/19 17:46:21  martius
00030  *   camerasensors added
00031  *   camera works great now. Near and far plane fixed by hand and optimal positioning
00032  *   many image processings added
00033  *
00034  *   Revision 1.4  2007/11/07 13:22:47  martius
00035  *   *** empty log message ***
00036  *
00037  *   Revision 1.3  2007/08/23 15:39:05  martius
00038  *   new IR sensor schema which uses substances and callbacks, very nice
00039  *
00040  *   Revision 1.2  2006/12/21 11:42:10  martius
00041  *   sensors have dimension to sense
00042  *   axissensors have finer settings
00043  *
00044  *   Revision 1.1  2006/08/08 11:59:01  martius
00045  *   new abstract class for sensors
00046  *
00047  *   Revision 1.1  2005/11/22 10:24:04  martius
00048  *   abstract class for position sensor
00049  *
00050  *                                                                         *
00051  ***************************************************************************/
00052 #ifndef __SENSOR_H
00053 #define __SENSOR_H
00054 
00055 #include <list>
00056 #include <selforg/types.h>
00057 #include <selforg/stl_adds.h>
00058 #include <selforg/matrix.h>
00059 #include "globaldata.h"
00060 #include "pos.h"
00061 
00062 namespace lpzrobots {
00063 
00064   // forward declaration 
00065   class Primitive;
00066 
00067   /** Abstract class for sensors that can be plugged into a robot
00068   */
00069   class Sensor {
00070   public:  
00071     /// defines which dimensions should be sensed. The meaning is sensor specific.
00072     enum Dimensions { X = 1, Y = 2, Z = 4, XY = X | Y, XZ = X | Z, YZ = Y | Z, XYZ = X | Y | Z };
00073 
00074     Sensor() {}
00075     virtual ~Sensor() {}
00076   
00077     /** initialises sensor with body of robot. This is usually done by the robot itself.
00078     */
00079     virtual void init(Primitive* own) = 0;  
00080   
00081     /** performs sense action
00082      */
00083     virtual bool sense(const GlobalData& globaldata) = 0;
00084 
00085     /** returns the number of sensors values produced by this sensor
00086      */
00087     virtual int getSensorNumber() const  = 0;
00088 
00089     /** returns a list of sensor values (usually in the range [0,1] )
00090      */
00091     virtual std::list<sensor> get() const  = 0;
00092 
00093     /** to update any visual appearance       
00094      */
00095     virtual void update() {};
00096 
00097     /** writes the sensor values (usually in the range [0,1] ) 
00098         into the giben sensor array and returns the number of sensors written
00099         @param sensors call by refernce array which received the values
00100         @param length capacity of sensors array
00101         @return number of sensor values written
00102      */
00103     virtual int get(sensor* sensors, int length) const  = 0;
00104 
00105     /// selects the rows specified by dimensions (X->0, Y->1, Z->2)
00106     static std::list<sensor> selectrows(const matrix::Matrix& m, short dimensions) {
00107       std::list<sensor> l;
00108       for(int i=0; i<2; i++){
00109         if(( 1 <<i ) & dimensions) l += m.row(i).convertToList();
00110       } 
00111       return l;
00112     }
00113     /// selects the rows specified by dimensions (X->0, Y->1, Z->2)
00114     static int selectrows(sensor* sensors, int length, const matrix::Matrix& m, short dimensions) {
00115       int len=0;
00116       for(int i=0; i<3; i++){
00117         if(( 1 << i) & dimensions) 
00118           len+=m.row(i).convertToBuffer(sensors+len, length-len);       
00119       } 
00120       return len;
00121     }
00122 
00123   };
00124 
00125 }
00126 
00127 #endif
Generated on Fri Nov 4 10:59:39 2011 for Robot Simulator of the Robotics Group for Self-Organization of Control by  doxygen 1.6.3