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: odeagent.h,v $ 00023 * Revision 1.8 2008/04/18 09:50:24 guettler 00024 * Implemented step functions for multiple threads of the class Simulation 00025 * 00026 * Revision 1.7 2008/04/17 15:59:00 martius 00027 * OSG2 port finished 00028 * 00029 * Revision 1.6.2.1 2008/04/17 15:05:47 martius 00030 * use RandGen 00031 * 00032 * Revision 1.6 2007/08/30 09:46:41 martius 00033 * simulation time 00034 * 00035 * Revision 1.5 2007/03/28 07:16:58 martius 00036 * trace is drawn thicker 00037 * 00038 * Revision 1.4 2006/12/11 18:11:01 martius 00039 * noisefactor and default constructor 00040 * 00041 * Revision 1.3 2006/07/20 17:19:43 martius 00042 * removed using namespace std from matrix.h 00043 * 00044 * Revision 1.2 2006/07/14 12:23:31 martius 00045 * selforg becomes HEAD 00046 * 00047 * Revision 1.1.2.6 2006/05/15 13:14:10 robot3 00048 * STRG-R now makes screenshots in jpg-format 00049 * STRG-F now toggles the file logging (controller stuff) on/off 00050 * STRG-G now restarts the GuiLogger 00051 * 00052 * Revision 1.1.2.5 2006/03/31 16:16:58 fhesse 00053 * changed trace() to init_tracing() 00054 * and check for init at beginning of step 00055 * 00056 * Revision 1.1.2.4 2006/03/29 15:08:06 martius 00057 * Agent::interninit not necessary 00058 * 00059 * Revision 1.1.2.3 2006/03/28 14:14:44 fhesse 00060 * tracing of a given primitive (in the osg window) added 00061 * 00062 * Revision 1.1.2.2 2005/12/06 10:13:23 martius 00063 * openscenegraph integration started 00064 * 00065 * Revision 1.1.2.1 2005/11/15 12:29:18 martius 00066 * new selforg structure and OdeAgent, OdeRobot ... 00067 * 00068 * * 00069 ***************************************************************************/ 00070 #ifndef __ODEAGENT_H 00071 #define __ODEAGENT_H 00072 00073 #include <selforg/agent.h> 00074 #include "oderobot.h" 00075 #include "osgprimitive.h" 00076 #include "primitive.h" 00077 00078 namespace lpzrobots { 00079 00080 /** Specialised agent for ode robots 00081 */ 00082 class OdeAgent : public Agent { 00083 public: 00084 /** constructor 00085 */ 00086 OdeAgent(const PlotOption& plotOption = PlotOption(NoPlot), double noisefactor = 1) 00087 : Agent(plotOption, noisefactor) { tracing_initialized=false; } 00088 OdeAgent(const std::list<PlotOption>& plotOptions, double noisefactor = 1) 00089 : Agent(plotOptions, noisefactor) {tracing_initialized=false;} 00090 /** destructor 00091 */ 00092 virtual ~OdeAgent() {} 00093 00094 /** initializes the object with the given controller, robot and wiring 00095 and initializes pipe to guilogger 00096 */ 00097 virtual bool init(AbstractController* controller, OdeRobot* robot, AbstractWiring* wiring, 00098 long int seed = 0){ 00099 return Agent::init(controller, robot, wiring, seed); 00100 } 00101 00102 00103 virtual void step(double noise, double time); 00104 00105 /** 00106 * Special function for the class Simulation to seperate the step 00107 * of the WiredController (plus TrackRobot) and the setting and getting 00108 * of the motor- and sensorvalues. 00109 * @param noise @see step() 00110 * @param time @see step() 00111 */ 00112 virtual void stepOnlyWiredController(double noise, double time); 00113 00114 /** 00115 * Special function for the class Simulation to seperate the step 00116 * of the WiredController (plus TrackRobot) and the setting and getting 00117 * of the motor- and sensorvalues. 00118 */ 00119 virtual void setMotorsGetSensors(); 00120 00121 00122 void internInit(){ 00123 trace_length=0; // number of past robot positions shown in osg 00124 } 00125 00126 /** 00127 * Returns a pointer to the robot. 00128 */ 00129 virtual OdeRobot* getRobot() { return (OdeRobot*)robot;} 00130 00131 /// gives the number of past robot positions shown as trace in osg 00132 virtual int getTraceLength(){return trace_length;} 00133 00134 /** 00135 * initialize tracing in ode 00136 * @param tracelength number of past positions shown as trace in osg 00137 * @param tracethickness thickness of the trace 00138 */ 00139 virtual void init_tracing(int tracelength=1000, double tracethickness=0.01); 00140 00141 00142 private: 00143 int trace_length; 00144 double trace_thickness; 00145 int counter; 00146 bool tracing_initialized; 00147 00148 OSGPrimitive** segments; // stores segments(cylinders) of the trace 00149 osg::Vec3 lastpos; 00150 }; 00151 00152 } 00153 00154 #endif