// starting function (executed once at the beginning of the simulation loop) void start(const OdeHandle& odeHandle, const OsgHandle& osgHandle, GlobalData& global) { setCameraHomePos(Pos(5.2728, 7.2112, 3.31768), Pos(140.539, -13.1456, 0)); // initialization // - set noise to 0.1 // - register file chess.ppm as a texture called chessTexture (used for the wheels) global.odeConfig.noise=0.05; // global.odeConfig.setParam("gravity", 0); global.odeConfig.setParam("controlinterval", 5); global.odeConfig.setParam("simstepsize", 0.01); // use Playground as boundary: OctaPlayground* playground = new OctaPlayground(odeHandle, osgHandle, osg::Vec3(11, 0.2, 1), 12); playground->setPosition(osg::Vec3(0,0,0)); // playground positionieren und generieren global.obstacles.push_back(playground); /* for(int i=0; i<50; i++){ PassiveSphere* s = new PassiveSphere(odeHandle, osgHandle.changeColor(Color(0.0,1.0,0.0)), 0.5); s->setPosition(osg::Vec3(-4+(i/10),-4+(i%10),1)); global.obstacles.push_back(s); } */ OdeRobot* nimm2; // AbstractController* contrl; AbstractWiring* wiring; OdeAgent* agent; Nimm2Conf conf = Nimm2::getDefaultConf(); conf.speed=10; conf.force=1.0; //conf.bumper=true; //conf.cigarMode=true; //conf.irFront=true; //conf.irBack=true; wiring = new One2OneWiring(new ColorUniformNoise(0.1)); //controller = new InvertMotorNStep(); controller = new InvertNChannelController(10); // controller = new InvertMotorSpace(10); agent = new OdeAgent(global); nimm2 = new Nimm2(odeHandle, osgHandle, conf, "Nimm2Yellow"); nimm2->setColor(Color(1.0,1.0,0)); global.configs.push_back(controller); agent->init(controller, nimm2, wiring); /* controller->setParam("adaptrate", 0.000); controller->setParam("nomupdate", 0.0005); controller->setParam("epsA", 0.01); controller->setParam("epsC", 0.05); controller->setParam("rootE", 0); controller->setParam("steps", 2); controller->setParam("s4avg", 5); controller->setParam("s4del", 5); controller->setParam("factorB",0);*/ controller->setParam("eps",0.1); controller->setParam("factor_a",0.01); nimm2->place(Pos(2.5,1.26,0)); global.agents.push_back(agent); }
// starting function (executed once at the beginning of the simulation loop) void start(const OdeHandle& odeHandle, const OsgHandle& osgHandle, GlobalData& global) { setCameraHomePos(Pos(5.2728, 7.2112, 3.31768), Pos(140.539, -13.1456, 0)); // initialization // - set global noise sensor to 0.05 global.odeConfig.setParam("noise",0.05); // global.odeConfig.setParam("gravity", 0); // no gravity // 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 initial position of the playground: setPosition(osg::Vec3(double x, double y, double z)) // - push playground to the global list of obstacles (global list comes from simulation.cpp) OctaPlayground* playground = new OctaPlayground(odeHandle, osgHandle, osg::Vec3(10, 0.2, 1), 12); playground->setPosition(osg::Vec3(0,0,0)); // place and create playground global.obstacles.push_back(playground); // 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 // - add sphere to list of obstacles for(int i=0; i<8; i++){ PassiveSphere* s = new PassiveSphere(odeHandle, osgHandle.changeColor(Color(0.0,1.0,0.0)), 0.5); s->setPosition(osg::Vec3(5,0,i*3)); global.obstacles.push_back(s); } // Spherical Robot with axis (gyro) sensors: // - get default configuration for robot // - create pointer to spherical robot (with odeHandle, osgHandle and configuration) // - place robot (unfortunatelly there is a type cast necessary, which is not quite understandable) Sphererobot3MassesConf conf = Sphererobot3Masses::getDefaultConf(); conf.addSensor(std::make_shared<Sensor>(AxisOrientationSensor(AxisOrientationSensor::ZProjection))); conf.diameter=1.0; conf.pendularrange= 0.35; robot = new Sphererobot3Masses ( odeHandle, osgHandle.changeColor(Color(1.0,0.0,0)), conf, "Spherical", 0.2); (robot)->place ( Pos( 0 , 0 , 0.1 )); // Selforg - Controller (Note there are several: use Sos or Sox now) // create pointer to controller // set some parameters // push controller in global list of configurables controller = new InvertMotorSpace(10); controller->setParam("epsA",0.05); // model learning rate controller->setParam("epsC",0.2); // controller learning rate controller->setParam("rootE",3); // model and contoller learn with square rooted error global.configs.push_back ( controller ); // SineController (produces just sine waves) // controller = new SineController(); // controller->setParam("sinerate", 40); // controller->setParam("phaseshift", 0.0); // create pointer to one2onewiring which uses colored-noise One2OneWiring* wiring = new One2OneWiring ( new ColorUniformNoise() ); // 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 , robot , wiring ); if(track){ // the following line will enables a position tracking of the robot, which is written into a file // you can customize what is logged with the TrackRobotConf TrackRobotConf tc = TrackRobot::getDefaultConf(); tc.scene = "zaxis"; tc.displayTrace = true; agent->setTrackOptions(TrackRobot(tc)); } global.agents.push_back ( agent ); }