template_schlange/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.16.4.4  2006/02/08 16:16:11  martius
00024  *   parameter tuning
00025  *
00026  *   Revision 1.16.4.3  2006/02/01 18:35:16  martius
00027  *   schlangeservo2
00028  *
00029  *   Revision 1.16.4.2  2006/01/05 11:41:01  fhesse
00030  *   moved to osg
00031  *                                                    *
00032  *                                                                         *
00033  ***************************************************************************/
00034 
00035 
00036 #include <selforg/noisegenerator.h>
00037 
00038 #include "simulation.h"
00039 #include "odeagent.h"
00040 #include <selforg/one2onewiring.h>
00041 #include <selforg/derivativewiring.h>
00042 #include "playground.h"
00043 #include "passivesphere.h"
00044 
00045 #include <selforg/invertnchannelcontroller.h>
00046 #include <selforg/invertmotorspace.h>
00047 #include <selforg/invertmotornstep.h>
00048 #include <selforg/sinecontroller.h>
00049 
00050 #include "schlangeservo.h"
00051 #include "schlangeservo2.h"
00052 #include "schlangeforce.h"
00053 #include "schlangevelocity.h"
00054 
00055 list<PlotOption> plotoptions;
00056 
00057 using namespace lpzrobots;
00058 
00059 class ThisSim : public Simulation {
00060 public:
00061         
00062 
00063   /// start() is called at the start and should create all the object (obstacles, agents...).
00064   virtual void start(const OdeHandle& odeHandle, const OsgHandle& osgHandle, GlobalData& global){
00065     setCameraHomePos(Pos(-10.7854, -7.41751, 5.92078),  Pos(-50.6311, -5.00218, 0));
00066 
00067     // conf for schlange1 and schlange2
00068     SchlangeConf conf = Schlange::getDefaultConf();
00069     conf.motorPower   = 0.1;
00070     conf.jointLimit   = conf.jointLimit*1.5;
00071     //conf.segmDia      = 0.2;
00072     conf.segmNumber   = 7; 
00073 
00074 
00075     // SchlangeServo
00076     SchlangeServo2* schlange1 = 
00077       new SchlangeServo2 ( odeHandle, osgHandle.changeColor(Color(0.8, 0.3, 0.5)),
00078                            conf, "Servo");
00079     ((OdeRobot*)schlange1)->place(Pos(2,2,5)); 
00080     InvertMotorNStepConf cc = InvertMotorNStep::getDefaultConf();
00081     cc.cInit=2;
00082     AbstractController *controller1 = new InvertMotorNStep(cc);  
00083     controller1->setParam("adaptrate",0);
00084     controller1->setParam("epsC",0.001);
00085     controller1->setParam("epsA",0.001);
00086     controller1->setParam("rootE",1);
00087     controller1->setParam("s4avg",10);
00088     controller1->setParam("steps",2);
00089     //    AbstractController *controller1 = new SineController();  
00090     AbstractWiring* wiring1 = new One2OneWiring(new ColorUniformNoise(0.1));
00091     OdeAgent* agent1 = new OdeAgent(plotoptions);
00092     agent1->init(controller1, schlange1, wiring1);
00093     global.agents.push_back(agent1);
00094     global.configs.push_back(controller1);
00095     global.configs.push_back(schlange1);
00096 
00097 
00098     //SchlangeForce
00099 //     conf.motorPower   = 0.2;
00100 //     conf.jointLimit   = conf.jointLimit*1.5;
00101 //     //conf.segmDia      = 0.2;
00102 //     conf.segmNumber   = 5; 
00103 //      SchlangeForce* schlange2 = 
00104 //        new SchlangeForce ( odeHandle, osgHandle.changeColor(Color(0.8, 0.3, 0.5)),
00105 //                        conf, "Force");
00106 //      ((OdeRobot*)schlange2)->place(Pos(3,3,5)); 
00107 //      InvertMotorNStepConf cc2 = InvertMotorNStep::getDefaultConf();
00108 //      cc2.cInit=0.01;
00109 //      AbstractController *controller2 = new InvertMotorNStep(cc2);
00110 //      //     AbstractController *controller2 = new SineController();
00111 //      AbstractWiring* wiring2 = new One2OneWiring(new ColorUniformNoise(0.1));
00112 //      OdeAgent* agent2 = new OdeAgent(plotoptions);
00113 //      agent2->init(controller2, schlange2, wiring2);
00114 //      global.agents.push_back(agent2);
00115 //      global.configs.push_back(controller2);
00116 //      global.configs.push_back(schlange2);
00117 //      controller2->setParam("adaptrate",0);
00118 //      controller2->setParam("epsC",0.005);
00119 //      controller2->setParam("epsA",0.001);
00120 //      controller2->setParam("rootE",1);
00121 //      controller2->setParam("s4avg",10);
00122 //      controller2->setParam("steps",2);
00123 
00124 //      controller2->setParam("phaseshift", 0.3);
00125 
00126     //SchlangeVelocity
00127 //      SchlangeConf conf3 = SchlangeVelocity::getDefaultConf();
00128 //      conf3.jointLimit=conf3.jointLimit*3;
00129 //      conf3.segmDia    = 0.2;
00130 //      conf3.segmNumber = 2;    
00131 //      SchlangeVelocity* schlange3 = 
00132 //        new SchlangeVelocity ( odeHandle, osgHandle.changeColor(Color(0.8, 0.3, 0.5)),
00133 //                           conf3, "Velocity");
00134 //      ((OdeRobot*)schlange3)->place(Pos(2,2,0)); 
00135 //      AbstractController *controller3 = new SineController();  
00136 //      AbstractWiring* wiring3 = new One2OneWiring(new ColorUniformNoise(0.1));
00137 //      OdeAgent* agent3 = new OdeAgent(plotoptions);
00138 //      agent3->init(controller3, schlange3, wiring3);
00139 //      global.agents.push_back(agent3);
00140 //      global.configs.push_back(controller3);
00141 //      global.configs.push_back(schlange3);
00142   
00143  
00144      global.odeConfig.setParam("controlinterval",1);
00145      //     global.odeConfig.setParam("gravity", -9.81); 
00146      global.odeConfig.setParam("gravity", 0); 
00147      global.odeConfig.setParam("noise", 0.05); 
00148 
00149     showParams(global.configs);
00150   }
00151 
00152 };
00153 
00154 void printUsage(const char* progname){
00155   printf("Usage: %s [-g] [-f]\n\t-g\tuse guilogger\n\t-f\tuse guilogger with logfile", progname);
00156 }
00157 
00158 int main (int argc, char **argv)
00159 {  
00160   if(contains(argv, argc, "-g")) plotoptions.push_back(PlotOption(GuiLogger, Controller, 10));
00161   if(contains(argv, argc, "-f")) plotoptions.push_back(PlotOption(GuiLogger_File, Controller, 10));
00162   if(contains(argv, argc, "-h")) printUsage(argv[0]);
00163 
00164   ThisSim sim;
00165   return sim.run(argc, argv) ? 0 : 1;
00166 }
00167 
00168 
00169  
00170   

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