示例#1
0
文件: main.cpp 项目: amr1985/playful
 virtual AbstractController* operator()( int index) { 
   AbstractController* c;
   c= new Sos(0.01);    
   c->setParam("epsC",eps);
   c->setParam("epsA",.1);
   return c; 
 }
示例#2
0
文件: main.cpp 项目: humm/playful
 virtual AbstractController* operator()( int index) {
     AbstractController* c;
     c= new Sox(cInit);
     c->setName("Sox " + itos(index));
     c->setParam("epsC",epsC);
     c->setParam("epsA",epsA);
     if(epsC==0) c->setParam("creativity",0);
     else  c->setParam("creativity",0.1);
     return c;
 }
示例#3
0
TEST_F(testsIbpGenHandler, BasicIbpGenHandlerPutGetMemCheck) {
    std::string cfgFile = testsTools::InitConfig(2, WithHotData);
    AbstractController* ctrl = NULL;
    StatusCode st = Controller::create(cfgFile, ctrl);
    ASSERT_TRUE(st.ok());
    ASSERT_TRUE(NULL != ctrl);
    EXPECT_EQ(cfgFile, ctrl->getConfigFile());
    EXPECT_EQ(TESTUUID, ctrl->getUuid());
    std::string cfgFileName = ctrl->getConfigFile();

    ctrl->start();

    StatusCode stPut = ctrl->put("key", "data");
    EXPECT_TRUE(stPut.ok());

    std::string buffer(80, 'A');
    DataChunk fetched(buffer);
    size_t count;
    StatusCode stGet = ctrl->fetch("key", std::move(fetched), count);
    EXPECT_TRUE(stGet.ok());
    EXPECT_TRUE(fetched == "data");

    ctrl->stop();

    ctrl->destroy();
    delete ctrl;
}
示例#4
0
  // 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
    global.odeConfig.setParam("noise",0.05);
    global.odeConfig.setParam("realtimefactor",1);
    global.odeConfig.setParam("drawinterval", 50);


    OdeRobot* robot = new ShortCircuit(odeHandle, osgHandle, channels, channels);
//     InvertMotorNStepConf cc = InvertMotorNStep::getDefaultConf();
//     cc.cInit=1;
//     cc.cNonDiag=0.5;
//     cc.someInternalParams=false;
//     AbstractController *controller = new InvertMotorNStep(cc);
    AbstractController *controller = new InvertNChannelController(10);

    //  AbstractController *controller = new InvertNChannelController_NoBias(40);
    controller->setParam("eps",0.2);
    //  controller->setParam("factor_a",0.00);
    //  controller->setParam("eps",0.01);
     //AbstractController *controller = new InvertMotorSpace(10,1);
    //    AbstractController *controller = new SineController();
    //controller->setParam("nomupdate",0.001);
    controller->setParam("sinerate",100.0);
    controller->setParam("phaseshift",0.6);
    controller->setParam("adaptrate",0.000);
    controller->setParam("epsA",0.00);
    controller->setParam("epsC",0.06);
    controller->setParam("factorB",0.0);
    controller->setParam("noiseB",0.0);
    controller->setParam("steps",1);
    //  AbstractController *controller = new InvertNChannelController(10);
    //AbstractController *controller = new SineController();

    OdeAgent* agent = new OdeAgent(global);

    // sineNoise = new SineWhiteNoise(omega,2,M_PI/2);
    // One2OneWiring* wiring = new One2OneWiring(sineNoise, true);
    One2OneWiring* wiring = new One2OneWiring(new WhiteUniformNoise(), true);
    //    One2OneWiring* wiring = new One2OneWiring(new ColorUniformNoise(0.05), true);

    //AbstractWiring* wiring = new SelectiveOne2OneWiring(sineNoise, &select_firsthalf);
    // DerivativeWiringConf c = DerivativeWiring::getDefaultConf();
//     c.useId=true;
//     c.useFirstD=false;
//     c.derivativeScale=20;
//     c.blindMotorSets=0;
//     AbstractWiring* wiring = new DerivativeWiring(c, new ColorUniformNoise(0.05));
    agent->init(controller, robot, wiring);
    global.agents.push_back(agent);

    global.configs.push_back(controller);


  }
