Robotsystem from Robot Group Leipzig: main.cpp Source File

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

- File List
- File Members

# template_schlangeforce/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.18.4.1  2005/11/15 12:30:11  martius
    00024  *   new selforg structure and OdeAgent, OdeRobot ...
    00025  *
    00026  *   Revision 1.18  2005/11/09 14:27:45  fhesse
    00027  *   schlangeforce active, schlangeservo commented out
    00028  *
    00029  *   Revision 1.17  2005/11/09 13:41:25  martius
    00030  *   GPL'ised
    00031  *
    00032  ***************************************************************************/
    00033 #include <stdio.h>
    00034 #include <drawstuff/drawstuff.h>
    00035 #include <ode/ode.h>
    00036
    00037 #include <selforg/noisegenerator.h>
    00038
    00039 #include "simulation.h"
    00040 #include "odeagent.h"
    00041 #include <selforg/one2onewiring.h>
    00042 #include <selforg/derivativewiring.h>
    00043 #include "playground.h"
    00044 #include "sphere.h"
    00045
    00046 #include <selforg/invertnchannelcontroller.h>
    00047 #include <selforg/sinecontroller.h>
    00048
    00049 #include "schlangeservo.h"
    00050 #include "schlangeforce.h"
    00051 #include "nimm2.h"
    00052
    00053 ConfigList configs;
    00054 list<PlotOption> plotoptions;
    00055
    00056 //Startfunktion die am Anfang der Simulationsschleife, einmal ausgefuehrt wird
    00057 void start(const OdeHandle& odeHandle, GlobalData& global)
    00058 {
    00059   dsPrint ( "\nWelcome to the virtual ODE - robot simulator of the Robot Group Leipzig\n" );
    00060   dsPrint ( "------------------------------------------------------------------------\n" );
    00061   dsPrint ( "Press Ctrl-C for an basic commandline interface.\n\n" );
    00062
    00063   global.odeConfig.setParam("gravity",-9.0); // do not use 'global.odeConfig.gravity=0.0;',
    00064                                             // because world is already initialized and
    00065                                             // dWorldSetGravity will not be called when
    00066                                             // you only set the value
    00067
    00068   //Anfangskameraposition und Punkt auf den die Kamera blickt
    00069   //float KameraXYZ[3]= {0.276f,7.12f,1.78f};
    00070   //float KameraViewXYZ[3] = {-88.0f,-5.5f,0.0000f};
    00071   float KameraXYZ[3]= {5.0f, 7.0f, 7.0f};
    00072   float KameraViewXYZ[3] = {-85.0f,-12.0f,0.0000f};
    00073
    00074   dsSetViewpoint ( KameraXYZ , KameraViewXYZ );
    00075   dsSetSphereQuality (2); //Qualitaet in der Sphaeren gezeichnet werden
    00076
    00077   // initialization
    00078
    00079
    00080   Playground* playground = new Playground(odeHandle);
    00081   playground->setGeometry(15.0, 0.2, 1.5);
    00082   playground->setPosition(0,0,0); // playground positionieren und generieren
    00083   global.obstacles.push_back(playground);
    00084
    00085   Sphere* sphere;
    00086   for (int i=-3; i<3; i++){
    00087     sphere = new Sphere(odeHandle);
    00088     sphere->setPosition(i*0.5,i*0.5,1.0); //positionieren und generieren
    00089     global.obstacles.push_back(sphere);
    00090   }
    00091
    00092
    00093
    00094
    00095   SchlangenConf con = SchlangeForce::getDefaultConf();
    00096   SchlangeForce*schlange3 = new SchlangeForce(0, odeHandle, con);
    00097   Position p3(1,1,0);
    00098   Color col3 (1,1,0);
    00099   schlange3->place(p3,&col3);
    00100   AbstractController *controller3 = new InvertNChannelController(10,true);
    00101
    00102   One2OneWiring* wiring3 = new One2OneWiring(new ColorUniformNoise(0.1));
    00103   OdeAgent* agent3 = new OdeAgent(NoPlot/*GuiLogger*/);
    00104   agent3->init(controller3, schlange3, wiring3);
    00105   global.agents.push_back(agent3);
    00106   configs.push_back(controller3);
    00107   configs.push_back(schlange3);
    00108
    00109
    00110
    00111   /* comment this in to add a SchlangeServo to the simulation*/
    00112   /*
    00113   SchlangeServoConf conf = SchlangeServo::getDefaultConf();
    00114   conf.servoPower=10;
    00115   conf.jointLimit=M_PI/2;
    00116   SchlangeServo* schlange1 =
    00117     new SchlangeServo ( odeHandle, conf, "S1");
    00118   Color col(0,0.5,0.8);
    00119   schlange1->place(Position(2,0,6),&col);
    00120
    00121
    00122   //schlange1->fixInSky();
    00123   AbstractController *controller = new SineController();
    00124
    00125   // AbstractWiring* wiring = new One2OneWiring(new ColorUniformNoise(0.1));
    00126   DerivativeWiringConf c = DerivativeWiring::getDefaultConf();
    00127   c.useId=true;
    00128   c.useFirstD=true;
    00129   // c.useSecondD=true;
    00130   c.derivativeScale=10;
    00131   AbstractWiring* wiring = new DerivativeWiring(c, new ColorUniformNoise(0.1));
    00132   OdeAgent* agent = new OdeAgent(plotoptions);
    00133   agent->init(controller, schlange1, wiring);
    00134   global.agents.push_back(agent);
    00135   configs.push_back(controller);
    00136   configs.push_back(schlange1);
    00137
    00138
    00139   global.odeConfig.setParam("noise",0.1);
    00140   global.odeConfig.setParam("simstepsize",0.005);
    00141   global.odeConfig.setParam("drawinterval",1);
    00142   global.odeConfig.setParam("controlinterval",1);
    00143
    00144    controller->setParam("epsC",0.001);
    00145    controller->setParam("epsA",0.01);
    00146
    00147   schlange1->setParam("gamma", 0.0);
    00148   schlange1->setParam("frictionGround",0.1);
    00149   schlange1->setParam("factorForce", 3);
    00150   schlange1->setParam("factorSensors", 5);
    00151   */
    00152
    00153
    00154
    00155   showParams(configs);
    00156 }
    00157
    00158 void end(GlobalData& global){
    00159   for(ObstacleList::iterator i=global.obstacles.begin(); i != global.obstacles.end(); i++){
    00160     delete (*i);
    00161   }
    00162   global.obstacles.clear();
    00163   for(OdeAgentList::iterator i=global.agents.begin(); i != global.agents.end(); i++){
    00164     delete (*i)->getRobot();
    00165     delete (*i)->getController();
    00166     delete (*i);
    00167   }
    00168   global.agents.clear();
    00169 }
    00170
    00171
    00172 // this function is called if the user pressed Ctrl-C
    00173 void config(GlobalData& global){
    00174   changeParams(configs);
    00175 }
    00176
    00177 void printUsage(const char* progname){
    00178   printf("Usage: %s [-g] [-l]\n\t-g\tuse guilogger\n\t-l\tuse guilogger with logfile", progname);
    00179 }
    00180
    00181 int main (int argc, char **argv)
    00182 {
    00183   if(contains(argv, argc, "-g")) plotoptions.push_back(PlotOption(GuiLogger));
    00184   if(contains(argv, argc, "-l")) plotoptions.push_back(PlotOption(GuiLogger_File));
    00185   if(contains(argv, argc, "-h")) printUsage(argv[0]);
    00186
    00187   // initialise the simulation and provide the start, end, and config-function
    00188   simulation_init(&start, &end, &config);
    00189   // start the simulation (returns, if the user closes the simulation)
    00190   simulation_start(argc, argv);
    00191   simulation_close();  // tidy up.
    00192   return 0;
    00193 }
    00194