Robotsystem from Robot Group Leipzig: main.cpp Source File

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Directories
- Examples

- File List
- File Members

# template_onerobot/main.cpp

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: main.cpp,v $
    00023  *   Revision 1.14.4.12  2006/03/31 12:14:49  fhesse
    00024  *   orange color for nimm robot
    00025  *
    00026  *   Revision 1.14.4.11  2006/03/31 11:27:53  fhesse
    00027  *   documentation updated
    00028  *   one sphere removed (todo: fix prob;em with sphere placing)
    00029  *
    00030  *   Revision 1.14.4.10  2006/01/12 15:17:46  martius
    00031  *   *** empty log message ***
    00032  *
    00033  *   Revision 1.14.4.9  2005/12/29 15:55:33  martius
    00034  *   end is obsolete
    00035  *
    00036  *   Revision 1.14.4.8  2005/12/29 15:47:12  martius
    00037  *   changed to real Sim class
    00038  *
    00039  *   Revision 1.14.4.7  2005/12/14 15:37:25  martius
    00040  *   *** empty log message ***
    00041  *
    00042  *   Revision 1.14.4.6  2005/12/13 18:12:09  martius
    00043  *   switched to nimm2
    00044  *
    00045  *   Revision 1.14.4.5  2005/12/11 23:35:08  martius
    00046  *   *** empty log message ***
    00047  *
    00048  *   Revision 1.14.4.4  2005/12/09 16:53:17  martius
    00049  *   camera is working now
    00050  *
    00051  *   Revision 1.14.4.3  2005/12/06 10:13:25  martius
    00052  *   openscenegraph integration started
    00053  *
    00054  *   Revision 1.14.4.2  2005/11/24 16:19:12  fhesse
    00055  *   include corrected
    00056  *
    00057  *   Revision 1.14.4.1  2005/11/15 12:30:07  martius
    00058  *   new selforg structure and OdeAgent, OdeRobot ...
    00059  *
    00060  *   Revision 1.14  2005/11/09 13:41:25  martius
    00061  *   GPL'ised
    00062  *
    00063  ***************************************************************************/
    00064 #include <stdio.h>
    00065
    00066 // include ode library
    00067 #include <ode/ode.h>
    00068
    00069 // include noisegenerator (used for adding noise to sensorvalues)
    00070 #include <selforg/noisegenerator.h>
    00071
    00072 // include simulation environment stuff
    00073 #include "simulation.h"
    00074
    00075 // include agent (class for holding a robot, a controller and a wiring)
    00076 #include "odeagent.h"
    00077
    00078 // used wiring
    00079 #include <selforg/one2onewiring.h>
    00080
    00081 // used robot
    00082 #include "nimm2.h"
    00083 #include "nimm4.h"
    00084
    00085 // used arena
    00086 #include "playground.h"
    00087 // used passive spheres
    00088 #include "passivesphere.h"
    00089
    00090 // used controller
    00091 //#include <selforg/invertnchannelcontroller.h>
    00092 #include <selforg/invertmotorspace.h>
    00093
    00094 // fetch all the stuff of lpzrobots into scope
    00095 using namespace lpzrobots;
    00096
    00097 // plotoptions is a list of possible online output,
    00098 // if the list is empty no online gnuplot windows and no logging to file occurs.
    00099 // The list is modified with commandline options, see main() at the bottom of this file
    00100 list<PlotOption> plotoptions;
    00101
    00102 class ThisSim : public Simulation {
    00103 public:
    00104
    00105   // starting function (executed once at the beginning of the simulation loop)
    00106   void start(const OdeHandle& odeHandle, const OsgHandle& osgHandle, GlobalData& global)
    00107   {
    00108     setCameraHomePos(Pos(5.2728, 7.2112, 3.31768), Pos(140.539, -13.1456, 0));
    00109     // initialization
    00110     // - set noise to 0.1
    00111     // - register file chess.ppm as a texture called chessTexture (used for the wheels)
    00112     global.odeConfig.noise=0.1;
    00113     //  global.odeConfig.setParam("gravity", 0);
    00114     //  int chessTexture = dsRegisterTexture("chess.ppm");
    00115
    00116     // use Playground as boundary:
    00117     // - create pointer to playground (odeHandle contains things like world and space the
    00118     //   playground should be created in; odeHandle is generated in simulation.cpp)
    00119     // - setting geometry for each wall of playground:
    00120     //   setGeometry(double length, double width, double        height)
    00121     // - setting initial position of the playground: setPosition(double x, double y, double z)
    00122     // - push playground in the global list of obstacles(globla list comes from simulation.cpp)
    00123     Playground* playground = new Playground(odeHandle, osgHandle, osg::Vec3(30, 0.2, 0.5));
    00124     playground->setPosition(osg::Vec3(0,0,0)); // playground positionieren und generieren
    00125     global.obstacles.push_back(playground);
    00126
    00127     // add passive spheres as obstacles
    00128     // - create pointer to sphere (with odehandle, osghandle and
    00129     //   optional parameters radius and mass,where the latter is not used here) )
    00130     // - set Pose(Position) of sphere
    00131     // - set a texture for the sphere
    00132     // - add sphere to list of obstacles
    00133     for (int i=0; i<= 1/*2*/; i+=2){
    00134       PassiveSphere* s1 = new PassiveSphere(odeHandle, osgHandle, 0.5);
    00135       s1->setPosition(osg::Vec3(-4.5+i*4.5,0,0));
    00136       s1->setTexture("Images/dusty.rgb");
    00137       global.obstacles.push_back(s1);
    00138     }
    00139
    00140     // set color for nimm robot
    00141     OsgHandle osgHandle_orange = osgHandle.changeColor(Color(2, 156/255.0, 0));
    00142
    00143     // use Nimm2 vehicle as robot:
    00144     // - get default configuration for nimm2
    00145     // - activate bumpers, cigar mode and infrared front sensors of the nimm2 robot
    00146     // - create pointer to nimm2 (with odeHandle, osg Handle and configuration)
    00147     // - place robot
    00148      Nimm2Conf c = Nimm2::getDefaultConf();
    00149      c.bumper  = true;
    00150      c.cigarMode  = true;
    00151      c.irFront = true;
    00152      OdeRobot* vehicle = new Nimm2(odeHandle, osgHandle_orange, c);
    00153      vehicle->place(Pos(2,0,0));
    00154
    00155     // use Nimm4 vehicle as robot:
    00156     // - create pointer to nimm4 (with odeHandle and osg Handle and possible other settings, see nimm4.h)
    00157     // - place robot
    00158     //OdeRobot* vehicle = new Nimm4(odeHandle, osgHandle);
    00159     //vehicle->place(Pos(0,2,0));
    00160
    00161     // create pointer to controller
    00162     // push controller in global list of configurables
    00163     //  AbstractController *controller = new InvertNChannelController(10);
    00164     AbstractController *controller = new InvertMotorSpace(10);
    00165     global.configs.push_back(controller);
    00166
    00167     // create pointer to one2onewiring
    00168     One2OneWiring* wiring = new One2OneWiring(new ColorUniformNoise(0.1));
    00169
    00170     // create pointer to agent
    00171     // initialize pointer with controller, robot and wiring
    00172     // push agent in globel list of agents
    00173     OdeAgent* agent = new OdeAgent(plotoptions);
    00174     agent->init(controller, vehicle, wiring);
    00175     global.agents.push_back(agent);
    00176
    00177     showParams(global.configs);
    00178   }
    00179
    00180
    00181 };
    00182
    00183 // print command line options
    00184 void printUsage(const char* progname){
    00185   printf("Usage: %s [-g] [-l]\n\t-g\tuse guilogger\n\t-l\tuse guilogger with logfile\n", progname);
    00186 }
    00187
    00188 int main (int argc, char **argv)
    00189 {
    00190   // start with online windows (default: start without plotting and logging)
    00191   if(contains(argv, argc, "-g")) plotoptions.push_back(PlotOption(GuiLogger));
    00192
    00193   // start with online windows and logging to file
    00194   if(contains(argv, argc, "-l")) plotoptions.push_back(PlotOption(GuiLogger_File));
    00195
    00196   // display help
    00197   if(contains(argv, argc, "-h")) printUsage(argv[0]);
    00198
    00199   ThisSim sim;
    00200   return sim.run(argc, argv) ? 0 : 1;
    00201
    00202 }
    00203