本文整理汇总了C++中ArRobot::attachKeyHandler方法的典型用法代码示例。如果您正苦于以下问题:C++ ArRobot::attachKeyHandler方法的具体用法?C++ ArRobot::attachKeyHandler怎么用?C++ ArRobot::attachKeyHandler使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArRobot
的用法示例。
在下文中一共展示了ArRobot::attachKeyHandler方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char** argv)
{
// set up our simpleConnector
ArSimpleConnector simpleConnector(&argc, argv);
// robot
ArRobot robot;
// a key handler so we can do our key handling
ArKeyHandler keyHandler;
ArLog::init(ArLog::StdOut,ArLog::Verbose);
// if there are more arguments left then it means we didn't
// understand an option
if (!simpleConnector.parseArgs() || argc > 1)
{
simpleConnector.logOptions();
keyHandler.restore();
exit(1);
}
// mandatory init
Aria::init();
ArLog::init(ArLog::StdOut, ArLog::Terse, NULL, true);
// let the global aria stuff know about it
Aria::setKeyHandler(&keyHandler);
// toss it on the robot
robot.attachKeyHandler(&keyHandler);
// set up the robot for connecting
if (!simpleConnector.connectRobot(&robot))
{
printf("Could not connect to robot... exiting\n");
Aria::shutdown();
keyHandler.restore();
return 1;
}
// turn on the motors for the velocity response test
robot.comInt(ArCommands::ENABLE, 1);
velTime.setToNow();
// turn off the sonar
robot.comInt(ArCommands::SONAR, 0);
ArGlobalFunctor1<ArRobot *> userTaskCB(&userTask, &robot);
robot.addUserTask("iotest", 100, &userTaskCB);
robot.comInt(ArCommands::IOREQUEST, 1);
requestTime.setToNow();
//start the robot running, true so that if we lose connection the run stops
robot.run(true);
// now exit
Aria::shutdown();
return 0;
}
示例2: addKeyHandlers
void addKeyHandlers()
{
ArKeyHandler *keyHandler = Aria::getKeyHandler();
if(keyHandler == NULL)
{
keyHandler = new ArKeyHandler();
Aria::setKeyHandler(keyHandler);
robot->attachKeyHandler(keyHandler);
}
//keyHandler->addKeyHandler('g', &myGoCB);
//keyHandler->addKeyHandler('c', &myGoHomeCB);
keyHandler->addKeyHandler('p', &myStartCB);
keyHandler->addKeyHandler('s', &myStopCB);
keyHandler->addKeyHandler('m', &myPrintCB);
}
示例3: main
int main(int argc, char **argv)
{
Aria::init();
ArArgumentParser parser(&argc, argv);
parser.loadDefaultArguments();
ArRobot robot;
ArRobotConnector robotConnector(&parser, &robot);
ArLaserConnector laserConnector(&parser, &robot, &robotConnector);
if(!robotConnector.connectRobot())
{
ArLog::log(ArLog::Terse, "lineFinderExample: Could not connect to the robot.");
if(parser.checkHelpAndWarnUnparsed())
{
// -help not given
Aria::logOptions();
Aria::exit(1);
}
}
if (!Aria::parseArgs() || !parser.checkHelpAndWarnUnparsed())
{
Aria::logOptions();
Aria::exit(1);
}
ArLog::log(ArLog::Normal, "lineFinderExample: Connected to robot.");
robot.runAsync(true);
// Connect to laser(s) as defined in parameter files.
// (Some flags are available as arguments to connectLasers() to control error behavior and to control which lasers are put in the list of lasers stored by ArRobot. See docs for details.)
if(!laserConnector.connectLasers())
{
ArLog::log(ArLog::Terse, "Could not connect to configured lasers. Exiting.");
Aria::exit(3);
return 3;
}
ArLog::log(ArLog::Normal, "lineFinderExample: Connected to laser");
ArKeyHandler keyHandler;
Aria::setKeyHandler(&keyHandler);
robot.attachKeyHandler(&keyHandler);
// Create the ArLineFinder object. Set it to log lots of information about its
// processing.
ArLaser *laser = robot.findLaser(1);
if(!laser)
{
ArLog::log(ArLog::Terse, "lineFinderExample: No laser device connected, exiting.");
Aria::exit(4);
return 4;
}
ArLineFinder lineFinder(laser);
lineFinder.setVerbose(true);
// Add key callbacks that simply call the ArLineFinder::getLinesAndSaveThem()
// function, which searches for lines in the current set of laser sensor
// readings, and saves them in files with the names 'points' and 'lines'.
ArFunctorC<ArLineFinder> findLineCB(&lineFinder,
&ArLineFinder::getLinesAndSaveThem);
keyHandler.addKeyHandler('f', &findLineCB);
keyHandler.addKeyHandler('F', &findLineCB);
printf("If you press the 'f' key the points and lines found will be saved\n");
printf("Into the 'points' and 'lines' file in the current working directory\n");
robot.waitForRunExit();
Aria::exit(0);
return 0;
}
示例4: _tmain
int __cdecl _tmain (int argc, char** argv)
{
//------------ I N I C I O M A I N D E L P R O G R A M A D E L R O B O T-----------//
//inicializaion de variables
Aria::init();
ArArgumentParser parser(&argc, argv);
parser.loadDefaultArguments();
ArSimpleConnector simpleConnector(&parser);
ArRobot robot;
ArSonarDevice sonar;
ArAnalogGyro gyro(&robot);
robot.addRangeDevice(&sonar);
ActionGos go(500, 350);
robot.addAction(&go, 48);
ActionTurns turn(400, 110);
robot.addAction(&turn, 49);
ActionTurns turn2(400, 110);
robot.addAction(&turn2, 49);
// presionar tecla escape para salir del programa
ArKeyHandler keyHandler;
Aria::setKeyHandler(&keyHandler);
robot.attachKeyHandler(&keyHandler);
printf("Presionar ESC para salir\n");
// uso de sonares para evitar colisiones con las paredes u
// obstaculos grandes, mayores a 8cm de alto
ArActionLimiterForwards limiterAction("limitador velocidad cerca", 300, 600, 250);
ArActionLimiterForwards limiterFarAction("limitador velocidad lejos", 300, 1100, 400);
ArActionLimiterTableSensor tableLimiterAction;
robot.addAction(&tableLimiterAction, 100);
robot.addAction(&limiterAction, 95);
robot.addAction(&limiterFarAction, 90);
// Inicializon la funcion de goto
ArActionGoto gotoPoseAction("goto");
robot.addAction(&gotoPoseAction, 50);
// Finaliza el goto si es que no hace nada
ArActionStop stopAction("stop");
robot.addAction(&stopAction, 40);
// Parser del CLI
if (!Aria::parseArgs() || !parser.checkHelpAndWarnUnparsed())
{
Aria::logOptions();
exit(1);
}
// Conexion del robot
if (!simpleConnector.connectRobot(&robot))
{
printf("Could not connect to robot... exiting\n");
Aria::exit(1);
}
robot.runAsync(true);
// enciende motores, apaga sonidos
robot.enableMotors();
robot.comInt(ArCommands::SOUNDTOG, 0);
// Imprimo algunos datos del robot como posicion velocidad y bateria
robot.lock();
ArLog::log(ArLog::Normal, "Posicion=(%.2f,%.2f,%.2f), Trans. Vel=%.2f, Bateria=%.2fV",
robot.getX(), robot.getY(), robot.getTh(), robot.getVel(), robot.getBatteryVoltage());
robot.unlock();
const int duration = 100000; //msec
ArLog::log(ArLog::Normal, "Completados los puntos en %d segundos", duration/1000);
// ============================ INICIO CONFIG COM =================================//
CSerial serial;
LONG lLastError = ERROR_SUCCESS;
// Trata de abrir el com seleccionado
lLastError = serial.Open(_T("COM3"),0,0,false);
if (lLastError != ERROR_SUCCESS)
return ::ShowError(serial.GetLastError(), _T("Imposible abrir el COM"));
// Inicia el puerto serial (9600,8N1)
lLastError = serial.Setup(CSerial::EBaud9600,CSerial::EData8,CSerial::EParNone,CSerial::EStop1);
if (lLastError != ERROR_SUCCESS)
return ::ShowError(serial.GetLastError(), _T("Imposible setear la config del COM"));
// Register only for the receive event
lLastError = serial.SetMask(CSerial::EEventBreak |
CSerial::EEventCTS |
CSerial::EEventDSR |
CSerial::EEventError |
CSerial::EEventRing |
CSerial::EEventRLSD |
CSerial::EEventRecv);
if (lLastError != ERROR_SUCCESS)
return ::ShowError(serial.GetLastError(), _T("Unable to set COM-port event mask"));
// Use 'non-blocking' reads, because we don't know how many bytes
// will be received. This is normally the most convenient mode
//.........这里部分代码省略.........
开发者ID:eilo,项目名称:Evolucion-Artificial-y-Robotica-Autonoma-en-Robots-Pioneer-P3-DX,代码行数:101,代码来源:guloso_mapeo+gopos.cpp
示例5: main
int main(int argc, char **argv)
{
bool done;
double distToTravel = 2300;
// whether to use the sim for the laser or not, if you use the sim
// for hte laser, you have to use the sim for the robot too
bool useSim = false;
// the laser
ArSick sick;
// connection
ArDeviceConnection *con;
// Laser connection
ArSerialConnection laserCon;
// robot
ArRobot robot;
// set a default filename
//std::string filename = "c:\\log\\1scans.2d";
std::string filename = "1scans.2d";
// see if we want to use a different filename
//if (argc > 1)
//Lfilename = argv[1];
printf("Logging to file %s\n", filename.c_str());
// start the logger with good values
sick.configureShort(useSim, ArSick::BAUD38400,
ArSick::DEGREES180, ArSick::INCREMENT_HALF);
ArSickLogger logger(&robot, &sick, 300, 25, filename.c_str());
// mandatory init
Aria::init();
// add it to the robot
robot.addRangeDevice(&sick);
//ArAnalogGyro gyro(&robot);
// if we're not using the sim, make a serial connection and set it up
if (!useSim)
{
ArSerialConnection *serCon;
serCon = new ArSerialConnection;
serCon->setPort();
//serCon->setBaud(38400);
con = serCon;
}
// if we are using the sim, set up a tcp connection
else
{
ArTcpConnection *tcpCon;
tcpCon = new ArTcpConnection;
tcpCon->setPort();
con = tcpCon;
}
// set the connection on the robot
robot.setDeviceConnection(con);
// try to connect, if we fail exit
if (!robot.blockingConnect())
{
printf("Could not connect to robot... exiting\n");
Aria::shutdown();
return 1;
}
// set up a key handler so escape exits and attach to the robot
ArKeyHandler keyHandler;
robot.attachKeyHandler(&keyHandler);
// run the robot, true here so that the run will exit if connection lost
robot.runAsync(true);
// if we're not using the sim, set up the port for the laser
if (!useSim)
{
laserCon.setPort(ArUtil::COM3);
sick.setDeviceConnection(&laserCon);
}
// now that we're connected to the robot, connect to the laser
sick.runAsync();
if (!sick.blockingConnect())
{
printf("Could not connect to SICK laser... exiting\n");
robot.disconnect();
Aria::shutdown();
return 1;
}
#ifdef WIN32
// wait until someone pushes the motor button to go
while (1)
{
//.........这里部分代码省略.........
示例6: main
int main(int argc, char **argv)
{
Aria::init();
ArArgumentParser argParser(&argc, argv);
argParser.loadDefaultArguments();
ArRobot robot;
ArSick laser;
std::ofstream stream; // for loggin
time_t timer;
char buffer[120];
//for loggin
ArRobotConnector robotConnector(&argParser, &robot);
ArLaserConnector laserConnector(&argParser, &robot, &robotConnector);
int32_t count = 0;
readyLog(stream);
if (!robotConnector.connectRobot())
{
ArLog::log(ArLog::Terse, "Could not connect to the robot.");
if (argParser.checkHelpAndWarnUnparsed())
{
// -help not given, just exit.
Aria::logOptions();
Aria::exit(1);
return 1;
}
}
// Trigger argument parsing
if (!Aria::parseArgs() || !argParser.checkHelpAndWarnUnparsed())
{
Aria::logOptions();
Aria::exit(1);
return 1;
}
ArKeyHandler keyHandler;
Aria::setKeyHandler(&keyHandler);
robot.attachKeyHandler(&keyHandler);
puts("This program will make the robot wander around. It uses some avoidance\n"
"actions if obstacles are detected, otherwise it just has a\n"
"constant forward velocity.\n\nPress CTRL-C or Escape to exit.");
//ArSonarDevice sonar;
//robot.addRangeDevice(&sonar);
robot.addRangeDevice(&laser);
robot.runAsync(true);
// try to connect to laser. if fail, warn but continue, using sonar only
if (!laserConnector.connectLasers())
{
ArLog::log(ArLog::Normal, "Warning: unable to connect to requested lasers, will wander using robot sonar only.");
}
double sampleAngle, dist;
auto sampleRange = laser.currentReadingPolar(-20, 20, &sampleAngle);
auto degreeStr = laser.getDegreesChoicesString();
std::cout << "auto sampleRange = laser.currentReadingPolar(-20, 20, &sampleAngle);" << sampleRange << std::endl;
std::cout << "auto degreeStr = laser.getDegreesChoicesString(); : " << degreeStr << std::endl;
// turn on the motors, turn off amigobot sounds
robot.enableMotors();
//robot.getLaserMap()
robot.comInt(ArCommands::SOUNDTOG, 0);
// add a set of actions that combine together to effect the wander behavior
ArActionStallRecover recover;
ArActionBumpers bumpers;
ArActionAvoidFront avoidFrontNear("Avoid Front Near", 100, 0);
ArActionAvoidFront avoidFrontFar;
ArActionConstantVelocity constantVelocity("Constant Velocity", 400);
robot.addAction(&recover, 100);
robot.addAction(&bumpers, 75);
robot.addAction(&avoidFrontNear, 50);
robot.addAction(&avoidFrontFar, 49);
robot.addAction(&constantVelocity, 25);
stream << "IMPORTANT !! == robot.getRobotRadius() : " << robot.getRobotRadius << std::endl;
std::string timestamp;
while (1)
{
//
//
time(&timer);
strftime(buffer, 80, " - timestamp : %I:%M:%S", localtime(&timer));
timestamp = buffer;
dist = robot.checkRangeDevicesCurrentPolar(-70, 70, &sampleAngle) - robot.getRobotRadius();
stream << count << timestamp << "checkRangeDevicesCurrentPolar(-70, 70, &angle) : " << dist << std::endl;
Sleep(500);
count++;
}
//.........这里部分代码省略.........
示例7: main
int main(int argc, char** argv)
{
// Initialize some global data
Aria::init();
// If you want ArLog to print "Verbose" level messages uncomment this:
//ArLog::init(ArLog::StdOut, ArLog::Verbose);
// This object parses program options from the command line
ArArgumentParser parser(&argc, argv);
// Load some default values for command line arguments from /etc/Aria.args
// (Linux) or the ARIAARGS environment variable.
parser.loadDefaultArguments();
// Central object that is an interface to the robot and its integrated
// devices, and which manages control of the robot by the rest of the program.
ArRobot robot;
// Object that connects to the robot or simulator using program options
ArRobotConnector robotConnector(&parser, &robot);
// If the robot has an Analog Gyro, this object will activate it, and
// if the robot does not automatically use the gyro to correct heading,
// this object reads data from it and corrects the pose in ArRobot
ArAnalogGyro gyro(&robot);
// Connect to the robot, get some initial data from it such as type and name,
// and then load parameter files for this robot.
if (!robotConnector.connectRobot())
{
// Error connecting:
// if the user gave the -help argumentp, then just print out what happened,
// and continue so options can be displayed later.
if (!parser.checkHelpAndWarnUnparsed())
{
ArLog::log(ArLog::Terse, "Could not connect to robot, will not have parameter file so options displayed later may not include everything");
}
// otherwise abort
else
{
ArLog::log(ArLog::Terse, "Error, could not connect to robot.");
Aria::logOptions();
Aria::exit(1);
}
}
// Connector for laser rangefinders
ArLaserConnector laserConnector(&parser, &robot, &robotConnector);
// Connector for compasses
ArCompassConnector compassConnector(&parser);
// Parse the command line options. Fail and print the help message if the parsing fails
// or if the help was requested with the -help option
if (!Aria::parseArgs() || !parser.checkHelpAndWarnUnparsed())
{
Aria::logOptions();
exit(1);
}
// Used to access and process sonar range data
ArSonarDevice sonarDev;
// Used to perform actions when keyboard keys are pressed
ArKeyHandler keyHandler;
Aria::setKeyHandler(&keyHandler);
// ArRobot contains an exit action for the Escape key. It also
// stores a pointer to the keyhandler so that other parts of the program can
// use the same keyhandler.
robot.attachKeyHandler(&keyHandler);
printf("You may press escape to exit\n");
// Attach sonarDev to the robot so it gets data from it.
robot.addRangeDevice(&sonarDev);
// Start the robot task loop running in a new background thread. The 'true' argument means if it loses
// connection the task loop stops and the thread exits.
robot.runAsync(true);
// Connect to the laser(s) if lasers were configured in this robot's parameter
// file or on the command line, and run laser processing thread if applicable
// for that laser class. (For the purposes of this demo, add all
// possible lasers to ArRobot's list rather than just the ones that were
// specified with the connectLaser option (so when you enter laser mode, you
// can then interactively choose which laser to use from the list which will
// show both connected and unconnected lasers.)
if (!laserConnector.connectLasers(false, false, true))
{
printf("Could not connect to lasers... exiting\n");
Aria::exit(2);
}
// Create and connect to the compass if the robot has one.
ArTCM2 *compass = compassConnector.create(&robot);
if(compass && !compass->blockingConnect()) {
compass = NULL;
}
//.........这里部分代码省略.........
示例8: main
//.........这里部分代码省略.........
if (videoForwarder.isForwardingVideo())
{
bool invertedCamera = false;
camera = new ArVCC4(&robot, invertedCamera,
ArVCC4::COMM_UNKNOWN, true, true);
camera->init();
cameraCollection = new ArCameraCollection();
cameraCollection->addCamera("Cam1", "VCC4", "Camera", "VCC4");
handlerCamera = new ArServerHandlerCamera("Cam1",
&server,
&robot,
camera,
cameraCollection);
}
// You can use this class to send a set of arbitrary strings
// for MobileEyes to display, this is just a small example
ArServerInfoStrings stringInfo(&server);
Aria::getInfoGroup()->addAddStringCallback(stringInfo.getAddStringFunctor());
Aria::getInfoGroup()->addStringInt(
"Motor Packet Count", 10,
new ArConstRetFunctorC<int, ArRobot>(&robot,
&ArRobot::getMotorPacCount));
/*
Aria::getInfoGroup()->addStringInt(
"Laser Packet Count", 10,
new ArRetFunctorC<int, ArSick>(&sick,
&ArSick::getSickPacCount));
*/
// start the robot running, true means that if we lose connection the run thread stops
robot.runAsync(true);
// connect the laser(s) if it was requested
if (!laserConnector.connectLasers())
{
printf("Could not connect to lasers... exiting\n");
Aria::exit(2);
}
drawings.addRobotsRangeDevices(&robot);
// log whatever we wanted to before the runAsync
simpleOpener.checkAndLog();
// now let it spin off in its own thread
server.runAsync();
printf("Server is now running...\n");
// Add a key handler so that you can exit by pressing
// escape. Note that a key handler prevents you from running
// a program in the background on Linux, since it expects an
// active terminal to read keys from; remove this if you want
// to run it in the background.
ArKeyHandler *keyHandler;
if ((keyHandler = Aria::getKeyHandler()) == NULL)
{
keyHandler = new ArKeyHandler;
Aria::setKeyHandler(keyHandler);
robot.lock();
robot.attachKeyHandler(keyHandler);
robot.unlock();
printf("To exit, press escape.\n");
}
// Read in parameter files.
std::string configFile = "serverDemoConfig.txt";
Aria::getConfig()->setBaseDirectory("./");
if (Aria::getConfig()->parseFile(configFile.c_str(), true, true))
{
ArLog::log(ArLog::Normal, "Loaded config file %s", configFile.c_str());
}
else
{
if (ArUtil::findFile(configFile.c_str()))
{
ArLog::log(ArLog::Normal,
"Trouble loading configuration file %s, continuing",
configFile.c_str());
}
else
{
ArLog::log(ArLog::Normal,
"No configuration file %s, will try to create if config used",
configFile.c_str());
}
}
clientSwitchManager.runAsync();
robot.lock();
robot.enableMotors();
robot.unlock();
robot.waitForRunExit();
Aria::exit(0);
}
示例9: _tmain
int _tmain(int argc, char** argv)
{
//-------------- M A I N D E L P R O G R A M A D E L R O B O T------------//
//----------------------------------------------------------------------------------//
//inicializaion de variables
Aria::init();
ArArgumentParser parser(&argc, argv);
parser.loadDefaultArguments();
ArSimpleConnector simpleConnector(&parser);
ArRobot robot;
ArSonarDevice sonar;
ArAnalogGyro gyro(&robot);
robot.addRangeDevice(&sonar);
ActionTurns turn(400, 55);
robot.addAction(&turn, 49);
ActionTurns turn2(400, 55);
robot.addAction(&turn2, 49);
turn.deactivate();
turn2.deactivate();
// presionar tecla escape para salir del programa
ArKeyHandler keyHandler;
Aria::setKeyHandler(&keyHandler);
robot.attachKeyHandler(&keyHandler);
printf("Presionar ESC para salir\n");
// uso de sonares para evitar colisiones con las paredes u
// obstaculos grandes, mayores a 8cm de alto
ArActionLimiterForwards limiterAction("limitador velocidad cerca", 300, 600, 250);
ArActionLimiterForwards limiterFarAction("limitador velocidad lejos", 300, 1100, 400);
ArActionLimiterTableSensor tableLimiterAction;
robot.addAction(&tableLimiterAction, 100);
robot.addAction(&limiterAction, 95);
robot.addAction(&limiterFarAction, 90);
// Inicializon la funcion de goto
ArActionGoto gotoPoseAction("goto");
robot.addAction(&gotoPoseAction, 50);
// Finaliza el goto si es que no hace nada
ArActionStop stopAction("stop");
robot.addAction(&stopAction, 40);
// Parser del CLI
if (!Aria::parseArgs() || !parser.checkHelpAndWarnUnparsed())
{
Aria::logOptions();
exit(1);
}
// Conexion del robot
if (!simpleConnector.connectRobot(&robot))
{
printf("Could not connect to robot... exiting\n");
Aria::exit(1);
}
robot.runAsync(true);
// enciende motores, apaga sonidos
robot.enableMotors();
robot.comInt(ArCommands::SOUNDTOG, 0);
// Imprimo algunos datos del robot como posicion velocidad y bateria
robot.lock();
ArLog::log(ArLog::Normal, "Posicion=(%.2f,%.2f,%.2f), Trans. Vel=%.2f, Bateria=%.2fV",
robot.getX(), robot.getY(), robot.getTh(), robot.getVel(), robot.getBatteryVoltage());
robot.unlock();
const int duration = 100000; //msec
ArLog::log(ArLog::Normal, "Completados los puntos en %d segundos", duration/1000);
bool first = true;
int goalNum = 0;
int color = 3;
ArTime start;
start.setToNow();
while (Aria::getRunning())
{
robot.lock();
// inicia el primer punto
if (first || gotoPoseAction.haveAchievedGoal())
{
first = false;
goalNum++; //cambia de 0 a 1 el contador
printf("El contador esta en: --> %d <---\n",goalNum);
if (goalNum > 20)
goalNum = 1;
//comienza la secuencia de puntos
if (goalNum == 1)
{
gotoPoseAction.setGoal(ArPose(1150, 0));
ArLog::log(ArLog::Normal, "Siguiente punto en %.0f %.0f",
gotoPoseAction.getGoal().getX(), gotoPoseAction.getGoal().getY());
// Imprimo algunos datos del robot como posicion velocidad y bateria
robot.lock();
//.........这里部分代码省略.........
开发者ID:eilo,项目名称:Evolucion-Artificial-y-Robotica-Autonoma-en-Robots-Pioneer-P3-DX,代码行数:101,代码来源:clasificador_guloso.cpp
示例10: main
int main(int argc, char **argv)
{
Aria::init();
ArArgumentParser parser(&argc, argv);
parser.loadDefaultArguments();
ArRobot robot;
ArRobotConnector robotConnector(&parser, &robot);
ArLaserConnector laserConnector(&parser, &robot, &robotConnector);
ArAnalogGyro analogGyro(&robot);
// Always connect to the laser, and add half-degree increment and 180 degrees as default arguments for
// laser
parser.addDefaultArgument("-connectLaser -laserDegrees 180 -laserIncrement half");
if(!robotConnector.connectRobot())
{
ArLog::log(ArLog::Terse, "sickLagger: Could not connect to the robot.");
if(parser.checkHelpAndWarnUnparsed())
{
Aria::logOptions();
Aria::exit(1);
}
}
if(!Aria::parseArgs() || !parser.checkHelpAndWarnUnparsed())
{
Aria::logOptions();
Aria::exit(1);
}
ArKeyHandler keyHandler;
Aria::setKeyHandler(&keyHandler);
robot.attachKeyHandler(&keyHandler);
#ifdef WIN32
printf("Pausing 5 seconds so you can disconnect VNC if you are using it.\n");
ArUtil::sleep(5000);
#endif
std::string filename = "1scans.2d";
if (argc > 1)
filename = argv[1];
printf("Logging to file %s\n", filename.c_str());
ArActionGroupRatioDriveUnsafe group(&robot);
group.activateExclusive();
robot.runAsync(true);
if(!laserConnector.connectLasers(false, false, true))
{
ArLog::log(ArLog::Terse, "sickLogger: Error: Could not connect to laser(s). Use -help to list options.");
Aria::exit(3);
}
// Allow some time for first set of laser reading to arrive
ArUtil::sleep(500);
// enable the motors, disable amigobot sounds
robot.comInt(ArCommands::SONAR, 0);
robot.comInt(ArCommands::ENABLE, 1);
robot.comInt(ArCommands::SOUND, 32);
robot.comInt(ArCommands::SOUNDTOG, 0);
// enable the joystick driving from the one connected to the microcontroller
robot.comInt(ArCommands::JOYDRIVE, 1);
// Create the logging object
// This must be created after the robot and laser are connected so it can get
// correct parameters from them.
// The third argmument is how far the robot must travel before a new laser
// scan is logged.
// The fourth argument is how many degrees the robot must rotate before a new
// laser scan is logged. The sixth boolean argument is whether to place a goal
// when the g or G key is pressed (by adding a handler to the global
// ArKeyHandler) or when the robots joystick button is
// pressed.
ArLaser *laser = robot.findLaser(1);
if(!laser)
{
ArLog::log(ArLog::Terse, "sickLogger: Error, not connected to any lasers.");
Aria::exit(2);
}
ArLaserLogger logger(&robot, laser, 300, 25, filename.c_str(), true);
// just hang out and wait for the end
robot.waitForRunExit();
Aria::exit(0);
}
示例11: main
int main(int argc, char **argv)
{
Aria::init();
ArSimpleConnector connector(&argc, argv);
ArRobot robot;
ArSick sick;
if (!Aria::parseArgs() || argc > 1)
{
Aria::logOptions();
Aria::exit(1); // exit program with error code 1
return 1;
}
ArKeyHandler keyHandler;
Aria::setKeyHandler(&keyHandler);
robot.attachKeyHandler(&keyHandler);
robot.addRangeDevice(&sick);
// Create the ArLineFinder object. Set it to log lots of information about its
// processing.
ArLineFinder lineFinder(&sick);
lineFinder.setVerbose(true);
// Add key callbacks that simply call the ArLineFinder::getLinesAndSaveThem()
// function, which searches for lines in the current set of laser sensor
// readings, and saves them in files with the names 'points' and 'lines'.
ArFunctorC<ArLineFinder> findLineCB(&lineFinder,
&ArLineFinder::getLinesAndSaveThem);
keyHandler.addKeyHandler('f', &findLineCB);
keyHandler.addKeyHandler('F', &findLineCB);
ArLog::log(ArLog::Normal, "lineFinderExample: connecting to robot...");
if (!connector.connectRobot(&robot))
{
printf("Could not connect to robot... exiting\n");
Aria::exit(1); // exit program with error code 1
return 1;
}
robot.runAsync(true);
// now set up the laser
ArLog::log(ArLog::Normal, "lineFinderExample: connecting to SICK laser...");
connector.setupLaser(&sick);
sick.runAsync();
if (!sick.blockingConnect())
{
printf("Could not connect to SICK laser... exiting\n");
Aria::exit(1);
return 1;
}
printf("If you press the 'f' key the points and lines found will be saved\n");
printf("Into the 'points' and 'lines' file in the current working directory\n");
robot.waitForRunExit();
Aria::exit(0);
return 0;
}
示例12: main
int main(int argc, char **argv)
{
Aria::init();
ArArgumentParser argParser(&argc, argv);
argParser.loadDefaultArguments();
ArRobot robot;
ArRobotConnector robotConnector(&argParser, &robot);
ArLaserConnector laserConnector(&argParser, &robot, &robotConnector);
if(!robotConnector.connectRobot())
{
ArLog::log(ArLog::Terse, "Could not connect to the robot.");
if(argParser.checkHelpAndWarnUnparsed())
{
// -help not given, just exit.
Aria::logOptions();
Aria::exit(1);
return 1;
}
}
// Trigger argument parsing
if (!Aria::parseArgs() || !argParser.checkHelpAndWarnUnparsed())
{
Aria::logOptions();
Aria::exit(1);
return 1;
}
ArKeyHandler keyHandler;
Aria::setKeyHandler(&keyHandler);
robot.attachKeyHandler(&keyHandler);
puts("This program will make the robot wander around. It uses some avoidance\n"
"actions if obstacles are detected, otherwise it just has a\n"
"constant forward velocity.\n\nPress CTRL-C or Escape to exit.");
ArSonarDevice sonar;
robot.addRangeDevice(&sonar);
robot.runAsync(true);
// try to connect to laser. if fail, warn but continue, using sonar only
if(!laserConnector.connectLasers())
{
ArLog::log(ArLog::Normal, "Warning: unable to connect to requested lasers, will wander using robot sonar only.");
}
// turn on the motors, turn off amigobot sounds
robot.enableMotors();
robot.comInt(ArCommands::SOUNDTOG, 0);
// add a set of actions that combine together to effect the wander behavior //działa
//general structure: robot.addAction (new Name_of_action (parameters), priority);
//to find out more about Actions go to ~/catkin_ws/src/rosaria/local/Aria/docs/index.html
// if we're stalled we want to back up and recover
robot.addAction(new ArActionStallRecover("stall recover", 100,50,100,30), 100); //basic values 225, 50, 150, 45
//when_stop, cycles_to_move, speed, turn'
//slow down when near obstacle
robot.addAction(new ArActionLimiterForwards("speed limiter near",
200, 200, 200), 95); // basic values 300,600,250
//stop_distance, slow_distance, slow_speed
// react to bumpers
robot.addAction(new ArActionLimiterBackwards, 75);
// turn avoid very close
robot.addAction(new ArActionAvoidFront("speed limiter far", 150,450,20), 47); //basic values 450, 200,15
//when_turn, speed, turn'
// turn avoid things near
robot.addAction(new ArActionAvoidFront("speed limiter far", 300,450,10), 46); //basic values 450, 200,15
//when_turn, speed, turn'
// turn avoid things further away
robot.addAction(new ArActionAvoidFront("speed limiter far", 800,450,5), 45); //basic values 450, 200,15
//when_turn, speed, turn'
//move forward
robot.addAction(new ArActionConstantVelocity("Constant Velocity", 500), 25);
// wait for robot task loop to end before exiting the program
robot.waitForRunExit();
Aria::exit(0);
return 0;
}
示例13: main
int main( int argc, char **argv ){
// parse our args and make sure they were all accounted for
ArSimpleConnector connector(&argc, argv);
ArRobot robot;
ArSick sick;
double dist, angle = 0;
// Allow for esc to release robot
ArKeyHandler keyHandler;
Aria::setKeyHandler(&keyHandler);
robot.attachKeyHandler(&keyHandler);
printf("You may press escape to exit\n");
if( !connector.parseArgs() || argc > 1 ){
connector.logOptions();
exit(1);
}
// add the laser to the robot
robot.addRangeDevice(&sick);
// try to connect, if we fail exit
if( !connector.connectRobot(&robot) ){
printf("Could not connect to robot... exiting\n");
Aria::shutdown();
return 1;
}
// start the robot running, true so that if we lose connection the run stops
robot.runAsync(true);
// now set up the laser
connector.setupLaser(&sick);
sick.runAsync();
if( !sick.blockingConnect() ){
printf("Could not connect to SICK laser... exiting\n");
Aria::shutdown();
return 1;
}
robot.comInt(ArCommands::ENABLE, 1);
ArPose pose(0, -1000, 0);
robot.moveTo(pose);
ArPose prev_pose = robot.getPose();
double total_distance = 0;
printf("Connected\n");
ArUtil::sleep(1000);
PathLog log("../Data/reactive.dat");
int iterations_wo_movement = 0;
while( iterations_wo_movement < CONSECUTIVE_NON_MOTIONS ){
// Get updated measurement
sick.lockDevice();
dist = sick.currentReadingPolar(-90, 90, &angle);
sick.unlockDevice();
dist = (dist > 30000) ? 0 : dist - IDEAL_DISTANCE;
trackRobot(&robot, dist, angle);
ArUtil::sleep(500);
pose = robot.getPose();
log.write(pose);
total_distance += getDistance(prev_pose, pose);
prev_pose = pose;
// Determine if the robot is done tracking
isRobotTracking(&iterations_wo_movement, dist, angle);
}
ArUtil::sleep(1000);
log.close();
ofstream output;
output.open("../Data/reactive_dist.dat", ios::out | ios::trunc);
output << "Reactive 1 " << total_distance << endl;
output.close();
Aria::exit(0);
return 0;
}
示例14: main
int main(int argc, char **argv)
{
Aria::init();
argc = 3;
argv[0] = "";
argv[1] = "-rp";
argv[2] = "/dev/ttyUSB0";
ArArgumentParser parser(&argc, argv);
parser.loadDefaultArguments();
ArRobot robot;
ArAnalogGyro gyro(&robot);
ArSonarDevice sonar;
ArRobotConnector robotConnector(&parser, &robot);
if(!robotConnector.connectRobot())
{
if(parser.checkHelpAndWarnUnparsed())
{
Aria::logOptions();
Aria::exit(1);
}
}
if (!Aria::parseArgs() || !parser.checkHelpAndWarnUnparsed())
{
Aria::logOptions();
Aria::exit(1);
}
imgdb.setRobot(&robot);
int Rc;
pthread_t slam_thread;
Rc = pthread_create(&slam_thread, NULL, slam_event, NULL);
if (Rc) { printf("Create slam thread failed!\n"); exit(-1); }
ImageList* current = NULL;
while (!current) current = imgdb.getEdge();
// current->person_point
robot.addRangeDevice(&sonar);
robot.runAsync(true);
ArKeyHandler keyHandler;
Aria::setKeyHandler(&keyHandler);
robot.attachKeyHandler(&keyHandler);
printf("You may press escape to exit\n");
robot.setAbsoluteMaxRotVel(30);
ArActionStallRecover recover;
ArActionBumpers bumpers;
double minDistance=10000;
// ArPose endPoint(point.x, point.z);
// current->collect_x
// current->collect_y
// robot.getX()
// robot.getY()
// current = imgdb.getEdge();
// for (int i = 0; i < current->edge.size(); i++) {
// for (int j = 0; j < current->edge[i].size() - 1; j++) {
// double dis = sqrt(pow(current->edge[i][j].z,2)+(pow(current->edge[i][j].x,2)));
// if(dis<minDistance){
// minDistance=dis;
// }
// }
// }
// 引入避障action,前方安全距离为500mm,侧边安全距离为340mm
Avoid avoidSide("Avoid side", ArPose(0, 0), 800, 100, 1000*minDistance);
robot.addAction(&recover, 100);
robot.addAction(&bumpers, 95);
robot.addAction(&avoidSide, 80);
ArActionStop stopAction("stop");
robot.addAction(&stopAction, 50);
robot.enableMotors();
robot.comInt(ArCommands::SOUNDTOG, 0);
const int duration = 500000;
bool first = true;
int goalNum = 0;
ArTime start;
start.setToNow();
while (Aria::getRunning())
{
current = imgdb.getEdge();
//.........这里部分代码省略.........
示例15: main
int main(int argc, char **argv)
{
int ret;
std::string str;
// the serial connection (robot)
ArSerialConnection serConn;
// tcp connection (sim)
ArTcpConnection tcpConn;
// the robot
ArRobot robot;
// the laser
ArSick sick;
// the laser connection
ArSerialConnection laserCon;
bool useSimForLaser = false;
std::string hostname = "prod.local.net";
// timeouts in minutes
int wanderTime = 0;
int restTime = 0;
// check arguments
if (argc == 3 || argc == 4)
{
wanderTime = atoi(argv[1]);
restTime = atoi(argv[2]);
if (argc == 4)
hostname = argv[3];
}
else
{
printf("\nUsage:\n\tpeoplebotTest <wanderTime> <restTime> <hostname>\n\n");
printf("Times are in minutes. Hostname is the machine to pipe the ACTS display to\n\n");
wanderTime = 15;
restTime = 45;
}
printf("Wander time - %d minutes\nRest time - %d minutes\n", wanderTime, restTime);
printf("Sending display to %s.\n\n", hostname.c_str());
// sonar, must be added to the robot
ArSonarDevice sonar;
// the actions we'll use to wander
ArActionStallRecover recover;
ArActionBumpers bumpers;
ArActionAvoidFront avoidFrontNear("Avoid Front Near", 225, 0);
ArActionAvoidFront avoidFrontFar;
// Make a key handler, so that escape will shut down the program
// cleanly
ArKeyHandler keyHandler;
// mandatory init
Aria::init();
// Add the key handler to Aria so other things can find it
Aria::setKeyHandler(&keyHandler);
// Attach the key handler to a robot now, so that it actually gets
// some processing time so it can work, this will also make escape
// exit
robot.attachKeyHandler(&keyHandler);
// First we see if we can open the tcp connection, if we can we'll
// assume we're connecting to the sim, and just go on... if we
// can't open the tcp it means the sim isn't there, so just try the
// robot
// modify this next line if you're not using default tcp connection
tcpConn.setPort();
// see if we can get to the simulator (true is success)
if (tcpConn.openSimple())
{
// we could get to the sim, so set the robots device connection to the sim
printf("Connecting to simulator through tcp.\n");
robot.setDeviceConnection(&tcpConn);
}
else
{
// we couldn't get to the sim, so set the port on the serial
// connection and then set the serial connection as the robots
// device
// modify the next line if you're not using the first serial port
// to talk to your robot
serConn.setPort();
printf(
"Could not connect to simulator, connecting to robot through serial.\n");
robot.setDeviceConnection(&serConn);
}
// add the sonar to the robot
//.........这里部分代码省略.........