use_java_controller.h

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: use_java_controller.h,v $
00023  *   Revision 1.3  2009/05/14 14:23:45  martius
00024  *   *** empty log message ***
00025  *
00026  *   Revision 1.2  2008/10/06 14:25:57  martius
00027  *   use const qualifier where warnings where produced
00028  *
00029  *   Revision 1.1  2007/12/12 15:46:00  robot3
00030  *   Gwizdziel
00031  *
00032  *   Revision 1.1  2007/12/10 15:39:05  robot3
00033  *   Gwizdziel
00034  *                                            *
00035  *   Revision 1.10  2006/11/29 16:22:43  martius
00036  *   name is a variable of configurable and is used as such
00037  *
00038  *
00039  *                                                                         *
00040  ***************************************************************************/
00041 #ifndef __USE_JAVA_CONTROLLER_H
00042 #define __USE_JAVA_CONTROLLER_H
00043 
00044 //#include <stdio.h>
00045 #include "abstractcontroller.h"
00046 
00047 //server
00048 //#include <stdio.h>
00049 #include <string.h>
00050 #include <stdlib.h>
00051 #include <sys/types.h>
00052 #include <sys/socket.h>
00053 #include <netdb.h>
00054 #include <netinet/in.h>
00055 #include <arpa/inet.h>
00056 #include <unistd.h>
00057 #include <fcntl.h>
00058 #include <exception>
00059 
00060 
00061 #define BUFFER_SIZE 1024
00062 #define MAX_CONFIG_PARAM 50
00063 #define MAX_INTERNAL_PARAM 50
00064 
00065 
00066 double atof ( const char * );
00067 int    ctoi ( const char * );
00068 
00069 
00070 using namespace std;
00071 
00072 /**
00073  * class for robot control with sine and cosine
00074  *
00075  *
00076  */
00077 class use_java_controller : public AbstractController
00078 {
00079         
00080     
00081         
00082 
00083 
00084         
00085         public:
00086 
00087                 static int anzahl_Java_controller;
00088        
00089 
00090                 use_java_controller ( const char* port_controller = "4444", const char* port_internalParams = NULL, const char* name = "defaultRobot" );
00091 
00092 
00093                 static void addController(){use_java_controller::anzahl_Java_controller++;}
00094                 
00095         
00096                 virtual ~use_java_controller();
00097 
00098                 /** initialisation of the controller with the given sensor/ motornumber
00099                     Must be called before use.
00100                 */
00101   virtual void init ( int sensornumber, int motornumber, RandGen* randgen = 0);
00102 
00103                 /** @return Number of sensors the controller was initialised
00104                     with or 0 if not initialised */
00105                 virtual int getSensorNumber() const {return number_sensors;}
00106 
00107 
00108                 /** @return Number of motors the controller was initialised
00109                     with or 0 if not initialised */
00110                 virtual int getMotorNumber() const {return number_motors;}
00111 
00112                 /** performs one step (includes learning).
00113                     Calculates motor commands from sensor inputs.
00114                     @param sensors sensors inputs scaled to [-1,1]
00115                     @param sensornumber length of the sensor array
00116                     @param motors motors outputs. MUST have enough space for motor values!
00117                     @param motornumber length of the provided motor array
00118                 */
00119                 virtual void step ( const sensor* sensors, int sensornumber,
00120                                     motor* motors, int motornumber );
00121                 /** performs one step without learning.
00122                     @see step
00123                 */
00124                 virtual void stepNoLearning ( const sensor* , int number_sensors,
00125                                               motor* , int number_motors );
00126 
00127                 /**
00128                   * Methode verschickt message an Java-controller
00129                   */
00130                 void sendToJava ( const char* message,bool abbruch, const char* meldung="Fehler beim Senden der Daten zum Java-Controller\n" );
00131         
00132         void closeJavaController();
00133 
00134 
00135                 /**
00136                 * executed once when guilogger or neuronvis or file logger is started to get the names of the
00137                 inspectable parameters (names should be sent from java-controller and returned)
00138                 */
00139                 virtual std::list<iparamkey> getInternalParamNames() const;
00140                 /**
00141                 * executed every step when guilogger or neuronvis or file logger is active to get the values of the
00142                 inspectable parameters (values should be sent from java-controller and returned)
00143                 */
00144                 
00145                 virtual std::list<iparamval> getInternalParams() const;
00146                 
00147                 // next three described in cpp-file
00148                 virtual paramval getParam ( const paramkey& key ) const;
00149                 virtual bool setParam ( const paramkey& key, paramval val );
00150                 virtual paramlist getParamList() const ;
00151 
00152                 
00153 
00154                 virtual bool store   ( FILE* f ) const { return true;};  // FIXME: store Parameter
00155                 virtual bool restore ( FILE* f )       { return true;};  // FIXME: restore Parameter
00156 
00157 
00158         protected:
00159 
00160                 int t;
00161                 const char* name;
00162                 int number_sensors;
00163                 int number_motors;
00164                 int number_controlled; 
00165 
00166                 bool serverOK;
00167 
00168                 int server_controller;
00169                 int server_internalParams;
00170                 int client_controller;
00171                 int client_internalParams;
00172 
00173                 socklen_t client_controller_size;
00174                 socklen_t client_internalParams_size;
00175 
00176                 struct sockaddr_in server_controller_addr;
00177                 struct sockaddr_in server_internalParams_addr;
00178                 struct sockaddr_in client_controller_addr;
00179                 struct sockaddr_in client_internalParams_addr;
00180 
00181 
00182                 paramlist config_param_list;
00183                 int anz_config_param;
00184                 
00185                 iparamkeylist internal_keylist;
00186                 iparamvallist internal_vallist;
00187                 iparamvallist internal_vallist_alt;
00188                 int anz_internal_param;
00189 
00190                 bool can_send;
00191             bool isFirst;
00192                 bool isClosed;
00193                 bool server_guilogger_isClosed;
00194                 bool server_controller_isClosed;
00195 
00196                 int anzahl_closed_Server;
00197 
00198                 double *motor_values_alt;
00199 
00200 };
00201 
00202 
00203 
00204 #endif

Generated on Fri Oct 30 16:29:01 2009 for Robot Simulator of the Robotics Group for Self-Organization of Control by  doxygen 1.4.7