Robotsystem of the Robot Group Leipzig: use_java_controller.h Source File

- Main Page
- Namespaces
- Classes
- Files
- Directories
- Related Pages
- Examples

- Search for |

- File List
- File Members

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