iCub-main
SimulationRun.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 
21 #include "SimulationRun.h"
22 
23 #include <yarp/dev/DriverLinkCreator.h>
24 #include <yarp/os/LogStream.h>
25 
26 #include "SimulatorModule.h"
27 #include "iCubSimulationControl.h"
28 #include "iCubSimulationIMU.h"
29 #include "SimConfig.h"
30 
31 using namespace yarp::dev;
32 using namespace std;
33 
34 bool SimulationRun::run(SimulationBundle *bundle, int argc, char *argv[]) {
35  if (bundle==NULL) {
36  yError("Failed to allocate simulator\n");
37  return false;
38  }
39 
40  bundle->onBegin();
41 
42  SimConfig config;
43  string moduleName;
44  int verbosity;
45  config.configure(argc, argv, moduleName, verbosity);
46 
47  LogicalJoints *icub_joints = bundle->createJoints(config);
48  if (icub_joints==NULL) {
49  yError("Failed to allocate joints\n");
50  delete bundle;
51  return false;
52  }
53 
54  WorldManager *world = bundle->createWorldManager(config);
55  if (world==NULL) {
56  yError("Failed to allocate world manager\n");
57  delete bundle;
58  return false;
59  }
60 
61  PolyDriver icub_joints_dev;
62  icub_joints_dev.give(icub_joints,true);
63 
64  // Make sure all individual control boards route to single ode_joints driver
65  Drivers::factory().add(new DriverLinkCreator("robot_joints",icub_joints_dev));
66 
67  // Provide simulated controlboard driver
68  Drivers::factory().add(new DriverCreatorOf<iCubSimulationControl>("simulationcontrol",
69  "controlboard",
70  "iCubSimulationControl"));
71 
72  Drivers::factory().add(new DriverCreatorOf<iCubSimulationIMU>("simulationIMU",
73  "multipleanalogsensorsserver",
74  "iCubSimulationIMU"));
75 
76  SimulatorModule module(*world,config,bundle->createSimulation(config));
77 
78  if (module.open()) {
79  //this blocks until termination (through ctrl+c or a kill)
80  module.runModule();
81  }
82 
83  module.closeModule();
84 
85  bundle->onEnd();
86 
87  delete world;
88  world = NULL;
89 
90  delete bundle;
91  bundle = NULL;
92 
93  return true;
94 }
Header for the automatic configuration of the iCub Simulator.
Route control for the robots controlled joints to their implementation.
Definition: LogicalJoints.h:31
std::string configure(int argc, char *argv[], std::string &moduleName, int &verbosity)
Definition: SimConfig.cpp:93
virtual LogicalJoints * createJoints(RobotConfig &config)=0
virtual WorldManager * createWorldManager(RobotConfig &config)=0
virtual bool onEnd()=0
virtual Simulation * createSimulation(RobotConfig &config)=0
virtual bool onBegin()=0
bool run(SimulationBundle *bundle, int argc, char *argv[])
This is the header file for the yarp interface of the iCubSimulation.
int verbosity
Definition: main.cpp:21