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

Generated on Tue Jan 16 02:14:35 2007 for Robotsystem of the Robot Group Leipzig by doxygen 1.3.8