本文整理汇总了C++中ArServerBase::runAsync方法的典型用法代码示例。如果您正苦于以下问题:C++ ArServerBase::runAsync方法的具体用法?C++ ArServerBase::runAsync怎么用?C++ ArServerBase::runAsync使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArServerBase
的用法示例。
在下文中一共展示了ArServerBase::runAsync方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char **argv)
{
Aria::init();
ArGlobalFunctor2<ArServerClient *, ArNetPacket *> testCB(&testFunction);
ArGlobalFunctor2<ArServerClient *, ArNetPacket *> setVelCB(&setVelFunction);
ArServerBase server;
//ArLog::init(ArLog::StdOut, ArLog::Verbose);
ArNetPacket packet;
server.addData("test", "some wierd test", &testCB, "none", "none");
server.addData("test2", "another wierd test", &testCB, "none", "none");
server.addData("test3", "yet another wierd test", &testCB, "none", "none");
server.addData("SetVelRequest", "yet another wierd test", &setVelCB, "none", "none");
if (!server.open(7273))
{
printf("Could not open server port\n");
exit(1);
}
server.runAsync();
while (server.getRunningWithLock())
{
ArUtil::sleep(1000);
server.broadcastPacketTcp(&packet, "test3");
}
Aria::shutdown();
return 0;
}
示例2: main
int main(int argc, char **argv)
{
Aria::init();
ArServerBase robotServer;
if (!robotServer.open(5000))
{
printf("Could not open robot server port\n");
Aria::exit(1);
}
ArServerBase clientServer;
if (!clientServer.open(7272))
{
printf("Could not open robot server port\n");
Aria::exit(1);
}
ArCentralManager switchManager(&robotServer, &clientServer);
switchManager.addForwarderAddedCallback(
new ArGlobalFunctor1<ArCentralForwarder *>(&forwarderAdded),
100);
switchManager.addForwarderRemovedCallback(
new ArGlobalFunctor1<ArCentralForwarder *>(&forwarderRemoved),
100);
// Start a small handler to monitor communication between the server and
// client.
ArServerHandlerCommMonitor commMonitor(&clientServer);
ArServerHandlerCommands commands(&clientServer);
commands.setPrefix("CentralServer");
ArServerSimpleServerCommands serverCommands(&commands, &clientServer,
false);
commands.addCommand(
"NetworkLogConnections", "Logs the connections to the central server, and to all the forwarded connections",
new ArFunctorC<ArCentralManager>
(&switchManager, &ArCentralManager::logConnections));
clientServer.runAsync();
robotServer.run();
Aria::exit(0);
}
示例3: main
int main(int argc, char *argv[])
{
Aria::init();
ArVideo::init();
ArArgumentParser argParser(&argc, argv);
ArServerBase server;
ArServerSimpleOpener openServer(&argParser);
argParser.loadDefaultArguments();
if(!Aria::parseArgs() || !argParser.checkHelpAndWarnUnparsed()) {
Aria::logOptions();
Aria::exit(-1);
}
if(!openServer.open(&server))
{
std::cout << "error opening ArNetworking server" << std::endl;
Aria::exit(5);
return 5;
}
server.runAsync();
std::cout << "ArNetworking server running on port " << server.getTcpPort() << std::endl;
/* Set up ArNetworking services */
ArVideoRemoteForwarder forwarder(&server, "localhost", 7070);
if(!forwarder.connected())
{
std::cout << "ERror connecting to server localhost:7070" << std::endl;
Aria::exit(1);
}
std::cout << "ArNetworking server running on port " << server.getTcpPort() << std::endl;
while(true) ArUtil::sleep(10000);
Aria::exit(0);
return 0;
}
示例4: main
//.........这里部分代码省略.........
ArCameraCollection *cameraCollection = NULL;
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();
示例5: main
//.........这里部分代码省略.........
robot.addRangeDevice(&sonarDev);
ArIRs irs;
robot.addRangeDevice(&irs);
ArBumpers bumpers;
robot.addRangeDevice(&bumpers);
// a laser in case one is used
ArSick sick(361, 180);
// add the laser to the robot
robot.addRangeDevice(&sick);
// attach stuff to the server
ArServerInfoRobot serverInfoRobot(&server, &robot);
ArServerInfoSensor serverInfoSensor(&server, &robot);
ArServerInfoDrawings drawings(&server);
drawings.addRobotsRangeDevices(&robot);
// ways of moving the robot
ArServerModeStop modeStop(&server, &robot);
ArServerModeDrive modeDrive(&server, &robot);
ArServerModeRatioDrive modeRatioDrive(&server, &robot);
ArServerModeWander modeWander(&server, &robot);
modeStop.addAsDefaultMode();
modeStop.activate();
// set up the simple commands
ArServerHandlerCommands commands(&server);
// add the commands for the microcontroller
ArServerSimpleComUC uCCommands(&commands, &robot);
// add the commands for logging
ArServerSimpleComMovementLogging loggingCommands(&commands, &robot);
// add the commands for the gyro
ArServerSimpleComGyro gyroCommands(&commands, &robot, &gyro);
// add the commands to enable and disable safe driving to the simple commands
modeDrive.addControlCommands(&commands);
// Forward any video if we have some to forward.. this will forward
// from SAV or ACTS, you can find both on our website
// http://robots.activmedia.com, ACTS is for color tracking and is
// charged for but SAV just does software A/V transmitting and is
// free to all our customers... just run ACTS or SAV before you
// start this program and this class here will forward video from it
// to MobileEyes
ArHybridForwarderVideo videoForwarder(&server, "localhost", 7070);
// make a camera to use in case we have video
ArPTZ *camera = NULL;
ArServerHandlerCamera *handlerCamera = NULL;
// if we have video then set up a camera
if (videoForwarder.isForwardingVideo())
{
bool invertedCamera = false;
camera = new ArVCC4(&robot, invertedCamera,
ArVCC4::COMM_UNKNOWN, true, true);
camera->init();
handlerCamera = new ArServerHandlerCamera(&server, &robot, camera);
}
server.logCommandGroups();
server.logCommandGroupsToFile("userServerTest.commandGroups");
// now let it spin off in its own thread
server.runAsync();
// set up the robot for connecting
if (!simpleConnector.connectRobot(&robot))
{
printf("Could not connect to robot... exiting\n");
Aria::shutdown();
return 1;
}
// set up the laser before handing it to the laser mode
simpleConnector.setupLaser(&sick);
robot.enableMotors();
// start the robot running, true so that if we lose connection the run stops
robot.runAsync(true);
sick.runAsync();
// connect the laser if it was requested
if (!simpleConnector.connectLaser(&sick))
{
printf("Could not connect to laser... exiting\n");
Aria::shutdown();
return 1;
}
robot.waitForRunExit();
// now exit
Aria::shutdown();
exit(0);
}
示例6: main
//.........这里部分代码省略.........
else
ArLog::log(ArLog::Normal, "Could not open server port");
exit(2);
}
// Connect the robot
if (!simpleConnector.connectRobot(&robot))
{
ArLog::log(ArLog::Normal, "Could not connect to robot... exiting");
Aria::exit(3);
}
//-----------------------------------------------
//**************************
// Set up a class that'll put the movement and gyro parameters into ArConfig
ArRobotConfig robotConfig(&robot);
robotConfig.addAnalogGyro(&gyro);
//*****************************
robot.enableMotors();
robot.clearDirectMotion();
// if we are connected to a simulator, reset it to its start position
robot.comInt(ArCommands::RESETSIMTOORIGIN, 1);
robot.moveTo(ArPose(0,0,0));
// Set up laser using connector (command line arguments, etc.)
simpleConnector.setupLaser(&sick);
// Start the robot thread.
robot.runAsync(true);
// Start the laser thread.
sick.runAsync();
// Try to connect the laser
if (!sick.blockingConnect())
ArLog::log(ArLog::Normal, "Warning: Couldn't connect to SICK laser, it won't be used");
else
ArLog::log(ArLog::Normal, "Connected to laser.");
//***************************************
// Add additional range devices to the robot and path planning task.
// IRs if the robot has them.
robot.lock();
// ArIRs irs;
// robot.addRangeDevice(&irs);
// pathTask.addRangeDevice(&irs, ArPathPlanningTask::CURRENT);
//******************************************
// Forbidden regions from the map
ArForbiddenRangeDevice forbidden(&arMap);
robot.addRangeDevice(&forbidden);
// This is the place to add a range device which will hold sensor data
// and delete it appropriately to replan around blocked paths.
ArGlobalReplanningRangeDevice replanDev(&pathTask);
// Create objects that add network services:
// Drawing in the map display:
ArServerInfoDrawings drawings(&server);
示例7: main
int main ( int argc, char *argv[] ){
//cout << "running....\n";
try{
// Create the socket
ServerSocket server ( 30000 );
Aria::init();
Arnl::init();
ArRobot robot;
ArArgumentParser parser(&argc, argv);
parser.loadDefaultArguments();
ArSonarDevice sonar;
ArSimpleConnector simpleConnector(&parser);
// Our server for mobile eyes
ArServerBase moServer;
// Set up our simpleOpener
ArServerSimpleOpener simpleOpener(&parser);
parser.loadDefaultArguments();
if (!Aria::parseArgs () || !parser.checkHelpAndWarnUnparsed()){
Aria::logOptions ();
Aria::exit (1);
}
//Add the sonar to the robot
robot.addRangeDevice(&sonar);
// Look for map in the current directory
ArMap arMap;
// set it up to ignore empty file names (otherwise the parseFile
// on the config will fail)
arMap.setIgnoreEmptyFileName (true);
// First open the server
if (!simpleOpener.open(&moServer)){
if (simpleOpener.wasUserFileBad())
ArLog::log(ArLog::Normal, "Bad user file");
else
ArLog::log(ArLog::Normal, "Could not open server port");
exit(2);
}
// Connect to the robot
if (!simpleConnector.connectRobot (&robot)){
ArLog::log (ArLog::Normal, "Could not connect to robot... exiting");
Aria::exit (3);
}
// Create the localization task (it will start its own thread here)
ArSonarLocalizationTask locTask(&robot, &sonar, &arMap);
ArLocalizationManager locManager(&robot, &arMap);
ArLog::log(ArLog::Normal, "Creating sonar localization task");
locManager.addLocalizationTask(&locTask);
// Set the initial pose to the robot's "Home" position from the map, or
// (0,0,0) if none, then let the localization thread take over.
locTask.localizeRobotAtHomeNonBlocking();
//Create the path planning task
ArPathPlanningTask pathTask(&robot,&sonar,&arMap);
ArLog::log(ArLog::Normal, "Robot Server: Connected.");
robot.enableMotors();
robot.clearDirectMotion();
// Start the robot processing cycle running in the background.
// True parameter means that if the connection is lost, then the
// run loop ends.
robot.runAsync(true);
// Read in parameter files.
Aria::getConfig ()->useArgumentParser (&parser);
if (!Aria::getConfig ()->parseFile (Arnl::getTypicalParamFileName ())){
ArLog::log (ArLog::Normal, "Trouble loading configuration file, exiting");
Aria::exit (5);
}
//Create the three states
robot.lock();
Follow follow = Follow(&robot,&sonar);
GoTo goTo(&robot,&pathTask,&arMap);
Search s(&robot,&sonar);
// Bumpers.
ArBumpers bumpers;
robot.addRangeDevice(&bumpers);
pathTask.addRangeDevice(&bumpers, ArPathPlanningTask::CURRENT);
// Forbidden regions from the map
ArForbiddenRangeDevice forbidden(&arMap);
robot.addRangeDevice(&forbidden);
//.........这里部分代码省略.........
示例8: main
//.........这里部分代码省略.........
ArServerInfoRobot serverInfoRobot(&server, &robot);
ArServerInfoSensor serverInfoSensor(&server, &robot);
// This is the service that provides drawing data to the client.
ArServerInfoDrawings drawings(&server);
// Convenience function that sets up drawings for all the robot's current
// range devices (using default shape and color info)
drawings.addRobotsRangeDevices(&robot);
// Add our custom drawings
drawings.addDrawing(
// shape: color: size: layer:
new ArDrawingData("polyLine", ArColor(255, 0, 0), 2, 49),
"exampleDrawing_Home",
new ArGlobalFunctor2<ArServerClient*, ArNetPacket*>(&exampleHomeDrawingNetCallback)
);
drawings.addDrawing(
new ArDrawingData("polyDots", ArColor(0, 255, 0), 250, 48),
"exampleDrawing_Dots",
new ArGlobalFunctor2<ArServerClient*, ArNetPacket*>(&exampleDotsDrawingNetCallback)
);
drawings.addDrawing(
new ArDrawingData("polySegments", ArColor(0, 0, 0), 4, 52),
"exampleDrawing_XMarksTheSpot",
new ArGlobalFunctor2<ArServerClient*, ArNetPacket*>(&exampleXDrawingNetCallback)
);
drawings.addDrawing(
new ArDrawingData("polyArrows", ArColor(255, 0, 255), 500, 100),
"exampleDrawing_Arrows",
new ArGlobalFunctor2<ArServerClient*, ArNetPacket*>(&exampleArrowsDrawingNetCallback)
);
// modes for moving the robot
ArServerModeStop modeStop(&server, &robot);
ArServerModeDrive modeDrive(&server, &robot);
ArServerModeRatioDrive modeRatioDrive(&server, &robot);
ArServerModeWander modeWander(&server, &robot);
modeStop.addAsDefaultMode();
modeStop.activate();
// Connect to the robot.
if (!simpleConnector.connectRobot(&robot))
{
printf("Error: Could not connect to robot... exiting\n");
Aria::shutdown();
return 1;
}
// set up the laser before handing it to the laser mode
simpleConnector.setupLaser(&sick);
robot.enableMotors();
// start the robot cycle running in a background thread
robot.runAsync(true);
// start the laser processing cycle in a background thread
sick.runAsync();
// connect the laser if it was requested
if (!simpleConnector.connectLaser(&sick))
{
printf("Error: Could not connect to laser... exiting\n");
Aria::shutdown();
return 1;
}
// log whatever we wanted to before the runAsync
simpleOpener.checkAndLog();
// run the server thread in the background
server.runAsync();
printf("Server is now running...\n");
// Add a key handler mostly that windows can exit by pressing
// escape, note that the key handler prevents you from running this program
// in the background on Linux.
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");
}
robot.waitForRunExit();
Aria::shutdown();
exit(0);
}
示例9: main
int main(int argc, char **argv)
{
// Initialize Aria and Arnl global information
Aria::init();
Arnl::init();
// The robot object
ArRobot robot;
// Parse the command line arguments.
ArArgumentParser parser(&argc, argv);
// Set up our simpleConnector, to connect to the robot and laser
//ArSimpleConnector simpleConnector(&parser);
ArRobotConnector robotConnector(&parser, &robot);
// Connect to the robot
if (!robotConnector.connectRobot())
{
ArLog::log(ArLog::Normal, "Error: Could not connect to robot... exiting");
Aria::exit(3);
}
// Set up where we'll look for files. Arnl::init() set Aria's default
// directory to Arnl's default directory; addDirectories() appends this
// "examples" directory.
char fileDir[1024];
ArUtil::addDirectories(fileDir, sizeof(fileDir), Aria::getDirectory(),
"examples");
// To direct log messages to a file, or to change the log level, use these calls:
//ArLog::init(ArLog::File, ArLog::Normal, "log.txt", true, true);
//ArLog::init(ArLog::File, ArLog::Verbose);
// Add a section to the configuration to change ArLog parameters
ArLog::addToConfig(Aria::getConfig());
// set up a gyro (if the robot is older and its firmware does not
// automatically incorporate gyro corrections, then this object will do it)
ArAnalogGyro gyro(&robot);
// Our networking server
ArServerBase server;
// Set up our simpleOpener, used to set up the networking server
ArServerSimpleOpener simpleOpener(&parser);
// the laser connector
ArLaserConnector laserConnector(&parser, &robot, &robotConnector);
// Tell the laser connector to always connect the first laser since
// this program always requires a laser.
parser.addDefaultArgument("-connectLaser");
// Load default arguments for this computer (from /etc/Aria.args, environment
// variables, and other places)
parser.loadDefaultArguments();
// Parse arguments
if (!Aria::parseArgs() || !parser.checkHelpAndWarnUnparsed())
{
logOptions(argv[0]);
Aria::exit(1);
}
// This causes Aria::exit(9) to be called if the robot unexpectedly
// disconnects
ArGlobalFunctor1<int> shutdownFunctor(&Aria::exit, 9);
robot.addDisconnectOnErrorCB(&shutdownFunctor);
// Create an ArSonarDevice object (ArRangeDevice subclass) and
// connect it to the robot.
ArSonarDevice sonarDev;
robot.addRangeDevice(&sonarDev);
// This object will allow robot's movement parameters to be changed through
// a Robot Configuration section in the ArConfig global configuration facility.
ArRobotConfig robotConfig(&robot);
// Include gyro configuration options in the robot configuration section.
robotConfig.addAnalogGyro(&gyro);
// Start the robot thread.
robot.runAsync(true);
// connect the laser(s) if it was requested, this adds them to the
// robot too, and starts them running in their own threads
if (!laserConnector.connectLasers())
{
ArLog::log(ArLog::Normal, "Could not connect to all lasers... exiting\n");
//.........这里部分代码省略.........
示例10: main
int main(int argc, char **argv)
{
Aria::init();
ArServerBase server;
ArArgumentParser parser(&argc, argv);
ArServerSimpleOpener simpleOpener(&parser);
// parse the command line... fail and print the help if the parsing fails
// or if help was requested
parser.loadDefaultArguments();
if (!simpleOpener.parseArgs() || !parser.checkHelpAndWarnUnparsed())
{
simpleOpener.logOptions();
exit(1);
}
// first open the server up
if (!simpleOpener.open(&server))
{
if (simpleOpener.wasUserFileBad())
printf("Error: Bad user/password/permissions file.\n");
else
printf("Error: Could not open server port. Use -help to see options.\n");
exit(1);
}
// This is the service that provides drawing data to the client.
ArServerInfoDrawings drawings(&server);
// Add our custom drawings
drawings.addDrawing(
// shape: color: size: layer:
new ArDrawingData("polyLine", ArColor(255, 0, 0), 2, 49),
"exampleDrawing_Home",
new ArGlobalFunctor2<ArServerClient*, ArNetPacket*>(&exampleHomeDrawingNetCallback)
);
drawings.addDrawing(
new ArDrawingData("polyDots", ArColor(0, 255, 0), 250, 48),
"exampleDrawing_Dots",
new ArGlobalFunctor2<ArServerClient*, ArNetPacket*>(&exampleDotsDrawingNetCallback)
);
drawings.addDrawing(
new ArDrawingData("polySegments", ArColor(0, 0, 0), 4, 52),
"exampleDrawing_XMarksTheSpot",
new ArGlobalFunctor2<ArServerClient*, ArNetPacket*>(&exampleXDrawingNetCallback)
);
drawings.addDrawing(
new ArDrawingData("polyArrows", ArColor(255, 0, 255), 500, 100),
"exampleDrawing_Arrows",
new ArGlobalFunctor2<ArServerClient*, ArNetPacket*>(&exampleArrowsDrawingNetCallback)
);
Circle circle(&drawings, "exampleDrawing_circle",
new ArDrawingData("polySegments", ArColor(255, 150, 0), 3, 120));
circle.setPos(ArPose(0, -5000));
circle.setRadius(1000);
circle.setNumPoints(360);
// log whatever we wanted to before the runAsync
simpleOpener.checkAndLog();
// run the server thread in the background
server.runAsync();
printf("Server is now running...\n");
// Add a key handler mostly that windows can exit by pressing
// escape, note that the key handler prevents you from running this program
// in the background on Linux.
ArKeyHandler *keyHandler;
if ((keyHandler = Aria::getKeyHandler()) == NULL)
{
keyHandler = new ArKeyHandler;
Aria::setKeyHandler(keyHandler);
printf("To exit, press escape.\n");
}
double circleRadius = 1000;
while(true)
{
ArUtil::sleep(100);
circleRadius += 50;
if(circleRadius > 5000)
circleRadius = 0;
circle.setRadius(circleRadius);
}
Aria::shutdown();
exit(0);
}
示例11: main
int main(int argc, char **argv)
{
Aria::init();
ArRobot robot;
ArArgumentParser parser(&argc, argv);
ArSimpleConnector simpleConnector(&parser);
// The base server object, manages all connections to clients.
ArServerBase server;
// This object simplifies configuration and opening of the ArServerBase
// object.
ArServerSimpleOpener simpleOpener(&parser);
// parse the command line. fail and print the help if the parsing fails
// or if the help was requested with -help
parser.loadDefaultArguments();
if (!simpleConnector.parseArgs() || !simpleOpener.parseArgs() ||
!parser.checkHelpAndWarnUnparsed())
{
simpleConnector.logOptions();
simpleOpener.logOptions();
exit(1);
}
// Use the ArSimpleOpener to open the server port
if (!simpleOpener.open(&server))
{
ArLog::log(ArLog::Terse, "Error: Could not open server on port %d", simpleOpener.getPort());
exit(1);
}
//
// Create services attached to the base server:
//
// Robot position etc.:
ArServerInfoRobot serverInfoRobot(&server, &robot);
// Robot control modes (only one mode can be active at once):
ArServerModeStop modeStop(&server, &robot);
// old ArServerModeDrive modeDrive(&server, &robot);
ArServerModeRatioDrive modeRatioDrive(&server, &robot);
ArServerModeWander modeWander(&server, &robot);
modeStop.addAsDefaultMode();
modeStop.activate();
// This provides a simple way to add new commands.
ArServerHandlerCommands commands(&server);
// Add our custom command. ArServerHandlerCommands also has other methods
// for adding commands taht take different kinds of arguments, or no
// arguments.
ArGlobalFunctor1<ArArgumentBuilder*> customCommandFunctor(&customCommandHandler);
commands.addStringCommand("ExampleCustomCommand", "Example of a custom command. simpleServerExample will print out the text sent with the command.", &customCommandFunctor);
// These objects provide various debugging and diagnostic custom commands:
ArServerSimpleComUC uCCommands(&commands, &robot); // Get information about the robot
ArServerSimpleComMovementLogging loggingCommands(&commands, &robot); // Control logging
modeRatioDrive.addControlCommands(&commands); // Drive mode diagnostics
// This provides the client (e.g. MobileEyes) with a simple table of string values
// (called an InfoGroup). An InfoGroup is kept globally by Aria.
// The values in the table sent to clients are retrieved periodically by calling a
// functor.
ArServerInfoStrings stringInfo(&server);
Aria::getInfoGroup()->addAddStringCallback(stringInfo.getAddStringFunctor());
// Here are some example entries in the InfoGroup:
Aria::getInfoGroup()->addStringInt(
"Motor Packet Count", 10,
new ArConstRetFunctorC<int, ArRobot>(&robot,
&ArRobot::getMotorPacCount));
//
// Connect to the robot:
//
if (!simpleConnector.connectRobot(&robot))
{
printf("Error: Could not connect to robot... exiting\n");
Aria::shutdown();
return 1;
}
robot.enableMotors();
robot.runAsync(true);
// The simple opener might have information to display right before starting
// the server thread:
simpleOpener.checkAndLog();
// now let the server base run in a new thread, accepting client connections.
server.runAsync();
ArLog::log(ArLog::Normal, "Server is now running... Press Ctrl-C to exit.");
robot.waitForRunExit();
//.........这里部分代码省略.........
示例12: main
int main(int argc, char **argv)
{
Aria::init();
ArRobot robot;
ArSonarDevice sonar;
ArSick sick;
robot.addRangeDevice(&sonar);
ArServerBase server;
// Argument parser:
ArArgumentParser parser(&argc, argv);
parser.loadDefaultArguments();
// Connector and server opener:
ArRobotConnector robotConnector(&parser, &robot);
if(!robotConnector.connectRobot())
{
ArLog::log(ArLog::Terse, "popupExample: Could not connect to the robot.");
if(parser.checkHelpAndWarnUnparsed())
{
Aria::logOptions();
}
Aria::exit(1);
}
ArLaserConnector laserConnector(&parser, &robot, &robotConnector);
ArServerSimpleOpener simpleOpener(&parser);
// Get command-line and other parameters
if(!Aria::parseArgs() || !parser.checkHelpAndWarnUnparsed())
{
Aria::logOptions();
Aria::exit(1);
}
robot.runAsync(true);
// connect to the laser
if(!laserConnector.connectLasers())
{
ArLog::log(ArLog::Normal, "popupExample: Warning: Could not connect to lasers.");
}
// Open the server
if(!simpleOpener.open(&server))
{
ArLog::log(ArLog::Terse, "popupExample: Error, could not open server.");
return 1;
}
server.runAsync();
ArLog::log(ArLog::Normal, "popupExample: Server running. Press control-C to exit.");
ArLog::log(ArLog::Normal, "popupExample: Each time an obstacle is detected near the robot, a new popup message will be created. Connect with MobileEyes to see them.");
// Sends robot position etc.
ArServerInfoRobot robotInfoServer(&server, &robot);
// This service sends drawings e.g. showing range device positions
ArServerInfoDrawings drawingsServer(&server);
drawingsServer.addRobotsRangeDevices(&robot);
// This service can send messages to clients to display as popup dialogs:
ArServerHandlerPopup popupServer(&server);
// This object contains the robot sensor interpretation task and creates
// popups:
SensorDetectPopup(&robot, &popupServer);
// modes for controlling robot movement
ArServerModeStop modeStop(&server, &robot);
ArServerModeRatioDrive modeRatioDrive(&server, &robot);
ArServerModeWander modeWander(&server, &robot);
modeStop.addAsDefaultMode();
modeStop.activate();
// allow configuration of driving and other settings
ArServerHandlerConfig serverHandlerConfig(&server, Aria::getConfig()); // make a config handler
ArLog::addToConfig(Aria::getConfig()); // let people configure logging
modeRatioDrive.addToConfig(Aria::getConfig(), "Teleop settings"); // able to configure teleop settings
robot.enableMotors();
robot.waitForRunExit();
Aria::exit(0);
}
示例13: main
//.........这里部分代码省略.........
// Load default arguments for this computer (from /etc/Aria.args, environment
// variables, and other places)
parser.loadDefaultArguments();
// Parse arguments
if (!Aria::parseArgs() || !parser.checkHelpAndWarnUnparsed())
{
logOptions(argv[0]);
Aria::exit(1);
}
// This causes Aria::exit(9) to be called if the robot unexpectedly
// disconnects
ArGlobalFunctor1<int> shutdownFunctor(&Aria::exit, 9);
robot.addDisconnectOnErrorCB(&shutdownFunctor);
// Create an ArSonarDevice object (ArRangeDevice subclass) and
// connect it to the robot.
ArSonarDevice sonarDev;
robot.addRangeDevice(&sonarDev);
// This object will allow robot's movement parameters to be changed through
// a Robot Configuration section in the ArConfig global configuration facility.
ArRobotConfig robotConfig(&robot);
// Include gyro configuration options in the robot configuration section.
robotConfig.addAnalogGyro(&gyro);
// Start the robot thread.
robot.runAsync(true);
#ifdef ARNL_GPSLOC
// On the Seekur, power to the GPS receiver is switched on by this command.
// (A third argument of 0 would turn it off). On other robots this command is
// ignored. If this fails, you may need to reset the port with ARIA demo or
// seekurPower program (turn port off then on again). If the port is already
// on, it will have no effect on the GPS (it will remain powered.)
// Do this now before connecting to lasers to give it plenty of time to power
// on, initialize, and find a good position before GPS localization begins.
ArLog::log(ArLog::Normal, "Turning on GPS power... (Seekur/Seekur Jr. power port 6)");
robot.com2Bytes(116, 6, 1);
#endif
#ifdef ARNL_LASER
// connect the laser(s) if it was requested, this adds them to the
// robot too, and starts them running in their own threads
ArLog::log(ArLog::Normal, "Connecting to laser(s) configured in parameters...");
if (!laserConnector.connectLasers())
{
ArLog::log(ArLog::Normal, "Error: Could not connect to laser(s). Exiting.");
Aria::exit(2);
}
ArLog::log(ArLog::Normal, "Done connecting to laser(s).");
#endif
#if defined(ARNL_LASERLOC) || defined(ARNL_MAPPING)
// find the laser we should use for localization and/or mapping,
// which will be the first laser
robot.lock();
ArLaser *firstLaser = robot.findLaser(1);
if (firstLaser == NULL || !firstLaser->isConnected())