示例#5
0
文件: main.cpp 项目: amr1985/playful
  // 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));
    setCameraMode(Follow);
    global.odeConfig.setParam("noise",0.1);
    global.odeConfig.setParam("controlinterval",4);
    global.odeConfig.setParam("realtimefactor",4);
    
    //  global.odeConfig.setParam("gravity", 0); // no gravity

    for(int i=0; i<0; 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 orientation sensors:
    Sphererobot3MassesConf conf = Sphererobot3Masses::getDefaultConf();  
    conf.addSensor(new AxisOrientationSensor(AxisOrientationSensor::ZProjection));
    // regular behaviour
    conf.motorsensor=false;
    conf.diameter=1.0;
    conf.pendularrange= 0.25;
    conf.motorpowerfactor = 150;     
    
//     conf.diameter=1.0;
//     conf.pendularrange= 0.35;
    sphere1 = new Sphererobot3Masses ( odeHandle, osgHandle.changeColor(Color(1.0,0.0,0)), 
				       conf, "Sphere1", 0.2);     
    ((OdeRobot*)sphere1)->place ( Pos( 0 , 0 , 0.1 ));
    global.configs.push_back ( sphere1 );
    
    controller = new Sox(.8,true);
    controller->setParam("epsA",0.3); // model learning rate
    controller->setParam("epsC",1); // controller learning rate
    controller->setParam("causeaware",0.4); 
    controller->setParam("pseudo",2); 
    global.configs.push_back ( controller );

    One2OneWiring* wiring = new One2OneWiring ( new ColorUniformNoise() );
    OdeAgent* agent = new OdeAgent ( global );
    agent->init ( controller , sphere1 , wiring );
    if(track) agent->setTrackOptions(TrackRobot(true, true, true, false, "zaxis", 20)); 
    global.agents.push_back ( agent );

  }
示例#6
0
 // add own key handling stuff here, just insert some case values
 virtual bool command(const OdeHandle&, const OsgHandle&, GlobalData& globalData, int key, bool down)
 {
   if (down) { // only when key is pressed, not when released
     switch ( (char) key )
       {
       case 'y' : dBodyAddForce ( sphere1->getMainPrimitive()->getBody() , 30 ,0 , 0 ); break;
       case 'Y' : dBodyAddForce ( sphere1->getMainPrimitive()->getBody() , -30 , 0 , 0 ); break;
       case 'x' : dBodyAddTorque ( sphere1->getMainPrimitive()->getBody() , 0 , 10 , 0 ); break;
       case 'X' : dBodyAddTorque ( sphere1->getMainPrimitive()->getBody() , 0 , -10 , 0 ); break;
       case 'S' : controller->setParam("sinerate", controller->getParam("sinerate")*1.2);
         printf("sinerate : %g\n", controller->getParam("sinerate"));
         break;
       case 's' : controller->setParam("sinerate", controller->getParam("sinerate")/1.2);
         printf("sinerate : %g\n", controller->getParam("sinerate"));
         break;
       default:
         return false;
         break;
       }
   }
   return false;
 }
示例#7
0
文件: main.cpp 项目: Sosi/lpzrobots
  // 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(new 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 );
  }
