template_sphererobot/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.15.4.4  2006/02/20 10:50:20  martius
00024  *   pause, random, windowsize, Ctrl-keys
00025  *
00026  *   Revision 1.15.4.3  2006/01/12 15:17:39  martius
00027  *   *** empty log message ***
00028  *
00029  *   Revision 1.15.4.2  2006/01/10 20:33:50  martius
00030  *   moved to osg
00031  *
00032  *   Revision 1.15.4.1  2005/11/15 12:30:17  martius
00033  *   new selforg structure and OdeAgent, OdeRobot ...
00034  *
00035  *   Revision 1.15  2005/11/09 14:54:46  fhesse
00036  *   nchannelcontroller used
00037  *
00038  *   Revision 1.14  2005/11/09 13:41:25  martius
00039  *   GPL'ised
00040  *
00041  ***************************************************************************/
00042 
00043 #include "simulation.h"
00044 
00045 #include "odeagent.h"
00046 #include "octaplayground.h"
00047 #include "passivesphere.h"
00048 
00049 #include <selforg/invertnchannelcontroller.h>
00050 #include <selforg/sinecontroller.h>
00051 #include <selforg/noisegenerator.h>
00052 #include <selforg/one2onewiring.h>
00053 
00054 #include "sphererobot.h"
00055 #include "sphererobot3masses.h"
00056 
00057 // fetch all the stuff of lpzrobots into scope
00058 using namespace lpzrobots;
00059 
00060 // plotoptions is a list of possible online output, 
00061 // if the list is empty no online gnuplot windows and no logging to file occurs.
00062 // The list is modified with commandline options, see main() at the bottom of this file
00063 list<PlotOption> plotoptions;
00064 
00065 AbstractController *controller;
00066 Sphererobot3Masses* sphere1;
00067 
00068 class ThisSim : public Simulation {
00069 public:
00070 
00071   // starting function (executed once at the beginning of the simulation loop)
00072   void start(const OdeHandle& odeHandle, const OsgHandle& osgHandle, GlobalData& global) 
00073   {
00074     setCameraHomePos(Pos(5.2728, 7.2112, 3.31768), Pos(140.539, -13.1456, 0));
00075     // initialization
00076     // - set noise to 0.1
00077     // - register file chess.ppm as a texture called chessTexture (used for the wheels)
00078     global.odeConfig.noise=0.1;
00079     //  global.odeConfig.setParam("gravity", 0);
00080     //  int chessTexture = dsRegisterTexture("chess.ppm");
00081 
00082     // use Playground as boundary:
00083     // - create pointer to playground (odeHandle contains things like world and space the 
00084     //   playground should be created in; odeHandle is generated in simulation.cpp)
00085     // - setting geometry for each wall of playground: 
00086     //   setGeometry(double length, double width, double        height)
00087     // - setting initial position of the playground: setPosition(double x, double y, double z)
00088     // - push playground in the global list of obstacles(globla list comes from simulation.cpp)
00089     OctaPlayground* playground = new OctaPlayground(odeHandle, osgHandle, osg::Vec3(10, 0.2, 1), 12);
00090     playground->setPosition(osg::Vec3(0,0,0)); // playground positionieren und generieren
00091     global.obstacles.push_back(playground);
00092 
00093     for(int i=0; i<5; i++){
00094       PassiveSphere* s = new PassiveSphere(odeHandle, osgHandle.changeColor(Color(0.0,1.0,0.0)), 0.5);
00095       s->setPosition(osg::Vec3(5,0,i*3)); 
00096       global.obstacles.push_back(s);    
00097     }
00098 
00099     
00100     //****************
00101     Sphererobot3MassesConf conf = Sphererobot3Masses::getDefaultConf();  
00102     sphere1 = new Sphererobot3Masses ( odeHandle, osgHandle.changeColor(Color(1.0,0.0,0)), 
00103                                        conf, "Sphere1", 0.2); 
00104     //    SphererobotConf conf = Sphererobot::getDefaultConf();  
00105     //    sphere1 = new Sphererobot ( odeHandle, osgHandle, conf, "Sphere1");
00106     
00107     ((OdeRobot*)sphere1)->place ( Pos( 0 , 0 , 0.1 ));
00108     //controller = new InvertNChannelController(10);  
00109     controller = new SineController();  
00110     controller->setParam("sinerate", 40);  
00111     controller->setParam("phaseshift", 0.0);
00112     
00113     One2OneWiring* wiring = new One2OneWiring ( new ColorUniformNoise() );
00114     OdeAgent* agent = new OdeAgent ( plotoptions );
00115     agent->init ( controller , sphere1 , wiring );
00116     // agent->setTrackOptions(TrackRobot(true, false, false, "ZSens_Ring10_11", 50));
00117     global.agents.push_back ( agent );
00118     global.configs.push_back ( controller );
00119       
00120     showParams(global.configs);
00121   }
00122 
00123 //   //Funktion die eingegebene Befehle/kommandos verarbeitet
00124 //   void command (const OdeHandle&, GlobalData& globalData, int key)
00125 //   {
00126 //     //dsPrint ( "Eingabe erfolgt %d (`%c')\n" , cmd , cmd );
00127 //     switch ( (char) key )
00128 //       {
00129 //       case 'y' : dBodyAddForce ( sphere1->object[Sphererobot::Base]->getBody() , 10 ,0 , 0 ); break;
00130 //       case 'Y' : dBodyAddForce ( sphere1->object[Sphererobot::Base]->getBody() , -10 , 0 , 0 ); break;
00131 //       case 'x' : dBodyAddTorque ( sphere1->object[Sphererobot::Base]->getBody() , 0 , 0 , 3 ); break;
00132 //       case 'X' : dBodyAddTorque ( sphere1->object[Sphererobot::Base]->getBody() , 0 , 0 , -3 ); break;
00133 //       case 'S' : controller->setParam("sineRate", controller->getParam("sineRate")*1.2); 
00134 //      printf("sineRate : %g\n", controller->getParam("sineRate"));
00135 //       break;
00136 //       case 's' : controller->setParam("sineRate", controller->getParam("sineRate")/1.2); 
00137 //      printf("sineRate : %g\n", controller->getParam("sineRate"));
00138 //      break;
00139 //       }
00140 //   }
00141   
00142 
00143 };
00144 
00145 // print command line options
00146 void printUsage(const char* progname){
00147   printf("Usage: %s [-g] [-l]\n\t-g\tuse guilogger\n\t-l\tuse guilogger with logfile\n", progname);
00148 }
00149 
00150 int main (int argc, char **argv)
00151 { 
00152   // start with online windows (default: start without plotting and logging)
00153   if(contains(argv, argc, "-g")) plotoptions.push_back(PlotOption(GuiLogger));
00154   
00155   // start with online windows and logging to file
00156   if(contains(argv, argc, "-l")) plotoptions.push_back(PlotOption(GuiLogger_File));
00157   
00158   // display help
00159   if(contains(argv, argc, "-h")) printUsage(argv[0]);
00160 
00161   ThisSim sim;
00162   return sim.run(argc, argv) ? 0 : 1;
00163 
00164 }
00165  
00166  

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