zoo/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.11.4.4  2006/03/28 09:55:12  robot3
00024  *   -main: fixed snake explosion bug
00025  *   -odeconfig.h: inserted cameraspeed
00026  *   -camermanipulator.cpp: fixed setbyMatrix,
00027  *    updateFactor
00028  *
00029  *   Revision 1.11.4.3  2006/01/12 15:17:30  martius
00030  *   *** empty log message ***
00031  *
00032  *   Revision 1.11.4.2  2005/11/16 11:27:38  martius
00033  *   invertmotornstep has configuration
00034  *
00035  *   Revision 1.11.4.1  2005/11/15 12:30:22  martius
00036  *   new selforg structure and OdeAgent, OdeRobot ...
00037  *
00038  *   Revision 1.11  2005/11/14 13:02:39  martius
00039  *   new paramters
00040  *
00041  *   Revision 1.10  2005/11/09 13:41:25  martius
00042  *   GPL'ised
00043  *
00044  ***************************************************************************/
00045 #include "simulation.h"
00046 
00047 #include "odeagent.h"
00048 #include "playground.h"
00049 #include "passivesphere.h"
00050 
00051 #include <selforg/invertnchannelcontroller.h>
00052 #include <selforg/invertmotornstep.h>
00053 #include <selforg/invertmotorspace.h>
00054 #include <selforg/sinecontroller.h>
00055 #include <selforg/noisegenerator.h>
00056 #include <selforg/one2onewiring.h>
00057 
00058 #include "hurlingsnake.h"
00059 #include "schlangeforce.h"
00060 #include "nimm2.h"
00061 #include "nimm4.h"
00062 
00063 // fetch all the stuff of lpzrobots into scope
00064 using namespace lpzrobots;
00065 
00066 // plotoptions is a list of possible online output, 
00067 // if the list is empty no online gnuplot windows and no logging to file occurs.
00068 // The list is modified with commandline options, see main() at the bottom of this file
00069 list<PlotOption> plotoptions;
00070 
00071 class ThisSim : public Simulation {
00072 public:
00073 
00074   // starting function (executed once at the beginning of the simulation loop)
00075   void start(const OdeHandle& odeHandle, const OsgHandle& osgHandle, GlobalData& global) 
00076   {
00077     setCameraHomePos(Pos(5.2728, 7.2112, 3.31768), Pos(140.539, -13.1456, 0));
00078     // initialization
00079     // - set noise to 0.1
00080     // - register file chess.ppm as a texture called chessTexture (used for the wheels)
00081 
00082     global.odeConfig.setParam("noise",0.05);
00083     global.odeConfig.setParam("controlinterval",1);
00084     // initialization
00085     
00086     Playground* playground = new Playground(odeHandle, osgHandle, osg::Vec3(25, 0.2, 1.5));
00087     playground->setPosition(osg::Vec3(0,0,0)); // playground positionieren und generieren
00088     global.obstacles.push_back(playground);
00089     
00090     for(int i=0; i<5; i++){
00091       PassiveSphere* s = 
00092         new PassiveSphere(odeHandle, 
00093                           osgHandle.changeColor(Color(184 / 255.0, 233 / 255.0, 237 / 255.0)), 0.2);
00094       s->setPosition(Pos(i*0.5-2, i*0.5, 1.0)); 
00095       s->setTexture("Images/dusty.rgb");
00096       global.obstacles.push_back(s);    
00097     }
00098         
00099     OdeAgent* agent;
00100     AbstractWiring* wiring;
00101     OdeRobot* robot;
00102     AbstractController *controller;
00103     
00104     SchlangeForce* snake;
00105     SchlangeConf snakeConf = SchlangeForce::getDefaultConf();
00106     //******* S C H L A N G E  (Short) *********/
00107     snakeConf.segmNumber=4;
00108     snakeConf.jointLimit=M_PI/3;
00109     snakeConf.motorPower=0.1;
00110     snakeConf.frictionGround=0.1;
00111     snake = new SchlangeForce ( odeHandle, osgHandle.changeColor(Color(0,0.5,0.8)), snakeConf, "Schlange1");
00112     ((OdeRobot*) snake)->place(Pos(-5,-5,0)); 
00113     
00114     InvertMotorNStepConf invertnconf = InvertMotorNStep::getDefaultConf();
00115     invertnconf.cInit=2.0;
00116     controller = new InvertMotorNStep(invertnconf);    
00117     wiring = new One2OneWiring(new ColorUniformNoise(0.1));
00118     agent = new OdeAgent( plotoptions );
00119     agent->init(controller, snake, wiring);
00120     global.agents.push_back(agent);
00121     global.configs.push_back(controller);
00122     global.configs.push_back(snake);   
00123     snake->setParam("gamma",/*0.0000*/ 0.0);
00124   
00125 
00126     //******* S C H L A N G E  (Long)  *********/
00127     snakeConf = SchlangeForce::getDefaultConf();
00128     snakeConf.motorPower=0.1;
00129     snakeConf.segmNumber=8;
00130     snakeConf.jointLimit=M_PI/3;
00131     snakeConf.frictionGround=0.1;
00132     snake = new SchlangeForce ( odeHandle, osgHandle.changeColor(Color(0,0.5,0.8)), snakeConf, "Schlange2" );
00133     ((OdeRobot*) snake)->place(Pos(0,0,0)); 
00134     controller = new InvertMotorNStep(invertnconf);     
00135     wiring = new One2OneWiring(new ColorUniformNoise(0.1));
00136     agent = new OdeAgent( list<PlotOption>() );
00137     agent->init(controller, snake, wiring);
00138     global.agents.push_back(agent);
00139     global.configs.push_back(controller);
00140     global.configs.push_back(snake);   
00141     snake->setParam("gamma",/*0.0000*/ 0.0);
00142   
00143 
00144     //******* N I M M  2 *********/
00145     Nimm2Conf nimm2conf = Nimm2::getDefaultConf();
00146     nimm2conf.size = 1.6;
00147     for(int r=0; r < 3; r++) {    
00148       robot = new Nimm2(odeHandle, osgHandle, nimm2conf);
00149       robot->place(Pos ((r-1)*5,5,0));
00150       //    controller = new InvertMotorNStep(10);   
00151       controller = new InvertMotorSpace(15);   
00152       controller->setParam("s4avg",10);
00153       //    controller->setParam("factorB",0); // not needed here and it does some harm on the behaviour
00154       wiring = new One2OneWiring(new ColorUniformNoise(0.1));
00155       agent = new OdeAgent( list<PlotOption>() );
00156       agent->init(controller, robot, wiring);
00157       global.configs.push_back(controller);
00158       global.agents.push_back(agent);        
00159     }
00160     
00161     //******* N I M M  4 *********/
00162     for(int r=0; r < 1; r++) {
00163       robot = new Nimm4(odeHandle, osgHandle);
00164       robot->place(Pos((r-1)*5,-3,0));
00165       controller = new InvertMotorSpace(20);
00166       controller->setParam("s4avg",10); 
00167       controller->setParam("factorB",0); // not needed here and it does some harm on the behaviour
00168       wiring = new One2OneWiring(new ColorUniformNoise(0.1));
00169       agent = new OdeAgent( list<PlotOption>() );
00170       agent->init(controller, robot, wiring);
00171       global.agents.push_back(agent);        
00172     }
00173 
00174     //****** H U R L I N G **********/
00175     for(int r=0; r < 2; r++) {
00176       HurlingSnake* snake;
00177       Color c;    
00178       if (r==0) c=Color(0.8, 0.8, 0);
00179       if (r==1) c=Color(0,   0.8, 0);
00180       snake = new HurlingSnake(odeHandle, osgHandle.changeColor(c));
00181       ((OdeRobot*) snake)->place(Pos(r*5,-6,0.3));
00182       invertnconf.cInit=1.5;
00183       controller = new InvertMotorNStep(invertnconf);
00184       controller->setParam("steps", 2);
00185       controller->setParam("adaptrate", 0.001);
00186       controller->setParam("nomupdate", 0.001);
00187       controller->setParam("factorB", 0);
00188     
00189       // deriveconf = DerivativeWiring::getDefaultConf();
00190       //     deriveconf.blindMotorSets=0;
00191       //     deriveconf.useId = true;
00192       //     deriveconf.useFirstD = true;
00193       //     deriveconf.derivativeScale = 50;
00194       //     wiring = new DerivativeWiring(deriveconf, new ColorUniformNoise(0.1));
00195       wiring = new One2OneWiring(new ColorUniformNoise(0.05));
00196       agent = new OdeAgent( list<PlotOption>() );
00197       agent->init(controller, snake, wiring);
00198                                global.configs.push_back(controller);
00199                                global.agents.push_back(agent);     
00200     }
00201       showParams(global.configs);
00202   }
00203   
00204 };
00205 
00206 
00207 void printUsage(const char* progname){
00208   printf("Usage: %s [-g] [-l] [-r seed]\n\t-g\tuse guilogger\n\t-l\tuse guilogger with logfile\n\t-r seed\trandom number seed ", progname);
00209 }
00210 
00211 int main (int argc, char **argv)
00212 { 
00213   // start with online windows (default: start without plotting and logging)
00214   if(contains(argv, argc, "-g")) plotoptions.push_back(PlotOption(GuiLogger));
00215   
00216   // start with online windows and logging to file
00217   if(contains(argv, argc, "-l")) plotoptions.push_back(PlotOption(GuiLogger_File));
00218   
00219   // display help
00220   if(contains(argv, argc, "-h")) printUsage(argv[0]);
00221 
00222   ThisSim sim;
00223   return sim.run(argc, argv) ? 0 : 1;
00224 
00225 }
00226  

Generated on Tue Apr 4 19:05:03 2006 for Robotsystem from Robot Group Leipzig by  doxygen 1.4.5