00001 /*************************************************************************** 00002 * Copyright (C) 2005-2011 by * 00003 * Georg Martius <georg dot martius at web dot de> * 00004 * Ralf Der <ralfder at mis dot mpg dot de> * 00005 * * 00006 * ANY COMMERCIAL USE FORBIDDEN! * 00007 * LICENSE: * 00008 * This work is licensed under the Creative Commons * 00009 * Attribution-NonCommercial-ShareAlike 2.5 License. To view a copy of * 00010 * this license, visit http://creativecommons.org/licenses/by-nc-sa/2.5/ * 00011 * or send a letter to Creative Commons, 543 Howard Street, 5th Floor, * 00012 * San Francisco, California, 94105, USA. * 00013 * * 00014 * This program is distributed in the hope that it will be useful, * 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * 00017 * * 00018 ***************************************************************************/ 00019 00020 #ifndef __CROSSMOTORCOUPLING_H 00021 #define __CROSSMOTORCOUPLING_H 00022 00023 #include "teachable.h" 00024 #include "abstractcontrolleradapter.h" 00025 00026 #include <list> 00027 #include <vector> 00028 00029 /** 00030 Adjacency lists representing the connection graph. 00031 CMC[i] contains the list of indices of motors, 00032 which are used as teaching signals for motor i. 00033 */ 00034 typedef std::vector< std::list<int> > CMC; 00035 00036 /** 00037 * This is an adapter for a teachable controller to implement a 00038 * cross motor coupling, see dissertation of Georg Martius 00039 * 00040 */ 00041 class CrossMotorCoupling : public AbstractControllerAdapter, public Teachable { 00042 public: 00043 00044 00045 /** 00046 @param controller actual controller 00047 @param teachable also pointer to the controller, must be equal to controller. 00048 This trick is used to ensure that the controller is both "AbstractController" and "Teachable". 00049 @param threshold value below which (absolute) no cross motor teaching is done 00050 (avoids suppression of activity) 00051 */ 00052 CrossMotorCoupling( AbstractController* controller, Teachable* teachable, double threshold = 0.4) 00053 : AbstractControllerAdapter(controller, "CrossMotorCoupling", "$ID$"), teachable(teachable), threshold(threshold) { 00054 // We check whether controller and teachable are equally the same thing. 00055 // the pure pointer comparison does not work, because the type case 00056 // also moves the pointer for the other vtable (tricky!) 00057 // That is why we need dynamic_cast here 00058 Teachable* t2 = dynamic_cast<Teachable*>(controller); 00059 t2=t2; // this is to avoid a "unused variable" in -DNDEBUG mode 00060 assert((void*)t2==(void*)teachable); 00061 } 00062 00063 virtual void step(const sensor* sensors, int sensornumber, motor* motors, int motornumber); 00064 00065 virtual void setCMC(const CMC& cmc); 00066 virtual CMC getCMC(); 00067 00068 /**** TEACHABLE Interface pass through ****/ 00069 00070 virtual void setMotorTeaching(const matrix::Matrix& teaching){ 00071 teachable->setMotorTeaching(teaching); 00072 } 00073 00074 virtual void setSensorTeaching(const matrix::Matrix& teaching){ 00075 teachable->setSensorTeaching(teaching); 00076 } 00077 virtual matrix::Matrix getLastMotorValues(){ 00078 return teachable->getLastMotorValues(); 00079 } 00080 00081 virtual matrix::Matrix getLastSensorValues(){ 00082 return teachable->getLastSensorValues(); 00083 } 00084 00085 /** 00086 creates a permutation cross motor coupling, where for each motor 00087 we define one cross motor connection. 00088 @param permutation permutation[i]=j means that motor i receives from motor j 00089 */ 00090 static CMC getPermutationCMC(const std::list<int>& permutation); 00091 00092 protected: 00093 CMC cmc; 00094 Teachable* teachable; 00095 double threshold; ///< treshhold below which not cmc-teaching is done 00096 00097 }; 00098 00099 #endif