示例#8
0
文件: main.cpp 项目: humm/playful
  // starting function (executed once at the beginning of the simulation loop)
  void start(const OdeHandle& odeHandle, const OsgHandle& osgHandle, GlobalData& global)
  {
    setCameraHomePos(Pos(-1.64766, 4.48823, 1.71381),  Pos(-158.908, -10.5863, 0));

    // initialization
    // - set noise to 0.0
    // - register file chess.ppm as a texture called chessTexture (used for the wheels)
    global.odeConfig.setParam("controlinterval",1);
    global.odeConfig.setParam("noise",0.01);
    global.odeConfig.setParam("realtimefactor",1);
    global.odeConfig.setParam("gravity", -6);
    //    global.odeConfig.setParam("cameraspeed", 250);
    //  int chessTexture = dsRegisterTexture("chess.ppm");

    bool useDerivativeWiring=false;

    // environemnt (type is set in constructor)
    env.numSpheres  = 0;
    env.numBoxes    = 0;
    env.numCapsules = 0;
    env.numSeeSaws  = 0;
    env.roughness   = 1.0;

    // use Playground as boundary:
    if(barriers){
      env.widthground = 4;
      env.distance    = 6;
      env.numgrounds  = 5;
      env.height      = 0.1;
      env.heightincrease =0.1;
    }else {
      env.widthground = 32;
      env.height      = 1.0;
    }

    env.create(odeHandle, osgHandle, global);
    global.configs.push_back(&env);


    // Boxpile* boxpile = new Boxpile(odeHandle, osgHandle, Pos(10,10,0.2),
    //                                100,0, Pos(0.3,0.3,0.05), Pos(0.3,0.3,0.05)
    //                                );
    // boxpile->setColor("wall");
    // boxpile->setPose(ROTM(M_PI/5.0,0,0,1)*TRANSM(0, 0 ,0.2));
    // global.obstacles.push_back(boxpile);



    for (int i=0; i< 1/*2*/; i++){ //Several dogs

      //    VierBeinerConf conf = VierBeiner::getDefaultConf();
    VierBeinerConf conf = VierBeiner::getDefaultConfVelServos();

    conf.dampingFactor = .0;
    conf.powerFactor = 1.3;
    if(air) conf.powerFactor = 0.3;
    if (hippo) conf.powerFactor = 1.5;

    conf.hipJointLimit = M_PI/3.0;
    if ( barriers)  conf.hipJointLimit = M_PI/2.5;

    conf.kneeJointLimit = M_PI/3;
    conf.legNumber = 4; /* for the dog's sake use only even numbers */
    conf.useBigBox = false;
    if(hippo) conf.useBigBox = false;
    conf.drawstupidface=true;
    conf.hippo = hippo;
    //    conf.onlyMainParameters = false; // all parameters

    OdeHandle doghandle = odeHandle;
    doghandle.substance.toRubber(10);
    VierBeiner* dog = new VierBeiner(doghandle, osgHandle,conf, "Dog");
    std::list<Sensor*> sensors;
    sensors.push_back(new SpeedSensor(1,SpeedSensor::TranslationalRel));
    AddSensors2RobotAdapter* robot =
      new AddSensors2RobotAdapter(odeHandle,osgHandle,dog, sensors);

    //dog->place(osg::Matrix::translate(0,0,0.15));
    robot->place(osg::Matrix::translate(0,0,.5 + 4*i));

    if(air || barriers){
      Primitive* trunk = dog->getMainPrimitive();
      fixator = new FixedJoint(trunk, global.environment);
      fixator->init(odeHandle, osgHandle);
    }

    // create pointer to one2onewiring
    //AbstractWiring* wiring = new One2OneWiring(new ColorUniformNoise(0.1));

    double booster = 0.05;
    if(air) booster=0;

    AbstractWiring* wiring;
    if(!useDerivativeWiring){
      wiring = new ForceBoostWiring(new ColorUniformNoise(0.1), booster);
    }else{
      ////////////////
      AbstractWiring* fbw = new ForceBoostWiring(new NoNoise(), booster);
      DerivativeWiringConf dc = DerivativeWiring::getDefaultConf();
      dc.useId=true;
      dc.useFirstD=true;
      // dc.derivativeScale = 1.0;
      AbstractWiring* drw = new DerivativeWiring(dc, new ColorUniformNoise(0.1));
      if(!useDerivativeWiring){ wiring = new WiringSequence(fbw, drw); // TODO booster bei derivative wiring ???
     }
    }

    AbstractController *controller = new Sox(.7, false);
    //AbstractController *controller = new SineController();
    controller->setParam("Logarithmic", 1);
    controller->setParam("epsC",0.05);
    if ( hippo) controller->setParam("epsC",0.1);
    controller->setParam("epsA",0.01);
    controller->setParam("damping",0.0001);

    controller->setParam("period",300);
    controller->setParam("phaseshift",0);

    AbstractController* cont= new GroupController(controller,3); // 3 context sensor

    OdeAgent* agent = new OdeAgent(global);
    agent->init(cont, robot, wiring);
    if(!hippo){
    // add an operator to keep robot from falling over
      agent->addOperator(new LimitOrientationOperator(Axis(0,0,1), Axis(0,0,1),
                                                      M_PI*0.35, 10));
    }

    //agent->setTrackOptions(TrackRobot(true,true,false,true,"bodyheight",20)); // position and speed tracking every 20 steps
    global.agents.push_back(agent);
    global.configs.push_back(agent);

    }// Several dogs end

  }
