splitcontrol.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 __SPLITCONTROL_H
00025 #define __SPLITCONTROL_H
00026 
00027 #include <selforg/abstractcontroller.h>
00028 #include <selforg/onecontrollerperchannel.h>
00029 
00030 #include <vector>
00031 #include <functional>
00032 
00033 
00034 /**
00035  * class for using multiple controller with one robot. The connection is flexible.
00036  * The controller are generated on the fly with a generator object.
00037  *
00038  */
00039 class SplitControl : public AbstractController {
00040 public:
00041   
00042   struct Assoziation {
00043     Assoziation();
00044     void addSensorIdx(int s) { sensors.push_back(s);}
00045     void addMotorIdx(int m)  { motors.push_back(m);}
00046     
00047     std::list<int> sensors;
00048     std::list<int> motors;
00049   };
00050   typedef std::vector<Assoziation> Assoziations;
00051 
00052   /** @param controllerGenerator generator object for controller
00053       @param assoziations list decribing which sensors and motors are connected to each controller
00054       @param controllerName name
00055       @param numCtrlCreateBeforeInit number of controller that are generated before the init function is called. Useful if they should be put into the inspectable list of the agent
00056       @param numContextSensors number of context sensors (counted from the end)
00057        passed to all controllers
00058    */
00059   SplitControl(ControllerGenerator* controllerGenerator,
00060                const Assoziations& assoziations,
00061                std::string controllerName,
00062                int numCtrlCreateBeforeInit = 1,
00063                int numContextSensors = 0
00064                );
00065 
00066   virtual ~SplitControl();
00067 
00068 
00069   virtual void init(int sensornumber, int motornumber, RandGen* randGen = 0);
00070 
00071   virtual void step(const sensor* sensors, int sensornumber,
00072                     motor* motors, int motornumber);
00073 
00074   virtual void stepNoLearning(const sensor* sensors , int sensornumber,
00075                                     motor* motors, int motornumber);
00076 
00077   virtual int getSensorNumber() const {return sensornumber; }
00078   virtual int getMotorNumber() const  {return motornumber; }
00079 
00080   /*********** STORABLE **************/
00081 
00082   virtual bool store(FILE* f) const {return false;}
00083   
00084   virtual bool restore(FILE* f) {return false;}
00085 
00086 
00087   virtual std::vector<AbstractController*> getControllers() const { return ctrl;}
00088   
00089 protected:
00090   std::vector<AbstractController*> ctrl;
00091 
00092   
00093   ControllerGenerator* controllerGenerator;
00094   Assoziations assoz;
00095   int numCtrlCreateBeforeInit;
00096   int numContextSensors;
00097   int motornumber;
00098   int sensornumber;
00099   double* sensorbuffer;
00100   double* motorbuffer;
00101 };
00102 
00103 #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