Robotsystem from Robot Group Leipzig: one2onewiring.cpp Source File

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Directories
- Examples

- File List
- File Members

# one2onewiring.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: one2onewiring.cpp,v $
    00023  *   Revision 1.1.2.1  2005/11/16 11:24:28  martius
    00024  *   moved to selforg
    00025  *
    00026  *   Revision 1.9  2005/10/28 12:05:54  martius
    00027  *   new inspectable interface
    00028  *
    00029  *   Revision 1.8  2005/10/24 13:32:07  fhesse
    00030  *   comments adjusted and in doxygen style
    00031  *
    00032  *   Revision 1.7  2005/10/06 17:11:37  martius
    00033  *   switched to stl lists
    00034  *
    00035  *   Revision 1.6  2005/08/31 11:10:36  martius
    00036  *   removed bug that causes segfault, it was in malloc of noise(vals)
    00037  *
    00038  *   Revision 1.5  2005/08/03 20:34:58  martius
    00039  *   use if Inspectable interface
    00040  *
    00041  *   Revision 1.4  2005/07/21 15:14:47  martius
    00042  *   wireSensors and wireMotors get constant fields
    00043  *
    00044  *   Revision 1.3  2005/07/18 14:44:27  martius
    00045  *   noise moved into wiring
    00046  *
    00047  *   Revision 1.2  2005/07/18 10:15:13  martius
    00048  *   noise is added here
    00049  *
    00050  *   Revision 1.1  2005/07/14 15:57:54  fhesse
    00051  *   now agent contains controller, robot and wiring, plotting ability included, therefore plotagent can be removed; ono2onewiring replaces one2oneagent
    00052  *                                            *
    00053  *                                                                         *
    00054  ***************************************************************************/
    00055
    00056 #include "one2onewiring.h"
    00057
    00058
    00059 /// constructor
    00060 One2OneWiring::One2OneWiring(NoiseGenerator* noise, bool plotNoise)
    00061   : AbstractWiring(noise), plotNoise(plotNoise){
    00062   noisevals=0;
    00063 }
    00064
    00065 One2OneWiring::~One2OneWiring(){
    00066   if(noisevals) delete (noisevals);
    00067 }
    00068
    00069
    00070 /// initializes the number of sensors and motors from robot, calculate
    00071 //  number of sensors and motors on controller side
    00072 bool One2OneWiring::init(int robotsensornumber, int robotmotornumber){
    00073   rsensornumber = robotsensornumber;
    00074   rmotornumber  = robotmotornumber;
    00075   csensornumber = rsensornumber;
    00076   cmotornumber  = rmotornumber;
    00077
    00078   noisevals     = (sensor*) malloc(sizeof(sensor)  * this->rsensornumber);
    00079
    00080   if(!noiseGenerator) return false;
    00081   noiseGenerator->init(rsensornumber);
    00082   return true;
    00083 }
    00084
    00085 /// Realizes one to one wiring from robot sensors to controller sensors.
    00086 //   @param rsensors pointer to array of sensorvalues from robot
    00087 //   @param rsensornumber number of sensors from robot
    00088 //   @param csensors pointer to array of sensorvalues for controller
    00089 //   @param csensornumber number of sensors to controller
    00090 //   @param noise size of the noise added to the sensors
    00091 bool One2OneWiring::wireSensors(const sensor* rsensors, int rsensornumber,
    00092                                 sensor* csensors, int csensornumber,
    00093                                 double noiseStrength){
    00094   if (rsensornumber!=csensornumber)
    00095     return false;
    00096   else{
    00097     memset(noisevals, 0 , sizeof(sensor) * this->rsensornumber);
    00098     noiseGenerator->add(noisevals, -noiseStrength, noiseStrength);
    00099     for(int i=0; i< rsensornumber; i++){
    00100       csensors[i] = rsensors[i] + noisevals[i];
    00101     }
    00102     return true;
    00103   }
    00104 }
    00105
    00106
    00107 /// Realizes one to one wiring from controller motor outputs to robot motors.
    00108 //   @param rmotors pointer to array of motorvalues for robot
    00109 //   @param rmotornumber number of robot motors
    00110 //   @param cmotors pointer to array of motorvalues from controller
    00111 //   @param cmotornumber number of motorvalues from controller
    00112 bool One2OneWiring::wireMotors(motor* rmotors, int rmotornumber,
    00113                                const motor* cmotors, int cmotornumber){
    00114   if (rmotornumber!=cmotornumber)
    00115     return false;
    00116   else{
    00117     memcpy(rmotors, cmotors, sizeof(motor)*rmotornumber);
    00118     return true;
    00119   }
    00120 }
    00121
    00122 /** Returns the list of the names of all internal parameters.
    00123 */
    00124 list<Inspectable::iparamkey> One2OneWiring::getInternalParamNames() const {
    00125   list<iparamkey> l;
    00126   char buffer[32];
    00127   if(plotNoise) {
    00128     for(int i = 0; i < rsensornumber; i++){
    00129       sprintf(buffer,"n[%d]", i);
    00130       l += string(buffer);
    00131     }
    00132   }
    00133   return l;
    00134 }
    00135
    00136 /** Returns a list of the values of all internal parameters
    00137     (in the order given by getInternalParamNames()).
    00138 */
    00139 list<Inspectable::iparamval> One2OneWiring::getInternalParams() const {
    00140   list<iparamval> l;
    00141   for(int i=0; i < rsensornumber; i++){
    00142     l += noisevals[i];
    00143   }
    00144   return l;
    00145 }
    00146
    00147