Robot Simulator of the Robotics Group for Self-Organization of Control  0.8.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
use_java_controller.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2011 LpzRobots development team *
3  * Georg Martius <georg dot martius at web dot de> *
4  * Frank Guettler <guettler at informatik dot uni-leipzig dot de *
5  * Frank Hesse <frank at nld dot ds dot mpg dot de> *
6  * Ralf Der <ralfder at mis dot mpg dot de> *
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this program; if not, write to the *
20  * Free Software Foundation, Inc., *
21  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
22  * *
23  ***************************************************************************/
24 #ifndef __USE_JAVA_CONTROLLER_H
25 #define __USE_JAVA_CONTROLLER_H
26 
27 #ifndef WIN32
28 
29 //#include <stdio.h>
30 #include "abstractcontroller.h"
31 
32 //server
33 //#include <stdio.h>
34 #include <string.h>
35 #include <stdlib.h>
36 #include <sys/types.h>
37 #include <sys/socket.h>
38 #include <netdb.h>
39 #include <netinet/in.h>
40 #include <arpa/inet.h>
41 #include <unistd.h>
42 #include <fcntl.h>
43 #include <exception>
44 
45 
46 #define BUFFER_SIZE 1024
47 #define MAX_CONFIG_PARAM 50
48 #define MAX_INTERNAL_PARAM 50
49 
50 
51 double atof ( const char * );
52 int ctoi ( const char * );
53 
54 
55 using namespace std;
56 
57 /**
58  * class for robot control with sine and cosine
59  *
60  *
61  */
63 {
64 
65 
66 
67 
68 
69 
70  public:
71 
73 
74 
75  use_java_controller ( const char* port_controller = "4444", const char* port_internalParams = NULL, const char* name = "defaultRobot" );
76 
77 
79 
80 
81  virtual ~use_java_controller();
82 
83  /** initialisation of the controller with the given sensor/ motornumber
84  Must be called before use.
85  */
86  virtual void init ( int sensornumber, int motornumber, RandGen* randgen = 0);
87 
88  /** @return Number of sensors the controller was initialised
89  with or 0 if not initialised */
90  virtual int getSensorNumber() const {return number_sensors;}
91 
92 
93  /** @return Number of motors the controller was initialised
94  with or 0 if not initialised */
95  virtual int getMotorNumber() const {return number_motors;}
96 
97  /** performs one step (includes learning).
98  Calculates motor commands from sensor inputs.
99  @param sensors sensors inputs scaled to [-1,1]
100  @param sensornumber length of the sensor array
101  @param motors motors outputs. MUST have enough space for motor values!
102  @param motornumber length of the provided motor array
103  */
104  virtual void step ( const sensor* sensors, int sensornumber,
105  motor* motors, int motornumber );
106  /** performs one step without learning.
107  @see step
108  */
109  virtual void stepNoLearning ( const sensor* , int number_sensors,
110  motor* , int number_motors );
111 
112  /**
113  * Methode verschickt message an Java-controller
114  */
115  void sendToJava ( const char* message,bool abbruch, const char* meldung="Fehler beim Senden der Daten zum Java-Controller\n" );
116 
117  void closeJavaController();
118 
119 
120  /**
121  * executed once when guilogger or neuronvis or file logger is started to get the names of the
122  inspectable parameters (names should be sent from java-controller and returned)
123  */
124  virtual std::list<iparamkey> getInternalParamNames() const;
125  /**
126  * executed every step when guilogger or neuronvis or file logger is active to get the values of the
127  inspectable parameters (values should be sent from java-controller and returned)
128  */
129 
130  virtual std::list<iparamval> getInternalParams() const;
131 
132  // next three described in cpp-file
133  virtual paramval getParam ( const paramkey& key ) const;
134  virtual bool setParam ( const paramkey& key, paramval val );
135  virtual paramlist getParamList() const ;
136 
137 
138 
139  virtual bool store ( FILE* f ) const { return true;}; // FIXME: store Parameter
140  virtual bool restore ( FILE* f ) { return true;}; // FIXME: restore Parameter
141 
142 
143  protected:
144 
145  int t;
146  const char* name;
150 
151  bool serverOK;
152 
157 
160 
161  struct sockaddr_in server_controller_addr;
162  struct sockaddr_in server_internalParams_addr;
163  struct sockaddr_in client_controller_addr;
164  struct sockaddr_in client_internalParams_addr;
165 
166 
169 
174 
175  bool can_send;
176  bool isFirst;
177  bool isClosed;
180 
182 
184 
185 };
186 
187 #endif // win32
188 
189 #endif
iparamkeylist internal_keylist
Definition: use_java_controller.h:170
int server_internalParams
Definition: use_java_controller.h:154
int anz_internal_param
Definition: use_java_controller.h:173
Abstract class for robot controller (with some basic functionality).
Definition: abstractcontroller.h:46
int server_controller
Definition: use_java_controller.h:153
int anz_config_param
Definition: use_java_controller.h:168
charArray paramkey
Definition: avrtypes.h:36
matrix::Matrix t(const std::vector< matrix::Matrix > &data, int time)
Definition: datafunc.h:102
std::list< std::pair< paramkey, paramval > > paramlist
Definition: configurable.h:89
bool isClosed
Definition: use_java_controller.h:177
double sensor
Definition: types.h:29
bool serverOK
Definition: use_java_controller.h:151
int client_controller
Definition: use_java_controller.h:155
random generator with 48bit integer arithmentic
Definition: randomgenerator.h:34
int client_internalParams
Definition: use_java_controller.h:156
paramlist config_param_list
Definition: use_java_controller.h:167
double * motor_values_alt
Definition: use_java_controller.h:183
bool can_send
Definition: use_java_controller.h:175
int number_controlled
Definition: use_java_controller.h:149
socklen_t client_internalParams_size
Definition: use_java_controller.h:159
socklen_t client_controller_size
Definition: use_java_controller.h:158
double paramval
Definition: avrtypes.h:37
virtual bool store(FILE *f) const
stores the object to the given file stream (ASCII preferred).
Definition: use_java_controller.h:139
bool server_guilogger_isClosed
Definition: use_java_controller.h:178
double motor
Definition: types.h:30
int number_motors
Definition: use_java_controller.h:148
virtual int getMotorNumber() const
Definition: use_java_controller.h:95
virtual int getSensorNumber() const
Definition: use_java_controller.h:90
class for robot control with sine and cosine
Definition: use_java_controller.h:62
static void addController()
Definition: use_java_controller.h:78
int ctoi(const char *)
bool server_controller_isClosed
Definition: use_java_controller.h:179
static int anzahl_Java_controller
Definition: use_java_controller.h:72
const char * name
Definition: use_java_controller.h:146
std::list< iparamkey > iparamkeylist
Definition: inspectable.h:59
std::list< iparamval > iparamvallist
Definition: inspectable.h:61
int anzahl_closed_Server
Definition: use_java_controller.h:181
iparamvallist internal_vallist_alt
Definition: use_java_controller.h:172
iparamvallist internal_vallist
Definition: use_java_controller.h:171
int number_sensors
Definition: use_java_controller.h:147
bool isFirst
Definition: use_java_controller.h:176
double atof(const char *)