selectiveone2onewiring.cpp

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: selectiveone2onewiring.cpp,v $
00023  *   Revision 1.1.2.1  2005/11/16 11:24:28  martius
00024  *   moved to selforg
00025  *
00026  *   Revision 1.3  2005/10/24 13:32:07  fhesse
00027  *   comments adjusted and in doxygen style
00028  *
00029  *   Revision 1.2  2005/08/31 11:11:37  martius
00030  *   noise->noisevals
00031  *
00032  *   Revision 1.1  2005/08/22 17:28:12  martius
00033  *   a 1 to 1 wiring that supports the selection of some sensors only
00034  *
00035  *                                                                         *
00036  ***************************************************************************/
00037 
00038 #include "selectiveone2onewiring.h"
00039 #include "assert.h"
00040 
00041 bool select_all(unsigned int index, unsigned int len){
00042   return true;
00043 }
00044 bool select_firsthalf(unsigned int index, unsigned int len){
00045   return index < len/2;
00046 }
00047 
00048 
00049 /// constructor
00050 SelectiveOne2OneWiring::SelectiveOne2OneWiring(NoiseGenerator* noise, 
00051                                                select_predicate sel_sensor)
00052   : One2OneWiring(noise){
00053   this->sel_sensor = sel_sensor;
00054 }
00055 
00056 SelectiveOne2OneWiring::~SelectiveOne2OneWiring(){
00057 }
00058 
00059 
00060 /// initializes the number of sensors and motors on robot side, calculate
00061 //  number of sensors and motors on controller side
00062 bool SelectiveOne2OneWiring::init(int robotsensornumber, int robotmotornumber){
00063   One2OneWiring::init(robotsensornumber, robotmotornumber);
00064   assert(sel_sensor);
00065   int num=0;
00066   for(int i=0; i<robotsensornumber; i++){
00067     if(sel_sensor(i,robotsensornumber)) num++;
00068   }  
00069   printf("csensornumber: %i\n", num);
00070   csensornumber = num;
00071   return true;
00072 }
00073 
00074 /// Realizes selective one to one wiring from robot sensors to controller sensors. 
00075 //   @param rsensors pointer to array of sensorvalues from robot 
00076 //   @param rsensornumber number of sensors from robot
00077 //   @param csensors pointer to array of sensorvalues for controller  
00078 //   @param csensornumber number of sensors to controller
00079 //   @param noise size of the noise added to the sensors
00080 bool SelectiveOne2OneWiring::wireSensors(const sensor* rsensors, int rsensornumber, 
00081                                 sensor* csensors, int csensornumber, 
00082                                 double noiseStrength){
00083   memset(noisevals, 0 , sizeof(sensor) * this->rsensornumber);
00084   noiseGenerator->add(noisevals, -noiseStrength, noiseStrength);   
00085   int num=0;
00086   for(int i=0; i< rsensornumber; i++){
00087     if(sel_sensor(i,rsensornumber)){
00088       csensors[num] = rsensors[i] + noisevals[i];
00089       num++;
00090     }
00091   }
00092   return true;
00093 }
00094 

Generated on Tue Apr 4 19:05:04 2006 for Robotsystem from Robot Group Leipzig by  doxygen 1.4.5