00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
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
00064 using namespace lpzrobots;
00065
00066
00067
00068
00069 list<PlotOption> plotoptions;
00070
00071 class ThisSim : public Simulation {
00072 public:
00073
00074
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
00079
00080
00081
00082 global.odeConfig.setParam("noise",0.05);
00083 global.odeConfig.setParam("controlinterval",1);
00084
00085
00086 Playground* playground = new Playground(odeHandle, osgHandle, osg::Vec3(25, 0.2, 1.5));
00087 playground->setPosition(osg::Vec3(0,0,0));
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
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.0);
00124
00125
00126
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.0);
00142
00143
00144
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
00151 controller = new InvertMotorSpace(15);
00152 controller->setParam("s4avg",10);
00153
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
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);
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
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
00190
00191
00192
00193
00194
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
00214 if(contains(argv, argc, "-g")) plotoptions.push_back(PlotOption(GuiLogger));
00215
00216
00217 if(contains(argv, argc, "-l")) plotoptions.push_back(PlotOption(GuiLogger_File));
00218
00219
00220 if(contains(argv, argc, "-h")) printUsage(argv[0]);
00221
00222 ThisSim sim;
00223 return sim.run(argc, argv) ? 0 : 1;
00224
00225 }
00226