示例#9
0
  // starting function (executed once at the beginning of the simulation loop)
  void start(const OdeHandle& odeHandle, const OsgHandle& osgHandle, GlobalData& global)
  {
    setCameraHomePos(Pos(6.5701, 17.3534, 11.7749),  Pos(159.449, -30.0839, 0));
    // initialization
    // - set noise to 0.1
    // - register file chess.ppm as a texture called chessTexture (used for the wheels)
    global.odeConfig.noise=0.1;
    //  global.odeConfig.setParam("gravity", 0);
    //  int chessTexture = dsRegisterTexture("chess.ppm");

    // 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)
    OctaPlayground* playground =
      new OctaPlayground(odeHandle, osgHandle,
                         osg::Vec3(8.0f, 0.2, 6.0f),
                         12, // number of corners
                         true); // if ground is created (only create one)
    // true); // if ground is created (only create one)
    // when you not set this texture, a brown wooden texture
    // is used, the setColor would overlay with the wooden texture
    playground->setColor(Color(1.0,0.5,0.0,0.2));
    // when you not set this texture, a brown wooden texture
    // is used, the setColor would overlay with the wooden texture
    playground->setTexture("Images/really_white.rgb");
    playground->setPosition(osg::Vec3(0,0,0)); // playground positionieren und generieren
    global.obstacles.push_back(playground);



    OctaPlayground* playground2 =
      new OctaPlayground(odeHandle, osgHandle,
                         osg::Vec3(1.0f, 0.2, 2.5f),
                         12, // number of corners
                         false); // if ground is created (only create one)
    playground2->setColor(Color(1.0,0.5,0.0,0.1));
    // when you not set this texture, a brown wooden texture
    // is used, the setColor would overlay with the wooden texture
    playground2->setTexture("Images/really_white.rgb");
    playground2->setPosition(osg::Vec3(0.0,0.0,0)); // playground positionieren und generieren
    global.obstacles.push_back(playground2);


    // Creation of passive boxes
    // add passive spheres, boxes and capsules as obstacles
    // - create pointer to sphere, box or capsule (with odehandle, osghandle and
    //   optional parameters radius and mass,where the latter is not used here) )
    // - set Pose(Position) of sphere, box or capsule
    // - set a texture for the sphere, box or capsule
    // - add sphere, box or capsule to list of obstacles
    // note that the dependent header file has to be include above
    // ("passivesphere.h", "passivebox.h" and/or "passivecapsule.h"

    int n=10;
    int m=3;
    for (int j=0;j<m;j++) {
      for(int i=0; i<n; i++){
        PassiveSphere* s =
          new PassiveSphere(odeHandle,
                          osgHandle.changeColor(Color(184 / 255.0, 233 / 255.0, 237 / 255.0)),
                          /*Diameter=*/.2+i*0.03,/*Mass=*/.5);
        s->setPosition(Pos(sin(2*M_PI*(((float)i)/((float)n)+0.05f))*(3.0f+2.0f*j),
                           cos(2*M_PI*(((float)i)/((float)n)+0.05f))*(3.0f+2.0f*j),
                           0.8f+2.0f*j));
        s->setTexture("Images/dusty.rgb");
        global.obstacles.push_back(s);
      }

    }
    n=8;
    m=3;
    for (int j=0;j<m;j++) {
      for(int i=0; i<n; i++){
        PassiveBox* b =
          new  PassiveBox(odeHandle,
                          osgHandle.changeColor(Color(184 / 255.0, 233 / 255.0, 237 / 255.0)),
                          osg::Vec3(0.4+i*0.1, 0.8-i*0.03, 0.4), 0.2+i*0.1);
        if (i==1)
          b->setTexture("Images/light_chess.rgb");
        else
          b->setTexture("Images/dusty.rgb");
        b->setPosition(Pos(sin(2*M_PI*(((float)i)/((float)n))+0.1f)*(3.0f+2.0f*j),
                           cos(2*M_PI*(((float)i)/((float)n))+0.1f)*(3.0f+2.0f*j),
                           3.0f+2.0f*j));
        global.obstacles.push_back(b);
      }

    }
    n=15;
    m=3;
    for (int j=0;j<m;j++) {
      for(int i=0; i<n; i++){
        PassiveCapsule* b =
          new  PassiveCapsule(odeHandle,
                          osgHandle.changeColor(Color(184 / 255.0, 233 / 255.0, 237 / 255.0)),
                          0.2f+0.03*i,1.0f-i*0.04);
        b->setPosition(Pos(sin(2*M_PI*(((float)i)/((float)n)))*(3.0f+2.0f*j),
                           cos(2*M_PI*(((float)i)/((float)n)))*(3.0f+2.0f*j),
                           5.0f+2.0f*j));
        b->setTexture("Images/dusty.rgb");
        global.obstacles.push_back(b);
      }

    }


 // Creation of spherical robots:
    for(int i=0; i<0; i++){
      OdeRobot* sphere1;
      Sphererobot3MassesConf conf = Sphererobot3Masses::getDefaultConf();
      conf.diameter=2;
      conf.irAxis1=true;
      conf.irAxis2=true;
      conf.irAxis3=true;
       sphere1 = new Sphererobot3Masses ( odeHandle, osgHandle.changeColor(Color(0.0+.1*i,0.0,1.0)),
                                               conf, "Sphere1", 0.4);
       // sphere1 = new ForcedSphere(odeHandle, osgHandle, "FSphere");

       // sphere1->place ( Pos(-3,1/2,3+2*i));
      sphere1->place ( Pos(0,0,7+2*i));
      AbstractController* controller = new InvertMotorNStep();
      controller->setParam("steps", 2);
      controller->setParam("adaptrate", 0.005);
      controller->setParam("nomupdate", 0.01);
      controller->setParam("epsC", 0.01);
      controller->setParam("epsA", 0.005);
      controller->setParam("rootE", 3);

      DerivativeWiringConf c = DerivativeWiring::getDefaultConf();
      c.useId = true;
      c.useFirstD = true;
      DerivativeWiring* wiring = new DerivativeWiring ( c , new ColorUniformNoise() );


       // One2OneWiring* wiring = new One2OneWiring ( new ColorUniformNoise() );
      OdeAgent* agent = new OdeAgent ( plotoptions );
      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 );
    }
 //creation of snakes
      for(int i=0; i<1; i++){
      //****************/
      SchlangeConf conf = Schlange::getDefaultConf();
      conf.motorPower=.3;
      conf.segmNumber =10-i/2;
      conf.segmDia    = 0.15;   //  diameter of a snake element

      // conf.jointLimit=conf.jointLimit*3;
      conf.jointLimit=conf.jointLimit*2.0;
      conf.frictionJoint=0.002;
      SchlangeServo2* schlange1 =
        //new SchlangeServo2 ( odeHandle, osgHandle.changeColor(Color(0.8, 0.3, 0.5)),
        new SchlangeServo2 ( odeHandle, osgHandle.changeColor(Color(1.0, 1.0, 1.0)),
                             conf, "S1");
      //Positionieren und rotieren
      schlange1->place(osg::Matrix::rotate(M_PI/2, 0, 1, 0)*
                       osg::Matrix::translate(2*i,i,conf.segmNumber/2+2));
      if (i==0) {
        //      schlange1->setTexture("Images/whitemetal_tiefgruen.rgb");
        //      schlange1->setHeadTexture("Images/whitemetal_tiefrot.rgb");
      } else {
        //        schlange1->setTexture("Images/whitemetal_tiefrot.rgb");
        //        schlange1->setHeadTexture("Images/whitemetal_tiefgruen.rgb");
      }


      //AbstractController *controller = new InvertNChannelController(100/*,true*/);
      //  AbstractController *controller = new InvertMotorSpace(100/*,true*/);
      AbstractController *controller = new InvertMotorNStep();
      // AbstractController *controller = new invertmotornstep();
      //AbstractController *controller = new SineController();
      //    AbstractController *controller = new InvertMotorNStep();

      //     AbstractController *controller = new SineController();

      //    AbstractWiring* wiring = new One2OneWiring(new ColorUniformNoise(0.05)); //Only this line for one2Onewiring


      //   AbstractWiring* wiring = new DerivativeWiring(c, new ColorUniformNoise(0.1));
      DerivativeWiringConf c = DerivativeWiring::getDefaultConf();
      c.useId = true;
      c.useFirstD = true;
      //   c.derivativeScale=10;
      DerivativeWiring* wiring = new DerivativeWiring ( c , new ColorUniformNoise() );



      OdeAgent* agent = new OdeAgent(global);
      agent->init(controller, schlange1, wiring);
      global.agents.push_back(agent);
      global.configs.push_back(controller);
      global.configs.push_back(schlange1);


      global.odeConfig.setParam("controlinterval",2);
      global.odeConfig.setParam("gravity", -2);

      controller->setParam("steps",2);
      controller->setParam("epsC",0.01);
      controller->setParam("epsA",0.01);
      controller->setParam("adaptrate",0.005);
          controller->setParam("logaE",3);

      // controller->setParam("desens",0.0);
         controller->setParam("s4delay",3.0);
      //   controller->setParam("s4avg",1.0);

         controller->setParam("factorB",0.0);
      //   controller->setParam("zetaupdate",0.1);

      }//creation of snakes End


  }
