Robot Simulator of the Robotics Group for Self-Organization of Control  0.8.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
crossmotorcoupling.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2011 by *
3  * Georg Martius <georg dot martius at web dot de> *
4  * Ralf Der <ralfder at mis dot mpg dot de> *
5  * *
6  * ANY COMMERCIAL USE FORBIDDEN! *
7  * LICENSE: *
8  * This work is licensed under the Creative Commons *
9  * Attribution-NonCommercial-ShareAlike 2.5 License. To view a copy of *
10  * this license, visit http://creativecommons.org/licenses/by-nc-sa/2.5/ *
11  * or send a letter to Creative Commons, 543 Howard Street, 5th Floor, *
12  * San Francisco, California, 94105, USA. *
13  * *
14  * This program is distributed in the hope that it will be useful, *
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
17  * *
18  ***************************************************************************/
19 
20 #ifndef __CROSSMOTORCOUPLING_H
21 #define __CROSSMOTORCOUPLING_H
22 
23 #include "teachable.h"
25 
26 #include <list>
27 #include <vector>
28 
29 /**
30  Adjacency lists representing the connection graph.
31  CMC[i] contains the list of indices of motors,
32  which are used as teaching signals for motor i.
33 */
34 typedef std::vector< std::list<int> > CMC;
35 
36 /**
37  * This is an adapter for a teachable controller to implement a
38  * cross motor coupling, see dissertation of Georg Martius
39  *
40  */
42 public:
43 
44 
45  /**
46  @param controller actual controller
47  @param teachable also pointer to the controller, must be equal to controller.
48  This trick is used to ensure that the controller is both "AbstractController" and "Teachable".
49  @param threshold value below which (absolute) no cross motor teaching is done
50  (avoids suppression of activity)
51  */
53  : AbstractControllerAdapter(controller, "CrossMotorCoupling", "$ID$"), teachable(teachable), threshold(threshold) {
54  // We check whether controller and teachable are equally the same thing.
55  // the pure pointer comparison does not work, because the type case
56  // also moves the pointer for the other vtable (tricky!)
57  // That is why we need dynamic_cast here
58  Teachable* t2 = dynamic_cast<Teachable*>(controller);
59  t2=t2; // this is to avoid a "unused variable" in -DNDEBUG mode
60  assert((void*)t2==(void*)teachable);
61  }
62 
63  virtual void step(const sensor* sensors, int sensornumber, motor* motors, int motornumber);
64 
65  virtual void setCMC(const CMC& cmc);
66  virtual CMC getCMC();
67 
68  /**** TEACHABLE Interface pass through ****/
69 
70  virtual void setMotorTeaching(const matrix::Matrix& teaching){
71  teachable->setMotorTeaching(teaching);
72  }
73 
74  virtual void setSensorTeaching(const matrix::Matrix& teaching){
75  teachable->setSensorTeaching(teaching);
76  }
78  return teachable->getLastMotorValues();
79  }
80 
83  }
84 
85  /**
86  creates a permutation cross motor coupling, where for each motor
87  we define one cross motor connection.
88  @param permutation permutation[i]=j means that motor i receives from motor j
89  */
90  static CMC getPermutationCMC(const std::list<int>& permutation);
91 
92 protected:
95  double threshold; ///< treshhold below which not cmc-teaching is done
96 
97 };
98 
99 #endif
Matrix type.
Definition: matrix.h:65
Interface for teachable controller.
Definition: teachable.h:32
Abstract class for robot controller (with some basic functionality).
Definition: abstractcontroller.h:46
Abstract adapter class (interface) for robot controller.
Definition: abstractcontrolleradapter.h:52
virtual matrix::Matrix getLastSensorValues()=0
returns the last sensor values (useful for cross sensor coupling)
virtual void setMotorTeaching(const matrix::Matrix &teaching)=0
The given motor teaching signal is used for this timestep.
virtual matrix::Matrix getLastMotorValues()=0
returns the last motor values (useful for cross motor coupling)
CMC cmc
Definition: crossmotorcoupling.h:93
double sensor
Definition: types.h:29
static CMC getPermutationCMC(const std::list< int > &permutation)
creates a permutation cross motor coupling, where for each motor we define one cross motor connection...
Definition: crossmotorcoupling.cpp:58
AbstractController * controller
Definition: abstractcontrolleradapter.h:158
virtual matrix::Matrix getLastSensorValues()
returns the last sensor values (useful for cross sensor coupling)
Definition: crossmotorcoupling.h:81
virtual void setSensorTeaching(const matrix::Matrix &teaching)=0
The given sensor teaching signal (distal learning) is used for this timestep.
Teachable * teachable
Definition: crossmotorcoupling.h:94
virtual CMC getCMC()
Definition: crossmotorcoupling.cpp:53
virtual void setSensorTeaching(const matrix::Matrix &teaching)
The given sensor teaching signal (distal learning) is used for this timestep.
Definition: crossmotorcoupling.h:74
CrossMotorCoupling(AbstractController *controller, Teachable *teachable, double threshold=0.4)
Definition: crossmotorcoupling.h:52
virtual matrix::Matrix getLastMotorValues()
returns the last motor values (useful for cross motor coupling)
Definition: crossmotorcoupling.h:77
std::vector< std::list< int > > CMC
Adjacency lists representing the connection graph.
Definition: crossmotorcoupling.h:34
double motor
Definition: types.h:30
virtual void step(const sensor *sensors, int sensornumber, motor *motors, int motornumber)
performs one step (includes learning).
Definition: crossmotorcoupling.cpp:25
double threshold
treshhold below which not cmc-teaching is done
Definition: crossmotorcoupling.h:95
virtual void setCMC(const CMC &cmc)
Definition: crossmotorcoupling.cpp:49
virtual void setMotorTeaching(const matrix::Matrix &teaching)
The given motor teaching signal is used for this timestep.
Definition: crossmotorcoupling.h:70
This is an adapter for a teachable controller to implement a cross motor coupling, see dissertation of Georg Martius.
Definition: crossmotorcoupling.h:41