// starting function (executed once at the beginning of the simulation loop) void start(const OdeHandle& odeHandle, const OsgHandle& osgHandle, GlobalData& global) { int num_barrels=1; int num_barrels_test=0; sensor=0; setCameraMode(Follow); bool normalplayground=false; // setCameraHomePos(Pos(-0.497163, 11.6358, 3.67419), Pos(-179.213, -11.6718, 0)); setCameraHomePos(Pos(-2.60384, 13.1299, 2.64348), Pos(-179.063, -9.7594, 0)); // initialization global.odeConfig.setParam("noise",0.1); // global.odeConfig.setParam("gravity",-10); global.odeConfig.setParam("controlinterval",4); global.odeConfig.setParam("realtimefactor",5); // add a new parameter to be configured on the console global.odeConfig.addParameterDef("friction", &friction, 0.1, "rolling friction coefficient"); if(normalplayground){ Playground* playground = new Playground(odeHandle, osgHandle,osg::Vec3(20, 0.01, 0.01 ), 1); playground->setGroundColor(Color(255/255.0,200/255.0,0/255.0)); playground->setGroundTexture("Images/really_white.rgb"); playground->setColor(Color(255/255.0,200/255.0,21/255.0, 0.1)); playground->setPosition(osg::Vec3(0,0,0.05)); global.obstacles.push_back(playground); } /* * * * BARRELS * * * */ for(int i=0; i< num_barrels; i++){ //**************** Sphererobot3MassesConf conf = Barrel2Masses::getDefaultConf(); conf.pendularrange = 0.3;//0.15; conf.motorpowerfactor = 200;//150; conf.motorsensor=false; conf.addSensor(new AxisOrientationSensor(AxisOrientationSensor::ZProjection, Sensor::X | Sensor::Y)); conf.spheremass = 1; conf.addSensor(new SpeedSensor(10, SpeedSensor::Translational, Sensor::X )); conf.irAxis1=false; conf.irAxis2=false; conf.irAxis3=false; conf.axesShift = 0; // conf.axesShift = conf.diameter/2 - conf.pendularrange/2; sphere1 = new Barrel2Masses ( odeHandle, osgHandle.changeColor(Color(0.0,0.0,1.0)), conf, "Barrel1", 0.4); sphere1->place (osg::Matrix::rotate(M_PI/2, 1,0,0)*osg::Matrix::translate(0,0,0.2)); // InvertMotorNStepConf cc = InvertMotorNStep::getDefaultConf(); // cc.cInit=1; // // cc.useSD=true; // controller = new InvertMotorNStep(cc); // controller->setParam("steps", 2); // controller->setParam("adaptrate", 0.0); // controller->setParam("nomupdate", 0.00); // controller->setParam("epsC", 0.03); // controller->setParam("epsA", 0.05); // controller->setParam("rootE", 0); // controller->setParam("logaE", 0); //controller = new PiMax(); //controller->setParam("epsC", 0.001); // controller = new Sox(); // controller->setParam("epsC", 0.5); controller = new ROSController("Test"); AbstractWiring* wiring = new SelectiveOne2OneWiring(new ColorUniformNoise(), new select_from_to(0,1)); // OdeAgent* agent = new OdeAgent ( PlotOption(File, Robot, 1) ); OdeAgent* agent = new OdeAgent (); agent->init ( controller , sphere1 , wiring ); // agent->setTrackOptions(TrackRobot(true, false, false, "ZSens_Ring10_11", 50)); global.agents.push_back ( agent ); global.configs.push_back ( controller ); } /* * * * TEST BARRELS * * * */ for(int i=0; i< num_barrels_test; i++){ global.odeConfig.setParam("realtimefactor",1); //**************** Sphererobot3MassesConf conf = Sphererobot3Masses::getDefaultConf(); conf.pendularrange = 0.15; conf.motorsensor=true; conf.irAxis1=false; conf.irAxis2=false; conf.irAxis3=false; conf.spheremass = 1; sphere1 = new Barrel2Masses ( odeHandle, osgHandle.changeColor(Color(0.0,0.0,1.0)), conf, "Barrel1", 0.4); sphere1->place ( osg::Matrix::rotate(M_PI/2, 1,0,0)); controller = new SineController(); controller->setParam("sinerate", 15); controller->setParam("phaseshift", 0.45); // DerivativeWiringConf dc = DerivativeWiring::getDefaultConf(); // dc.useId=true; // dc.useFirstD=false; // AbstractWiring* wiring = new DerivativeWiring(dc,new ColorUniformNoise()); AbstractWiring* wiring = new One2OneWiring(new ColorUniformNoise()); OdeAgent* agent = new OdeAgent (); agent->init ( controller , sphere1 , wiring ); // agent->setTrackOptions(TrackRobot(true, false, false, "ZSens_Ring10_11", 50)); global.agents.push_back ( agent ); global.configs.push_back ( controller ); } }
// starting function (executed once at the beginning of the simulation loop) void start(const OdeHandle& odeHandle, const OsgHandle& osgHandle, GlobalData& global) { // first: position(x,y,z) second: view(alpha,beta,gamma) // gamma=0; // alpha == horizontal angle // beta == vertical angle setCameraHomePos(Pos(-0.18, 20.36, 13.63), Pos(-179.93, -34.37, 0)); // initialization // - set noise to 0.1 global.odeConfig.noise=0.1; global.odeConfig.setParam("controlinterval", 10); // use Playground as boundary: // - create pointer to playground (odeHandle contains things like world and space the // playground should be created in; odeHandle is generated in simulation.cpp) // - setting geometry for each wall of playground: // setGeometry(double length, double width, double height) // - setting initial position of the playground: setPosition(double x, double y, double z) // - push playground in the global list of obstacles(globla list comes from simulation.cpp) bool labyrint=false; bool squarecorridor=false; bool normalplayground=true; bool boxes = true; if(normalplayground){ // Playground* playground = new Playground(odeHandle, osgHandle, osg::Vec3(12, 0.2, 0.5)); Playground* playground = new Playground(odeHandle, osgHandle, osg::Vec3(17, 0.2, 1.0)); playground->setPosition(osg::Vec3(0,0,0.05)); // playground positionieren und generieren // register playground in obstacles list global.obstacles.push_back(playground); } if(squarecorridor){ Playground* playground = new Playground(odeHandle, osgHandle,osg::Vec3(15, 0.2, 1.2 ), 1); playground->setGroundColor(Color(255/255.0,200/255.0,0/255.0)); playground->setGroundTexture("Images/really_white.rgb"); playground->setColor(Color(255/255.0,200/255.0,21/255.0, 0.1)); playground->setPosition(osg::Vec3(0,0,0.1)); playground->setTexture(""); global.obstacles.push_back(playground); // // inner playground playground = new Playground(odeHandle, osgHandle,osg::Vec3(10, 0.2, 1.2), 1, false); playground->setColor(Color(255/255.0,200/255.0,0/255.0, 0.1)); playground->setPosition(osg::Vec3(0,0,0.1)); playground->setTexture(""); global.obstacles.push_back(playground); } if(labyrint){ double radius=7.5; Playground* playground = new Playground(odeHandle, osgHandle,osg::Vec3(radius*2+1, 0.2, 5 ), 1); playground->setGroundColor(Color(255/255.0,200/255.0,0/255.0)); playground->setGroundTexture("Images/really_white.rgb"); playground->setColor(Color(255/255.0,200/255.0,21/255.0, 0.1)); playground->setPosition(osg::Vec3(0,0,0.1)); playground->setTexture(""); global.obstacles.push_back(playground); int obstanz=30; OsgHandle rotOsgHandle = osgHandle.changeColor(Color(255/255.0, 47/255.0,0/255.0)); OsgHandle gruenOsgHandle = osgHandle.changeColor(Color(0,1,0)); for(int i=0; i<obstanz; i++){ PassiveBox* s = new PassiveBox(odeHandle, (i%2)==0 ? rotOsgHandle : gruenOsgHandle, osg::Vec3(random_minusone_to_one(0)+1.2, random_minusone_to_one(0)+1.2 ,1),5); s->setPose(osg::Matrix::translate(radius/(obstanz+10)*(i+10),0,i) * osg::Matrix::rotate(2*M_PI/obstanz*i,0,0,1)); global.obstacles.push_back(s); } } if(boxes) { for (int i=0; i<= 2; i+=2){ PassiveBox* s1 = new PassiveBox(odeHandle, osgHandle, osg::Vec3(1,1,1), 0.4); s1->setTexture("Images/dusty.rgb"); s1->setPosition(osg::Vec3(-5+i*5,0,0)); global.obstacles.push_back(s1); Joint* fixator; Primitive* p = s1->getMainPrimitive(); fixator = new FixedJoint(p, global.environment); fixator->init(odeHandle, osgHandle); s1 = new PassiveBox(odeHandle, osgHandle, osg::Vec3(1,1,1), 0.4); s1->setTexture("Images/dusty.rgb"); s1->setPosition(osg::Vec3(0,-5+i*5,0)); global.obstacles.push_back(s1); p = s1->getMainPrimitive(); fixator = new FixedJoint(p, global.environment); fixator->init(odeHandle, osgHandle); s1 = new PassiveBox(odeHandle, osgHandle, osg::Vec3(1,1,1), 0.4); s1->setTexture("Images/dusty.rgb"); s1->setPosition(osg::Vec3(-3.5+i*3.5,-3.5+i*3.5,0)); global.obstacles.push_back(s1); p = s1->getMainPrimitive(); fixator = new FixedJoint(p, global.environment); fixator->init(odeHandle, osgHandle); s1 = new PassiveBox(odeHandle, osgHandle, osg::Vec3(1,1,1), 0.4); s1->setTexture("Images/dusty.rgb"); s1->setPosition(osg::Vec3(-3.5+i*3.5,3.5-i*3.5,0)); global.obstacles.push_back(s1); p = s1->getMainPrimitive(); fixator = new FixedJoint(p, global.environment); fixator->init(odeHandle, osgHandle); } } // add passive spheres as obstacles // - create pointer to sphere (with odehandle, osghandle and // optional parameters radius and mass,where the latter is not used here) ) // - set Pose(Position) of sphere // - set a texture for the sphere // - add sphere to list of obstacles for (int i=0; i < 0/*2*/; i++){ PassiveSphere* s1 = new PassiveSphere(odeHandle, osgHandle, 0.5); s1->setPosition(osg::Vec3(-4.5+i*4.5,0,0)); s1->setTexture("Images/dusty.rgb"); global.obstacles.push_back(s1); } // use Nimm2 vehicle as robot: // - get default configuration for nimm2 // - activate bumpers, cigar mode and infrared front sensors of the nimm2 robot // - create pointer to nimm2 (with odeHandle, osg Handle and configuration) // - place robot Nimm2Conf c = Nimm2::getDefaultConf(); c.bumper = false;//true; c.cigarMode = false;//true; c.irFront = true; c.irBack = true; //c.irSide = true; c.irRange = 1.2;//2;//3; c.force=2; c.speed=8; OdeRobot* vehicle = new Nimm2(odeHandle, osgHandle, c, "Nimm2"); vehicle->place(Pos(0,0,0.5)); // vehicle->place(Pos(0,6.25,0)); // use Nimm4 vehicle as robot: // - create pointer to nimm4 (with odeHandle and osg Handle and possible other settings, see nimm4.h) // - place robot //OdeRobot* vehicle = new Nimm4(odeHandle, osgHandle, "Nimm4"); //vehicle->place(Pos(0,1,0)); // create pointer to controller // push controller in global list of configurables AbstractController *controller = new LayeredController(10); controller->setParam("eps",0.1); controller->setParam("factor_a",0.1); controller->setParam("eps_hebb",0.03); global.configs.push_back(controller); // create pointer to one2onewiring One2OneWiring* wiring = new One2OneWiring(new ColorUniformNoise(0.1)); // create pointer to agent // initialize pointer with controller, robot and wiring // push agent in globel list of agents OdeAgent* agent = new OdeAgent(global); agent->init(controller, vehicle, wiring); agent->setTrackOptions(TrackRobot(true, false, false, false, "hebbh" ,1)); global.agents.push_back(agent); }