raysensorbank.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2005-2011 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 __RAYSENSORBANK_H
00025 #define __RAYSENSORBANK_H
00026 
00027 #include <vector>
00028 #include "raysensor.h"
00029 
00030 namespace lpzrobots {
00031 
00032 /** Class for a bank (collection) of ray sensors. 
00033     Ray sensors can be registered at the bank. Methods for resetting, 
00034     sensing and reading the sensor values of all sensors are provided.
00035  */
00036 class RaySensorBank {
00037 public:  
00038   RaySensorBank();
00039 
00040   virtual ~RaySensorBank();
00041 
00042   /** initialises sensor bank with handles for ode and osg
00043    */
00044   virtual void init( const OdeHandle& odeHandle, const OsgHandle& osgHandle ); 
00045 
00046   /** registers a new sensor at the sensor bank. The body and the pose have to be provided.
00047       @param raysensor RaySensor to add
00048       @param body body to which the sensor should be connected
00049       @param pose relative position/orientation
00050       @param range maximum sense range of the sensor
00051       @return index of the sensor
00052    */
00053   virtual unsigned int registerSensor(RaySensor* raysensor, Primitive* body, 
00054                                       const osg::Matrix& pose, float range,
00055                                       RaySensor::rayDrawMode drawMode);  
00056 
00057   /** resets all sensors (used for reseting the sensor value to a value of maximal distance) 
00058    */
00059   virtual void reset();  
00060 
00061   /// returns the number of sensors
00062   virtual int size() { return bank.size(); }
00063   
00064   /** returns the sensor value of the given sensor (usually in the range [-1,1] )
00065    */
00066   virtual double get(unsigned int index);
00067 
00068   /** writes sensorvalues in given sensorarray
00069       @param sensorarray pointer to the sensorarray in which the values should be stored
00070       @param array_size maximal number of all elements in the sensorarray
00071       @return number of written sensorvalues
00072    */
00073   virtual int get(double* sensorarray, unsigned int array_size);
00074 
00075   /// returns the number of sensors in the bank
00076   virtual int getSensorNumber();
00077 
00078   /** set the range of the specified sensor (index)
00079       @param index index of sensor to modify
00080       @param range new length of the sensor
00081   */
00082   virtual void setRange(unsigned int index, float range);
00083 
00084   /** set the range of all sensors 
00085       @param range new length of the sensors
00086   */
00087   virtual void setRange(float range);
00088   
00089   /** returns the spaceID of the sensor space
00090    */
00091   virtual dSpaceID getSpaceID();
00092 
00093   /** updates the sensor's graphical representation
00094    */
00095   virtual void update();
00096   
00097   // delete all registered sensors.
00098   virtual void clear();
00099 
00100   // returns true if initialized
00101   virtual bool isInitialized() { return initialized;}
00102 
00103 protected:
00104   std::vector<RaySensor*> bank;
00105   bool initialized;
00106 
00107   OdeHandle odeHandle;
00108   OsgHandle osgHandle; 
00109 };
00110 
00111 }
00112 
00113 #endif
Generated on Thu Jun 28 14:45:37 2012 for Robot Simulator of the Robotics Group for Self-Organization of Control by  doxygen 1.6.3