Robotsystem of the Robot Group Leipzig: selectiveone2onewiring.h Source File

- Main Page
- Namespaces
- Classes
- Files
- Directories
- Related Pages
- Examples

- Search for |

- File List
- File Members

# selectiveone2onewiring.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: selectiveone2onewiring.h,v $
    00023  *   Revision 1.4  2008/04/17 14:54:45  martius
    00024  *   randomGen added, which is a random generator with long period and an
    00025  *    internal state. Each Agent has an instance and passed it to the controller
    00026  *    and the wiring. This is good for
    00027  *   a) repeatability on agent basis,
    00028  *   b) parallel execution as done in ode_robots
    00029  *
    00030  *   Revision 1.3  2006/12/21 11:44:17  martius
    00031  *   commenting style for doxygen //< -> ///<
    00032  *   FOREACH and FOREACHC are macros for collection iteration
    00033  *
    00034  *   Revision 1.2  2006/07/14 12:24:02  martius
    00035  *   selforg becomes HEAD
    00036  *
    00037  *   Revision 1.1.2.1  2005/11/16 11:24:28  martius
    00038  *   moved to selforg
    00039  *
    00040  *   Revision 1.2  2005/10/24 13:32:07  fhesse
    00041  *   comments adjusted and in doxygen style
    00042  *
    00043  *   Revision 1.1  2005/08/22 17:28:13  martius
    00044  *   a 1 to 1 wiring that supports the selection of some sensors only
    00045  *
    00046  *                                                                         *
    00047  ***************************************************************************/
    00048 #ifndef __SELECTIVEONE2ONEWIRING_H
    00049 #define __SELECTIVEONE2ONEWIRING_H
    00050
    00051 #include "one2onewiring.h"
    00052 #include <functional>
    00053
    00054 /** predicate to select sensors.
    00055     First parameter is the index
    00056     and the second parameter is the length (or number of sensors).
    00057 */
    00058 struct select_predicate : public std::binary_function< int,  int, bool> {
    00059   virtual ~select_predicate(){}
    00060   virtual bool operator()( int index,  int len) { return true; }
    00061 };
    00062
    00063 struct select_all : public  select_predicate { };
    00064
    00065 struct select_firsthalf : public  select_predicate {
    00066   virtual ~select_firsthalf(){}
    00067   virtual bool operator()( int index,  int len) { return index < len/2; }
    00068 };
    00069
    00070 /// select sensors in the range \f[ [from, to] \f] (inclusively)
    00071 struct select_from_to : public  select_predicate {
    00072   virtual ~select_from_to(){}
    00073   select_from_to( int from,  int to) : from(from), to(to) {}
    00074   virtual bool operator()( int index,  int len) { return (index >= from) && (index <= to); }
    00075   int from;
    00076   int to;
    00077 };
    00078
    00079 /**
    00080  *   Implements a selective one to one wireing of robot sensors to inputs of the controller
    00081  *   and controller outputs to robot motors.
    00082  */
    00083 class SelectiveOne2OneWiring : public One2OneWiring{
    00084 public:
    00085   /** constructor
    00086       @param noise NoiseGenerator that is used for adding noise to sensor values
    00087       @param sel_sensor binary predicate taking the index and the length (number of sensors)
    00088              and decides which sensor to select
    00089   */
    00090   SelectiveOne2OneWiring(NoiseGenerator* noise, select_predicate* sel_sensor);
    00091   virtual ~SelectiveOne2OneWiring();
    00092
    00093   /** initializes the number of sensors and motors on robot side, calculate
    00094       number of sensors and motors on controller side
    00095   */
    00096   virtual bool init(int robotsensornumber, int robotmotornumber, RandGen* randGen=0);
    00097
    00098   /// Realizes one to one wiring from robot sensors to controller sensors.
    00099   //   @param rsensors pointer to array of sensorvalues from robot
    00100   //   @param rsensornumber number of sensors from robot
    00101   //   @param csensors pointer to array of sensorvalues for controller
    00102   //   @param csensornumber number of sensors to controller
    00103   //   @param noise size of the noise added to the sensors
    00104   virtual bool wireSensors(const sensor* rsensors, int rsensornumber,
    00105                            sensor* csensors, int csensornumber,
    00106                            double noise);
    00107
    00108 protected:
    00109   select_predicate* sel_sensor;
    00110
    00111 };
    00112
    00113 #endif