示例#1
0
//------------------------------------------------------------------------------
int main( int argc, char* argv[] )
{
  if (argc < 3) {
    printf("Too few arguments!\nUsage: orbittarget <robot_name> <neighbour_name> [config_file]\n");
    return 1;
  }

  // init general stuff
  ErrorInit ( 1, false );
  initRandomNumberGenerator();

  printf("-----------------------------------\n");
  printf("Chatterbox Orbit Target\n");
  printf("  build %s %s \n", __DATE__, __TIME__);
  printf("  compiled against RAPI version %s (%s) build %s\n", RAPI_VERSION(),
           RAPI_GIT_VERSION(), RAPI_BUILD() );
  printf("\n");
  printf("Lifting the robot up disables motors\n");

  if (signal(SIGINT, quitSig) == SIG_ERR) {
     PRT_ERR1("Error resetting signal handler %s", strerror(errno));
  }

  // Create robot and its controller
  robot = new Rapi::CCBRobot ();
  if ( robot->init() == 0) {
    Rapi::rapiError->print();
    delete robot;
    exit(-1);
  }
  robot->setName(argv[1]);

  if (argc > 3)
    robotCtrl = new COrbitTarget ( robot, std::string(argv[3]) );
  else  
    robotCtrl = new COrbitTarget ( robot );

  robotCtrl->setNNName(std::string(argv[2]));

  // Blocking call
  robot->run();

  // Clean up robot controller
  if (robotCtrl) {
    delete robotCtrl;
    robotCtrl = NULL;
  }

  // Clean up robot
  if (robot)
    delete (robot);
  return 1;
}
示例#2
0
文件: main.cpp 项目: rtv/autolab-fasr
//-----------------------------------------------------------------------------
extern "C" int Init ( Stg::Model* mod )
{
  std::string logFileName = "fasr_analyst.log";
  std::string value;
  float probBroadcast = 1.0;
  char* policy = new char[40];
  static bool init = false;
  Rapi::CLooseStageRobot* robot;
  CTaskManager* taskManager;
  CAnalyst* analyst;
  ABaseRobotCtrl* robotCtrl;

  static CCharger charger ( mod->GetWorld()->GetModel ( "charger" ) );
  static CDestination depotDestination ( mod->GetWorld()->GetModel ( "depot" ) );


  if ( not init ) {
    init = true;
    //mod->AddShutdownCallback ( ( Stg::stg_model_callback_t ) shutDownCallback, NULL );
    printf ( "-----------------------------------\n" );
    printf ( "FASR \n" );
    printf ( "  build %s %s \n", __DATE__, __TIME__ );
    printf ( "  compiled against RAPI version %s (%s) build %s\n", RAPI_VERSION(),
             RAPI_GIT_VERSION(), RAPI_BUILD() );
    printf ( "\n" );

    //************************************
    // init general stuff
    ErrorInit ( 2, false );
    initRandomNumberGenerator();
  }
  //************************************
  // create robot and its controller
  robot = new Rapi::CLooseStageRobot ( mod );
  if ( ! mod->GetPropertyStr ( "policy", &policy,  NULL ) ) {
    PRT_WARN0 ( "No policy specified " );
    exit ( -1 );
  }
  else {
    if ( strcmp ( policy, "fixed" ) == 0 )
      robotCtrl = new CFixedRatioPolicyRobotCtrl ( robot );
    else if ( strcmp ( policy, "replan" ) == 0 )
      robotCtrl = new CReplanPolicyRobotCtrl ( robot );
    else if ( strcmp ( policy, "static" ) == 0 )
      robotCtrl = new CStaticPolicyRobotCtrl ( robot );
    else if ( strcmp ( policy, "loop" ) == 0 )
      robotCtrl = new CLoopPolicyRobotCtrl ( robot );
    else if ( strcmp ( policy, "epsilon" ) == 0 )
      robotCtrl = new CEpsilonSamplerRobotCtrl ( robot );
    else if ( strcmp ( policy, "wait" ) == 0 ) {
      for ( unsigned int i=0; i< Stg::World::args.size(); i++ ) {
        if ( Stg::World::args[i].compare ( 0, 3, "-pb" ) == 0 ) {
          value = Stg::World::args[i].substr ( 4, Stg::World::args[i].size()-4 );
          probBroadcast = atof ( value.c_str() );
        }
      }
      printf ( "running with prob broadcast %f \n", probBroadcast );
      robotCtrl = new CWaitProbPolicyRobotCtrl ( robot, probBroadcast );
    }
    else {
      PRT_WARN1 ( "Unknown policy: %s", policy );
      exit ( -1 );
    }
  }

  //************************************
  // determine name of log file
  for ( unsigned int i=0; i< Stg::World::args.size(); i++ ) {
    if ( Stg::World::args[i].compare ( 0, 3, "-lf" ) == 0 ) {
      logFileName = Stg::World::args[i].substr ( 4, Stg::World::args[i].size()-4 );
    }
  }

  //************************************
  // get tasks from the task manager and hand them to the robot
  taskManager = CTaskManager::getInstance (
                  mod->GetWorld()->GetModel ( "taskmanager" ) );
  analyst = CAnalyst::getInstance ( mod->GetWorld()->GetModel ( "taskmanager" ), logFileName );

  taskManager->registerRobot ( robotCtrl );
  analyst->registerRobot ( robotCtrl );
  robotCtrl->addCharger ( &charger );
  robotCtrl->setDepot ( &depotDestination );

#ifdef GUI
  gui = CFasrGui::getInstance ( 0, NULL );
  gui->registerRobot ( robot );
#endif

  return 0; // ok

}