iCub-main
main.cpp
Go to the documentation of this file.
1 // -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
2 
3 /*
4 * Copyright (C) 2010 RobotCub Consortium, European Commission FP6 Project IST-004370
5 * Author: Vadim Tikhanoff, Paul Fitzpatrick
6 * email: vadim.tikhanoff@iit.it, paulfitz@alum.mit.edu
7 * website: www.robotcub.org
8 * Permission is granted to copy, distribute, and/or modify this program
9 * under the terms of the GNU General Public License, version 2 or any
10 * later version published by the Free Software Foundation.
11 *
12 * A copy of the license can be found at
13 * http://www.robotcub.org/icub/license/gpl.txt
14 *
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
18 * Public License for more details
19 */
20 
156 //\file main.cpp
157 //\brief This file is responsible for the initialisation the module and yarp ports. It deals with incoming world commands such as getting information or creating new objects
158 
159 #include <yarp/os/Network.h>
160 #include <yarp/os/Property.h>
161 #include <yarp/os/Thread.h>
162 #include <yarp/dev/Drivers.h>
163 #include <yarp/os/LogStream.h>
164 
165 #include "SimulationRun.h"
166 #ifdef ICUB_SIM_ENABLE_ODESDL
167 #include "OdeSdlSimulationBundle.h"
168 #endif
169 #ifdef ICUB_SIM_ENABLE_FAKE
170 #include "FakeSimulationBundle.h"
171 #endif
172 
173 // Needed on OSX, to hijack main()
174 #ifdef ICUB_SIM_ENABLE_ODESDL
175 #include "SDL.h"
176 #endif
177 
178 class MainThread : public yarp::os::Thread {
179  public:
181  int argc;
182  char **argv;
183  bool result;
184 
185  void run() {
187  result = main.run(bundle,argc,argv);
188  }
189  };
190 
191 
192 int main(int argc, char** argv) {
193  //yarp::os::Thread::setDefaultStackSize(3145728);
194  yarp::os::Network yarp;
195  if (!yarp.checkNetwork())
196  {
197  yError ("could not initialize YARP network (is the nameserver running?)\n");
198  return 1;
199  }
200 
201  yarp::os::Property options;
202  options.fromCommand(argc,argv);
203 
204  // the "bundle" controls the implementation used for the simulation
205  // (as opposed to the simulation interface). The default is the
206  // standard ODE/SDL implementation. There is a "fake" do-nothing
207  // simulation for test purposes that does nothing other than create
208  // the standard ports (pass --fake to start this simulation).
209  SimulationBundle *bundle = NULL;
210 
211  if (options.check("fake")) {
212 #ifdef ICUB_SIM_ENABLE_FAKE
213  bundle = new FakeSimulationBundle;
214 #endif
215  } else {
216 #ifdef ICUB_SIM_ENABLE_ODESDL
217  bundle = new OdeSdlSimulationBundle;
218 #endif
219  }
220  //This was not used - replacing with int verbosity at wrapper/RobotConfig.h and SimConfig.h
221  /*if (options.check("verbose"))
222  {
223  bundle->verbose = true;
224  yDebug("Starting the simulator with verbose flag on\n");
225  }*/
226  if (bundle==NULL) {
227  yError("Failed to allocate simulator\n");
228  return 1;
229  }
230 
231  //SimulationRun main;
232  //if (!main.run(bundle,argc,argv)) return 1;
233  MainThread thread;
234  thread.bundle = bundle;
235  thread.argc = argc;
236  thread.argv = argv;
237 #ifdef _WIN32
238  //thread.setOptions(3145728);
239 #endif
240  thread.start();
241  thread.join();
242  return thread.result?0:1;
243 }
MainThread
Definition: main.cpp:178
SimulationRun
Definition: SimulationRun.h:27
MainThread::result
bool result
Definition: main.cpp:183
main
int main(int argc, char *argv[])
Definition: main.cpp:31
SimulationRun.h
MainThread::argc
int argc
Definition: main.cpp:181
OdeSdlSimulationBundle.h
SimulationBundle
Definition: SimulationBundle.h:29
FakeSimulationBundle
Definition: FakeSimulationBundle.h:25
MainThread::run
void run()
Definition: main.cpp:185
MainThread::argv
char ** argv
Definition: main.cpp:182
MainThread::bundle
SimulationBundle * bundle
Definition: main.cpp:180
OdeSdlSimulationBundle
Definition: OdeSdlSimulationBundle.h:26
yarp
Copyright (C) 2008 RobotCub Consortium.
Definition: DebugInterfaces.h:51
scripting.argc
argc
Definition: scripting.py:184
FakeSimulationBundle.h