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: shortcircuit.cpp,v $ 00023 * Revision 1.5.4.3 2006/01/10 20:32:51 martius 00024 * moved to osg 00025 * 00026 * Revision 1.5.4.2 2005/11/15 12:29:27 martius 00027 * new selforg structure and OdeAgent, OdeRobot ... 00028 * 00029 * Revision 1.5.4.1 2005/11/14 17:37:18 martius 00030 * moved to selforg 00031 * 00032 * Revision 1.5 2005/11/09 13:24:42 martius 00033 * added GPL 00034 * 00035 ***************************************************************************/ 00036 #include <assert.h> 00037 00038 #include "simulation.h" 00039 00040 #include "shortcircuit.h" 00041 00042 namespace lpzrobots { 00043 00044 ShortCircuit::ShortCircuit(const OdeHandle& odeHandle, 00045 const OsgHandle& osgHandle, int sensornumber, int motornumber) 00046 : OdeRobot(odeHandle, osgHandle){ 00047 00048 sensorno = sensornumber; 00049 motorno = motornumber; 00050 motors = (motor*)malloc(motorno * sizeof(motor)); 00051 for(int i=0; i < motorno; i++){ 00052 motors[i]=0.0; 00053 } 00054 00055 }; 00056 00057 /** sets actual motorcommands 00058 @param motors motors scaled to [-1,1] 00059 @param motornumber length of the motor array 00060 */ 00061 void ShortCircuit::setMotors(const motor* _motors, int motornumber){ 00062 assert(motornumber == motorno); 00063 memcpy(motors, _motors, sizeof(motor) * motornumber); 00064 }; 00065 00066 /** returns actual sensorvalues 00067 @param sensors sensors scaled to [-1,1] (more or less) 00068 @param sensornumber length of the sensor array 00069 @return number of actually written sensors 00070 */ 00071 int ShortCircuit::getSensors(sensor* sensors, int sensornumber){ 00072 assert(sensornumber == sensorno); 00073 int mini = min(sensorno,motorno); 00074 for (int i=0; i< mini; i++){ 00075 sensors[i]=motors[i]; // %motorno 00076 } 00077 for (int i=mini; i< sensorno; i++){ 00078 sensors[i]=0; 00079 } 00080 return sensorno; 00081 }; 00082 00083 00084 }