示例#10
0
    // starting function (executed once at the beginning of the simulation loop)
    void start(const OdeHandle& odeHandle, const OsgHandle& osgHandle, GlobalData& global)
    {
        setCameraHomePos(Pos(-6.32561, 5.12705, 3.17278),  Pos(-130.771, -17.7744, 0));


        global.odeConfig.setParam("noise", 0.05);
        global.odeConfig.setParam("controlinterval", 2);
        global.odeConfig.setParam("cameraspeed", 250);
        global.odeConfig.setParam("gravity", -6);
        setParam("UseQMPThread", false);

        // use Playground as boundary:
        AbstractGround* playground =
            new Playground(odeHandle, osgHandle, osg::Vec3(8, 0.2, 1), 1);
        //     // playground->setColor(Color(0,0,0,0.8));
        playground->setGroundColor(Color(2,2,2,1));
        playground->setPosition(osg::Vec3(0,0,0.05)); // playground positionieren und generieren
        global.obstacles.push_back(playground);

        Boxpile* boxpile = new Boxpile(odeHandle, osgHandle);
        boxpile->setColor("wall");
        boxpile->setPose(ROTM(M_PI/5.0,0,0,1)*TRANSM(0, 0,0.2));
        global.obstacles.push_back(boxpile);


        //     global.obstacles.push_back(playground);
        // double diam = .90;
        // OctaPlayground* playground3 = new OctaPlayground(odeHandle, osgHandle, osg::Vec3(/*Diameter*/4.0*diam, 5,/*Height*/ .3), 12,
        //                                                  false);
        // //  playground3->setColor(Color(.0,0.2,1.0,1));
        // playground3->setPosition(osg::Vec3(0,0,0)); // playground positionieren und generieren
        // global.obstacles.push_back(playground3);

        controller=0;

        //    addParameter("gamma_s",&teacher);
        global.configs.push_back(this);

        for(int i=0; i< bars; i++) {
            PassiveBox* b = new PassiveBox(odeHandle, osgHandle.changeColor(Color(0.,0.,0.)),
                                           osg::Vec3(1,10,0.3+i*.1),10);
            b->setPosition(osg::Vec3(10+i*7,0,0));
            global.obstacles.push_back(b);
        }

        /*******  H E X A P O D  *********/
        int numhexapods = 1;
        for ( int ii = 0; ii< numhexapods; ii++) {

            HexapodConf myHexapodConf        = Hexapod::getDefaultConf();
            myHexapodConf.coxaPower          = 1.5;
            myHexapodConf.tebiaPower         = 0.8;
            myHexapodConf.coxaJointLimitV    = .9; // M_PI/8;  // angle range for vertical dir. of legs
            myHexapodConf.coxaJointLimitH    = 1.3; //M_PI/4;
            myHexapodConf.tebiaJointLimit    = 1.8; // M_PI/4; // +- 45 degree
            myHexapodConf.percentageBodyMass = .5;
            myHexapodConf.useBigBox          = false;
            myHexapodConf.tarsus             = true;
            myHexapodConf.numTarsusSections  = 1;
            myHexapodConf.useTarsusJoints    = true;
            //    myHexapodConf.numTarsusSections = 2;

            OdeHandle rodeHandle = odeHandle;
            rodeHandle.substance.toRubber(20);


            vehicle = new Hexapod(rodeHandle, osgHandle.changeColor("Green"),
                                  myHexapodConf, "Hexapod_" + std::itos(teacher*10000));

            // on the top
            vehicle->place(osg::Matrix::rotate(M_PI*1,1,0,0)*osg::Matrix::translate(0,0,1.5+ 2*ii));
            // normal position
            //    vehicle->place(osg::Matrix::translate(0,0,0));

//     InvertMotorNStepConf cc = InvertMotorNStep::getDefaultConf();
//     cc.cInit=1.0;
//     cc.useS=false;
            //    cc.someInternalParams=true;
//     InvertMotorNStep *semox = new InvertMotorNStep(cc);
//     semox->setParam("steps", 1);
//     semox->setParam("continuity", 0.005);
//     semox->setParam("teacher", teacher);

            SoMLConf sc = SoML::getDefaultConf();
            sc.useHiddenContr=true;
            sc.useHiddenModel=false;
            sc.someInternalParams=false;
            sc.useS=false;
            SoML* soml = new SoML(sc);
            soml->setParam("epsC",0.105);
            soml->setParam("epsA",0.05);

            Sox* sox = new Sox(1.2, false);
            sox->setParam("epsC",0.105);
            sox->setParam("epsA",0.05);
            sox->setParam("Logarithmic",1);


            SeMoXConf cc = SeMoX::getDefaultConf();
            //cc.cInit=.95;
            cc.cInit=.99;
            cc.modelExt=false;
            cc.someInternalParams=true;
            SeMoX* semox = new SeMoX(cc);

            DerInfConf dc = DerInf::getDefaultConf();
            dc.cInit=.599;
            dc.someInternalParams=false;
            AbstractController* derinf = new DerInf(dc);
            derinf->setParam("epsC",0.1);
            derinf->setParam("epsA",0.05);

            AbstractController* sine = 0;
            if(useSineController) {
                // sine = new SineController(~0, SineController::Sine);
                sine = new SineController(~0, SineController::Impulse);
                // //     // //     // motorpower 20
                sine->setParam("period", 30);
                sine->setParam("phaseshift", 0.5);
                sine->setParam("amplitude", 0.5);
            }

            semox->setParam("epsC", 0.1);
            semox->setParam("epsA", 0.1);
            semox->setParam("rootE", 3);
            semox->setParam("s4avg", 1);
            semox->setParam("gamma_cont", 0.005);

            semox->setParam("gamma_teach", teacher);


            if(useSineController) {
                controller = sine;
            } else {
                //      controller = semox;
                controller = sox;
                //  controller = soml;
                // controller = derinf;
            }

            One2OneWiring* wiring = new One2OneWiring(new ColorUniformNoise(0.1));
            // the feedbackwiring feeds here 75% of the motor actions as inputs and only 25% of real inputs
//     AbstractWiring* wiring = new FeedbackWiring(new ColorUniformNoise(0.1),
//                                                 FeedbackWiring::Motor, 0.75);
            //global.plotoptions.push_back(PlotOption(GuiLogger,Robot,5));
            OdeAgent* agent = new OdeAgent(global);
            agent->init(controller, vehicle, wiring);
            // add an operator to keep robot from falling over
            agent->addOperator(new LimitOrientationOperator(Axis(0,0,1), Axis(0,0,1), M_PI*0.5, 30));
            if(track) {
                TrackRobotConf c = TrackRobot::getDefaultConf();
                c.displayTrace = true;
                c.scene        = "";
                c.interval     = 1;
                c.trackSpeed   = false;
                c.displayTraceThickness = 0.01;
                agent->setTrackOptions(TrackRobot(c));
            }
            if(tracksegm) {
                TrackRobotConf c   = TrackRobot::getDefaultConf();
                Color      col = osgHandle.getColor("joint");
                c.displayTrace = true;
                c.scene        = "segm";
                c.interval     = 1;
                c.displayTraceThickness = 0.02;
                col.alpha()    = 0.5;
                agent->addTracking(5, TrackRobot(c), col);
                agent->addTracking(8, TrackRobot(c), col);
            }

            global.agents.push_back(agent);
            global.configs.push_back(agent);
            //agent->startMotorBabblingMode(5000);

            // this->getHUDSM()->setColor(Color(1.0,1.0,0));
            // this->getHUDSM()->setFontsize(18);
            // this->getHUDSM()->addMeasure(teacher,"gamma_s",ID,1);

        }
    }
