Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.70 KB | None | 0 0
  1. #include "Aria.h"
  2.  
  3. int matriz[1001][1001];
  4.  
  5. class ActionGo : public ArAction {
  6.   public:
  7.     ActionGo (ArActionGoto go_to);
  8.     virtual ~ActionGo(void) {};
  9.     virtual ArActionDesired *fire(ArActionDesired currentDesired);
  10.     virtual void setRobot(ArRobot *robot);
  11.  
  12.   protected:
  13.   ArRangeDevice *mySonar;
  14.   ArActionDesired myDesired;
  15.   ArActionGoto myGoto;
  16.  
  17. };
  18.  
  19. ActionGo::ActionGo(ArActionGoto go_to) :
  20.   ArAction("Go") {
  21.   mySonar = NULL;
  22.   myGoto = go_to;
  23. }
  24.  
  25. void ActionGo::setRobot(ArRobot *robot)
  26. {
  27.   ArAction::setRobot(robot);
  28.   mySonar = robot->findRangeDevice("sonar");
  29.   if (robot == NULL)
  30.     {
  31.       ArLog::log(ArLog::Terse, "actionExample: ActionGo: Warning: I found no sonar, deactivating.");
  32.       deactivate();
  33.     }
  34. }
  35.  
  36. ArActionDesired *ActionGo::fire(ArActionDesired currentDesired)
  37. {
  38.   double range;
  39.   double speed;
  40.  
  41.   myDesired.reset();
  42.  
  43.   if (mySonar == NULL) {
  44.     deactivate();
  45.     return NULL;
  46.   }
  47.  
  48.   return &myDesired;
  49. }
  50.  
  51. int main(int argc, char**argv){
  52.  
  53.     matriz[500][500] = -1;
  54.     //-1 escolhido para representar a posição do robo
  55.     //tamanho do robo é 500mm, ent de cada posicao da matriz pra outra
  56.     //é 510mm
  57.     //fazer modulo (%510)
  58.  
  59.   Aria::init();
  60.   ArArgumentParser parser(&argc, argv);
  61.   parser.loadDefaultArguments();
  62.   ArRobot robot;
  63.   ArSonarDevice sonar;
  64.  
  65.   // Connect to the robot, get some initial data from it such as type and name,
  66.   // and then load parameter files for this robot.
  67.   ArRobotConnector robotConnector(&parser, &robot);
  68.   if(!robotConnector.connectRobot()) {
  69.     ArLog::log(ArLog::Terse, "actionExample: Could not connect to the robot.");
  70.     if(parser.checkHelpAndWarnUnparsed()) {
  71.         // -help not given
  72.         Aria::logOptions();
  73.         Aria::exit(1);
  74.     }
  75.   }
  76.   if (!Aria::parseArgs() || !parser.checkHelpAndWarnUnparsed()) {
  77.     Aria::logOptions();
  78.     Aria::exit(1);
  79.   }
  80.   ArLog::log(ArLog::Normal, "actionExample: Connected to robot.");
  81.  
  82.   //adicionando sonar
  83.   robot.addRangeDevice(&sonar);
  84.   robot.runAsync(true);
  85.  
  86.   ArActionStallRecover recover;
  87.   ArActionAvoidFront AvoidFront("AvoidFront");
  88.   ArActionGoto gotoPoseAction("goto");
  89.   //ActionGo go(gotoPoseAction);
  90.  
  91.   //adicionando acoes para o robo
  92.    ArActionLimiterForwards limiterAction("speed limiter near", 300, 600, 250);
  93.   ArActionLimiterForwards limiterFarAction("speed limiter far", 300, 1100, 400);
  94.   ArActionLimiterTableSensor tableLimiterAction;
  95.   robot.addAction(&recover, 500);
  96.   robot.addAction(&AvoidFront, 400);
  97.   robot.addAction(&gotoPoseAction, 350);
  98.  
  99.   /*robot.lock();
  100.   gotoPoseAction.setGoal(ArPose(10000, 10000));
  101.   robot.unlock();
  102.   ArUtil::sleep(4000);*/
  103.  
  104.   robot.enableMotors();
  105.  
  106.   Aria::exit(0);
  107.  
  108.   return 0;
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement