Robot Simulator of the Robotics Group for Self-Organization of Control: use_java_controller.h Source File

# use_java_controller.h

Go to the documentation of this file.

    00001 /***************************************************************************
    00002  *   Copyright (C) 2005-2011 LpzRobots development team                    *
    00003  *    Georg Martius  <georg dot martius at web dot de>                     *
    00004  *    Frank Guettler <guettler at informatik dot uni-leipzig dot de        *
    00005  *    Frank Hesse    <frank at nld dot ds dot mpg dot de>                  *
    00006  *    Ralf Der       <ralfder at mis dot mpg dot de>                       *
    00007  *                                                                         *
    00008  *   This program is free software; you can redistribute it and/or modify  *
    00009  *   it under the terms of the GNU General Public License as published by  *
    00010  *   the Free Software Foundation; either version 2 of the License, or     *
    00011  *   (at your option) any later version.                                   *
    00012  *                                                                         *
    00013  *   This program is distributed in the hope that it will be useful,       *
    00014  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
    00015  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
    00016  *   GNU General Public License for more details.                          *
    00017  *                                                                         *
    00018  *   You should have received a copy of the GNU General Public License     *
    00019  *   along with this program; if not, write to the                         *
    00020  *   Free Software Foundation, Inc.,                                       *
    00021  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
    00022  *                                                                         *
    00023  ***************************************************************************/
    00024 #ifndef __USE_JAVA_CONTROLLER_H
    00025 #define __USE_JAVA_CONTROLLER_H
    00026
    00027 #ifndef WIN32
    00028
    00029 //#include <stdio.h>
    00030 #include "abstractcontroller.h"
    00031
    00032 //server
    00033 //#include <stdio.h>
    00034 #include <string.h>
    00035 #include <stdlib.h>
    00036 #include <sys/types.h>
    00037 #include <sys/socket.h>
    00038 #include <netdb.h>
    00039 #include <netinet/in.h>
    00040 #include <arpa/inet.h>
    00041 #include <unistd.h>
    00042 #include <fcntl.h>
    00043 #include <exception>
    00044
    00045
    00046 #define BUFFER_SIZE 1024
    00047 #define MAX_CONFIG_PARAM 50
    00048 #define MAX_INTERNAL_PARAM 50
    00049
    00050
    00051 double atof ( const char * );
    00052 int    ctoi ( const char * );
    00053
    00054
    00055 using namespace std;
    00056
    00057 /**
    00058  * class for robot control with sine and cosine
    00059  *
    00060  *
    00061  */
    00062 class use_java_controller : public AbstractController
    00063 {
    00064
    00065
    00066
    00067
    00068
    00069
    00070         public:
    00071
    00072                 static int anzahl_Java_controller;
    00073
    00074
    00075                 use_java_controller ( const char* port_controller = "4444", const char* port_internalParams = NULL, const char* name = "defaultRobot" );
    00076
    00077
    00078                 static void addController(){use_java_controller::anzahl_Java_controller++;}
    00079
    00080
    00081                 virtual ~use_java_controller();
    00082
    00083                 /** initialisation of the controller with the given sensor/ motornumber
    00084                     Must be called before use.
    00085                 */
    00086   virtual void init ( int sensornumber, int motornumber, RandGen* randgen = 0);
    00087
    00088                 /** @return Number of sensors the controller was initialised
    00089                     with or 0 if not initialised */
    00090                 virtual int getSensorNumber() const {return number_sensors;}
    00091
    00092
    00093                 /** @return Number of motors the controller was initialised
    00094                     with or 0 if not initialised */
    00095                 virtual int getMotorNumber() const {return number_motors;}
    00096
    00097                 /** performs one step (includes learning).
    00098                     Calculates motor commands from sensor inputs.
    00099                     @param sensors sensors inputs scaled to [-1,1]
    00100                     @param sensornumber length of the sensor array
    00101                     @param motors motors outputs. MUST have enough space for motor values!
    00102                     @param motornumber length of the provided motor array
    00103                 */
    00104                 virtual void step ( const sensor* sensors, int sensornumber,
    00105                                     motor* motors, int motornumber );
    00106                 /** performs one step without learning.
    00107                     @see step
    00108                 */
    00109                 virtual void stepNoLearning ( const sensor* , int number_sensors,
    00110                                               motor* , int number_motors );
    00111
    00112                 /**
    00113                   * Methode verschickt message an Java-controller
    00114                   */
    00115                 void sendToJava ( const char* message,bool abbruch, const char* meldung="Fehler beim Senden der Daten zum Java-Controller\n" );
    00116
    00117         void closeJavaController();
    00118
    00119
    00120                 /**
    00121                 * executed once when guilogger or neuronvis or file logger is started to get the names of the
    00122                 inspectable parameters (names should be sent from java-controller and returned)
    00123                 */
    00124                 virtual std::list<iparamkey> getInternalParamNames() const;
    00125                 /**
    00126                 * executed every step when guilogger or neuronvis or file logger is active to get the values of the
    00127                 inspectable parameters (values should be sent from java-controller and returned)
    00128                 */
    00129
    00130                 virtual std::list<iparamval> getInternalParams() const;
    00131
    00132                 // next three described in cpp-file
    00133                 virtual paramval getParam ( const paramkey& key ) const;
    00134                 virtual bool setParam ( const paramkey& key, paramval val );
    00135                 virtual paramlist getParamList() const ;
    00136
    00137
    00138
    00139                 virtual bool store   ( FILE* f ) const { return true;};  // FIXME: store Parameter
    00140                 virtual bool restore ( FILE* f )       { return true;};  // FIXME: restore Parameter
    00141
    00142
    00143         protected:
    00144
    00145                 int t;
    00146                 const char* name;
    00147                 int number_sensors;
    00148                 int number_motors;
    00149                 int number_controlled;
    00150
    00151                 bool serverOK;
    00152
    00153                 int server_controller;
    00154                 int server_internalParams;
    00155                 int client_controller;
    00156                 int client_internalParams;
    00157
    00158                 socklen_t client_controller_size;
    00159                 socklen_t client_internalParams_size;
    00160
    00161                 struct sockaddr_in server_controller_addr;
    00162                 struct sockaddr_in server_internalParams_addr;
    00163                 struct sockaddr_in client_controller_addr;
    00164                 struct sockaddr_in client_internalParams_addr;
    00165
    00166
    00167                 paramlist config_param_list;
    00168                 int anz_config_param;
    00169
    00170                 iparamkeylist internal_keylist;
    00171                 iparamvallist internal_vallist;
    00172                 iparamvallist internal_vallist_alt;
    00173                 int anz_internal_param;
    00174
    00175                 bool can_send;
    00176             bool isFirst;
    00177                 bool isClosed;
    00178                 bool server_guilogger_isClosed;
    00179                 bool server_controller_isClosed;
    00180
    00181                 int anzahl_closed_Server;
    00182
    00183                 double *motor_values_alt;
    00184
    00185 };
    00186
    00187 #endif // win32
    00188
    00189 #endif