示例#11
0
  // 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 );
    }



  }
示例#12
0
  // starting function (executed once at the beginning of the simulation loop)
  void start(const OdeHandle& odeHandle, const OsgHandle& osgHandle, GlobalData& global)
  {
    setCameraHomePos(Pos(46.8304, -1.4434, 19.3963),  Pos(88.9764, -26.2964, 0));

    OdeHandle elast = odeHandle;
    elast.substance.toMetal(0.8);

    // initialization
    // - set global noise to 0.1
    global.odeConfig.setParam("noise",0.01);
    //  global.odeConfig.setParam("gravity", 0); // no gravity

    Playground* playground1 = new Playground(elast, osgHandle, osg::Vec3(30.0, 0.2, 1.0), 1, true);
    playground1->setColor(Color(0.88f,0.4f,0.26f,0.2f));
    playground1->setTexture("Images/really_white.rgb");
    playground1->setGroundColor(Color(200/255.0,174.0/255.0,21.0/255.0));
    playground1->setGroundTexture("Images/really_white.rgb");
    playground1->setPosition(osg::Vec3(0,0,0.0)); // playground positionieren und generieren
    global.obstacles.push_back(playground1);


    // Agents
    numrobots = 2;
    ForcedSphereConf conf;
    ForcedSphere** spheres = new ForcedSphere*[numrobots];
    Sensor** sensors = new Sensor*[numrobots];
    controllers = new AbstractController*[numrobots];
    AbstractWiring* wiring;
    OdeAgent* agent;

    for(int i=0; i<numrobots; i++){
      conf = ForcedSphere::getDefaultConf();
      //    conf.addSensor(new AxisOrientationSensor(AxisOrientationSensor::OnlyZAxis));
      //    RelativePositionSensor* s = new RelativePositionSensor(4,1,Sensor::X | Sensor::Y);
      // s->setReference(playground1->getMainPrimitive());
      SpeedSensor* s = new SpeedSensor(5,SpeedSensor::Translational,
                                       Sensor::X | Sensor::Y);
      conf.addSensor(s);
      conf.addSensor(new SoundSensor());
      conf.addMotor(new Speaker(-1));
      conf.maxForce = 10;
      conf.speedDriven = true;
      conf.maxSpeed = 5;
      conf.radius = 0.5;
      conf.cylinderBody=true;
      ForcedSphere* sphere1;
      sphere1 = new ForcedSphere ( elast, osgHandle.changeColor(Color(i==0,i==1,i==2)),
                                   conf, "Agent1");
      ((OdeRobot*)sphere1)->place ( Pos( 2*i , 0 , 0.1 ));

      InvertMotorNStepConf cc = InvertMotorNStep::getDefaultConf();
      cc.useSD=true;

      controller = new InvertMotorNStep(cc);
      controller->setParam("epsA",0.03); // model learning rate
      controller->setParam("epsC",0.01); // controller learning rate
      controller->setParam("rootE",3);    // model and contoller learn with square rooted error
      controller->setParam("factorB",0.2);
      controller->setParam("noiseB",0.01);
      controller->setParam("s4avg",10);
      controller->setParam("adaptrate",0.000);
      controller->setParam("nomupdate",0.001);
      controller->setParam("noiseY",0.0);


      // controller = new SineController();
      // controller = new InvertNChannelController(10,1.2);
      // controller->setParam("eps",0.2);

      global.configs.push_back ( controller );

      wiring = new One2OneWiring ( new ColorUniformNoise() );
      // DerivativeWiringConf wc = DerivativeWiring::getDefaultConf();
      //     wc.useId=false;
      //     wc.useSecondD=true;
      //     wc.eps=1;
      //     wc.derivativeScale=100;
      //     wiring = new DerivativeWiring ( wc, new ColorUniformNoise());
      agent = new OdeAgent ( i==0 ? plotoptions : std::list<PlotOption>() );
      agent->init ( controller , sphere1 , wiring );
      global.agents.push_back ( agent );
      spheres[i]=sphere1;
      sensors[i]=s;
      controllers[i]=controller;
    }

    // connect them
    // let robot 2  actually persive robot 1
    //    sensors[1]->init(spheres[0]->getMainPrimitive());

    myspeaker=0;
//     myspeaker = new Speaker(1);
//     myspeaker->init(playground1->getMainPrimitive());


  }
示例#13
0
  // 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);


  }
示例#14
0
文件: main.cpp 项目: Sosi/lpzrobots
  void start(const OdeHandle& odeHandle, const OsgHandle& osgHandle, GlobalData& global)
  {

    setCameraHomePos ( Pos ( 0, 0, 7), Pos ( -0.0828247 , -89.9146 , 0) );
    // initialization
    // - set noise to 0.1
    // - register file chess.ppm as a texture called chessTexture (used for the wheels)
    global.odeConfig.noise=0.1;
    //  global.odeConfig.setParam("gravity", 0);
    //  int chessTexture = dsRegisterTexture("chess.ppm");

    // 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)

    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);
    //****************

    ComponentConf cConf = Component::getDefaultConf ();
    cConf.max_force = 2;
    cConf.speed = 10;

//adding the controller for the component-connections

    InvertMotorNStepConf cc = InvertMotorNStep::getDefaultConf();

    cc.cInit=1.2;
    AbstractController* controller;
    DerivativeWiringConf c = DerivativeWiring::getDefaultConf ();
    DerivativeWiring* wiring;
    OdeAgent* agent;

    body = new SimpleComponent ( odeHandle , osgHandle , cConf );
    wheel[0] = new SimpleComponent ( odeHandle , osgHandle , cConf );
    wheel[1] = new SimpleComponent ( odeHandle , osgHandle , cConf );
    wheel[2] = new SimpleComponent ( odeHandle , osgHandle , cConf );
    wheel[3] = new SimpleComponent ( odeHandle , osgHandle , cConf );

    body->setSimplePrimitive ( new Capsule ( 0.1 , 1 ) );
    body->getMainPrimitive ()->init ( odeHandle , 0.5 , osgHandle.changeColor ( Color ( 2, 156/255.0, 0, 1.0f ) ) );
    body->getMainPrimitive()->getOSGPrimitive()->setTexture("Images/wood.rgb");

    for ( int n = 0; n < 4; n++ )
    {
        wheel[n]->setSimplePrimitive ( (Primitive*) new Sphere ( 0.3 ) );
        wheel[n]->getMainPrimitive ()->init ( odeHandle , 0.2 , osgHandle.changeColor ( Color ( 0.8,0.8,0.8 )) );
        wheel[n]->getMainPrimitive()->getOSGPrimitive()->setTexture("Images/wood.rgb");
    }


    body->place ( osg::Matrix::rotate ( M_PI/2 , osg::Vec3 (1 , 0 , 0 ))*osg::Matrix::translate ( 0 , 0 , 0.5 ) );

    wheel[0]->place ( Pos ( -0.45 , -0.5 , 0.5 ) );
    wheel[1]->place ( Pos ( 0.45 , -0.5 , 0.5 ) );
    wheel[2]->place ( Pos ( -0.45 , 0.5 , 0.5 ) );
    wheel[3]->place ( Pos ( 0.45 , 0.5 , 0.5 ) );

    for ( int n = 0; n < 4; n++ )
    {
        Axis axis = Axis ( ( wheel[n<2?0:2]->getPosition () - wheel[n<2?1:3]->getPosition ()).toArray() );
        HingeJoint* j1 = new HingeJoint ( body->getMainPrimitive () , wheel[n]->getMainPrimitive () , osg::Vec3 (0,0.5*( n<2?-1:1),0.5) , axis );
        j1->init ( odeHandle , osgHandle , true , 1 );

        body->addSubcomponent ( wheel[n] , j1 , false );
    }

            //controller
            controller = new InvertMotorNStep ( cc );
            controller->setParam ("adaptrate", 0.0);
            controller->setParam ("epsC", 0.1);
            controller->setParam ("epsA", 0.01);
            controller->setParam ("rootE", 3);
            controller->setParam ("steps", 2);
            controller->setParam ("s4avg", 2);
            controller->setParam ("factorB",0);
//            controller = new SineController ( 18 );
            //wiring
            wiring = new DerivativeWiring ( c , new ColorUniformNoise () );
            //agent
            agent = new OdeAgent ( plotoptions );
            agent->init ( controller , body , wiring );
            global.agents.push_back ( agent );
            global.configs.push_back ( controller );


  }