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: derivativewiring.h,v $ 00023 * Revision 1.2 2006/07/14 12:24:02 martius 00024 * selforg becomes HEAD 00025 * 00026 * Revision 1.1.2.1 2005/11/16 11:24:28 martius 00027 * moved to selforg 00028 * 00029 * Revision 1.6 2005/10/28 12:05:27 martius 00030 * adapted time horizont for derivative 00031 * to quater of the time horizont of averaging 00032 * 00033 * Revision 1.5 2005/10/24 13:32:07 fhesse 00034 * comments adjusted and in doxygen style 00035 * 00036 * Revision 1.4 2005/10/24 11:06:33 fhesse 00037 * comments adjusted and in doxygen style 00038 * 00039 * Revision 1.3 2005/07/21 15:09:00 martius 00040 * blind motors 00041 * 00042 * Revision 1.2 2005/07/21 11:30:59 fhesse 00043 * started with blind motors 00044 * 00045 * Revision 1.1 2005/07/18 14:44:55 martius 00046 * wiring that supports derivatives 00047 * 00048 * * 00049 ***************************************************************************/ 00050 #ifndef __DERIVATIVEWIRING_H 00051 #define __DERIVATIVEWIRING_H 00052 00053 #include "abstractwiring.h" 00054 00055 /** Configuration Object for DerivativeWiring. 00056 If all boolean parametes are false, id is set to true (equivalent to One2OneWiring) 00057 */ 00058 typedef struct __DerivativeWiringConf { 00059 bool useId; //< include zeroth derivative 00060 bool useFirstD; //< include first derivative 00061 bool useSecondD; //< second include second derivative 00062 double eps; //< update rate for floating average (0 -> no sensor variation, 1 -> no smoothing) 00063 double derivativeScale; //< factor for the derivatives 00064 unsigned int blindMotorSets; //< number of complete motor sets that are blind (not given to robot) 00065 } DerivativeWiringConf; 00066 00067 00068 /** Implements a wiring (between controller and robot) 00069 which includes the first and second derivative 00070 of the original robot sensor values 00071 */ 00072 class DerivativeWiring : public AbstractWiring{ 00073 public: 00074 /** constructor 00075 @param conf for giving the wished configuration of DerivativeWiring 00076 via \ref __DerivativeWiringConf "DerivativeWiringConf" 00077 @param noise NoiseGenerator that is used for adding noise to sensor values 00078 */ 00079 DerivativeWiring(const DerivativeWiringConf& conf, 00080 NoiseGenerator* noise); 00081 00082 /** destructor 00083 */ 00084 virtual ~DerivativeWiring(); 00085 00086 /** initializes the internal numbers of sensors and motors on robot side, calculate 00087 number of sensors and motors on controller side 00088 */ 00089 virtual bool init(int robotsensornumber, int robotmotornumber); 00090 00091 /** Realizes derivative wiring from robot sensors to controller sensors. 00092 @param rsensors pointer to array of sensorvalues from robot 00093 @param rsensornumber number of sensors from robot 00094 @param csensors pointer to array of sensorvalues for controller 00095 @param csensornumber number of sensors to controller 00096 @param noise size of the noise added to the sensors 00097 */ 00098 virtual bool wireSensors(const sensor* rsensors, int rsensornumber, 00099 sensor* csensors, int csensornumber, 00100 double noise); 00101 00102 /** Realizes wiring from controller motor outputs to robot motors. 00103 @param rmotors pointer to array of motorvalues for robot 00104 @param rmotornumber number of robot motors 00105 @param cmotors pointer to array of motorvalues from controller 00106 @param cmotornumber number of motorvalues from controller 00107 */ 00108 virtual bool wireMotors(motor* rmotors, int rmotornumber, 00109 const motor* cmotors, int cmotornumber); 00110 00111 /** Providing default configuration for DerivativeWiring as static method 00112 */ 00113 static DerivativeWiringConf getDefaultConf(){ 00114 DerivativeWiringConf c; 00115 c.useId = true; // use id 00116 c.useFirstD = false; // do not use first derivative 00117 c.useSecondD = false; // do not use secound derivative 00118 c.eps = 0.05; 00119 c.derivativeScale=3; 00120 c.blindMotorSets=0; // no blind motors used 00121 return c; 00122 }; 00123 00124 protected: 00125 /** Calculate the first derivative of the sensorvalues given by the robot 00126 * f'(x) = (f(x+1) - f(x-1)) / 2 00127 * since we do not have f(x+1) we go one timestep in the past 00128 */ 00129 void calcFirstDerivative(); 00130 00131 /** Calculate the secound derivative of the sensorvalues given by the robot 00132 * f'(x) = f(x) - 2f(x-1) + f(x-2) 00133 */ 00134 void calcSecondDerivative(); 00135 00136 /// used configuration 00137 DerivativeWiringConf conf; 00138 static const int buffersize=40; 00139 int time; 00140 /// number timesteps the sensor values are delayed for calculation of the derivative 00141 int delay; 00142 00143 00144 /// current and old smoothed sensor values of robot 00145 sensor* sensorbuffer[buffersize]; 00146 00147 /// current sensors (with noise) 00148 sensor* id; 00149 00150 /// current first derivative 00151 sensor* first; 00152 00153 /// current second derivative 00154 sensor* second; 00155 00156 /// array that stored the values of the blind motors 00157 motor *blindMotors; 00158 00159 /// number of blind motors used 00160 unsigned int blindMotorNumber; 00161 }; 00162 00163 #endif
1.4.7