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: agent.h,v $ 00023 * Revision 1.1.2.4 2006/03/30 12:33:53 fhesse 00024 * trackrobot now protected to give OdeAgent access 00025 * 00026 * Revision 1.1.2.3 2006/01/31 16:45:18 martius 00027 * neuronviz plotoption 00028 * 00029 * Revision 1.1.2.2 2005/11/15 12:30:26 martius 00030 * new selforg structure and OdeAgent, OdeRobot ... 00031 * 00032 * Revision 1.1.2.1 2005/11/14 17:37:56 martius 00033 * moved to selforg 00034 * 00035 * Revision 1.9 2005/11/07 17:03:30 martius 00036 * class PlotOption added 00037 * agent can be constructed with a list of PlotOptions 00038 * tracking file gets controller parameters as well 00039 * 00040 * Revision 1.8 2005/10/24 13:32:07 fhesse 00041 * comments adjusted and in doxygen style 00042 * 00043 * Revision 1.7 2005/09/22 12:24:36 martius 00044 * removed global variables 00045 * OdeHandle and GlobalData are used instead 00046 * sensor prepared 00047 * 00048 * Revision 1.6 2005/08/03 20:34:58 martius 00049 * use if Inspectable interface 00050 * 00051 * Revision 1.5 2005/07/26 17:01:47 martius 00052 * flushing every 10 00053 * guilogger is opened with nice -2 00054 * 00055 * Revision 1.4 2005/07/18 10:13:46 martius 00056 * noise moved to wiring 00057 * 00058 * Revision 1.3 2005/07/14 15:57:53 fhesse 00059 * now agent contains controller, robot and wiring, plotting ability included, therefore plotagent can be removed; ono2onewiring replaces one2oneagent 00060 * 00061 * Revision 1.2 2005/06/15 14:02:47 martius 00062 * revised and basicly tested 00063 * * 00064 ***************************************************************************/ 00065 #ifndef __AGENT_H 00066 #define __AGENT_H 00067 00068 #include <stdio.h> 00069 #include <list> 00070 using namespace std; 00071 00072 class AbstractRobot; 00073 class AbstractController; 00074 class AbstractWiring; 00075 00076 #include "types.h" 00077 #include "trackrobots.h" 00078 00079 class Agent; 00080 00081 /** Plot mode for plot agent. 00082 */ 00083 enum PlotMode { 00084 /// no plotting to screen or logging to file 00085 NoPlot, 00086 /// only plotting to screen, no logging to file 00087 GuiLogger, 00088 /// plotting to screen and logging to file 00089 GuiLogger_File, 00090 /// net visualiser 00091 NeuronViz 00092 }; 00093 00094 /** Plot either sensors from robot or from controller 00095 (there can be a difference depending on the used wiring) 00096 */ 00097 enum PlotSensors {Robot, Controller}; 00098 00099 /** This class contains option and internal data for the use of an external plot util 00100 like guilogger or neuronviz 00101 */ 00102 class PlotOption { 00103 public: 00104 friend class Agent; 00105 00106 PlotOption(){ mode=NoPlot; whichSensors=Controller; interval=1; pipe=0; } 00107 PlotOption( PlotMode mode, PlotSensors whichSensors = Controller, int interval = 1) 00108 :mode(mode), whichSensors(whichSensors), interval(interval) { pipe=0; } 00109 00110 private: 00111 00112 bool open(); /// opens the connections to the plot tool 00113 void close();/// closes the connections to the plot tool 00114 00115 FILE* pipe; 00116 long t; 00117 00118 PlotMode mode; 00119 PlotSensors whichSensors; 00120 int interval; 00121 }; 00122 00123 00124 /** Object containing controller, robot and wiring between them. 00125 (Corresponding to use of the word in the robotic/simulation domain.) 00126 */ 00127 class Agent { 00128 public: 00129 /** constructor 00130 */ 00131 Agent(const PlotOption& plotOption); 00132 Agent(const list<PlotOption>& plotOptions); 00133 00134 /** destructor 00135 */ 00136 virtual ~Agent(); 00137 00138 /** initializes the object with the given controller, robot and wiring 00139 and initializes pipe to guilogger 00140 */ 00141 virtual bool init(AbstractController* controller, AbstractRobot* robot, AbstractWiring* wiring); 00142 00143 00144 /** Performs an step of the agent, including sensor reading, pushing sensor values through wiring, 00145 controller step, pushing controller outputs (= motorcommands) back through wiring and sent 00146 resulting motorcommands to robot. 00147 @param noise Noise strength. 00148 */ 00149 virtual void step(double noise); 00150 00151 /** Returns a pointer to the controller. 00152 */ 00153 virtual AbstractController* getController() { return controller;} 00154 00155 /** Returns a pointer to the robot. 00156 */ 00157 virtual AbstractRobot* getRobot() { return robot;} 00158 00159 /** Returns a pointer to the wiring. 00160 */ 00161 virtual AbstractWiring* getWiring() { return wiring;} 00162 00163 /// sets the trackoptions which enable tracking of a robot 00164 virtual void setTrackOptions(const TrackRobot& trackrobot); 00165 00166 protected: 00167 00168 /** 00169 * Plots controller sensor- and motorvalues and internal controller parameters. 00170 * @param rx actual sensorvalues from robot (used for generation of motorcommand in actual timestep) 00171 * @param cx actual sensorvalues which are passed to controller (used for generation of motorcommand in actual timestep) 00172 * @param y actual motorcommand (generated in the actual timestep) 00173 */ 00174 virtual void plot(const sensor* rx, int rsensornumber, const sensor* cx, int csensornumber, 00175 const motor* y, int motornumber); 00176 00177 00178 AbstractController* controller; 00179 AbstractRobot* robot; 00180 AbstractWiring* wiring; 00181 00182 /// number of sensors of robot 00183 int rsensornumber; 00184 /// number of motors of robot 00185 int rmotornumber; 00186 /// number of sensors of comntroller 00187 int csensornumber; 00188 /// number of motors of comntroller 00189 int cmotornumber; 00190 00191 sensor *rsensors; 00192 motor *rmotors; 00193 sensor *csensors; 00194 motor *cmotors; 00195 00196 void internInit(); 00197 00198 protected: 00199 TrackRobot trackrobot; 00200 00201 private: 00202 list<PlotOption> plotOptions; 00203 00204 int t; 00205 }; 00206 00207 #endif