#include "Aria.h"
#include "ArNetworking.h"
#include "Arnl.h"
#include "ArLocalizationTask.h"
int main(int argc, char *argv[])
{
Aria::init();
Arnl::init();
ArRobot robot;
ArServerBase server;
ArArgumentParser parser(&argc, argv);
parser.loadDefaultArguments();
ArSimpleConnector simpleConnector(&parser);
ArServerSimpleOpener simpleOpener (&parser);
ArAnalogGyro gyro (&robot);
parser.loadDefaultArguments();
if (!Aria::parseArgs () || !parser.checkHelpAndWarnUnparsed())
{
Aria::logOptions ();
Aria::exit (1);
}
ArSick sick;
robot.addRangeDevice (&sick);
ArSonarDevice sonarDev;
robot.addRangeDevice (&sonarDev);
ArBumpers bumpers;
robot.addRangeDevice (&bumpers);
char fileDir[1024];
ArUtil::addDirectories (fileDir, sizeof (fileDir), Aria::getDirectory (),
"examples");
ArMap arMap (fileDir);
arMap.setIgnoreEmptyFileName (true);
ArLocalizationManager locManager(&robot, &arMap);
ArLocalizationTask locTask (&robot, &sick, &arMap);
locManager.addLocalizationTask(&locTask);
ArLog::addToConfig (Aria::getConfig ());
if (!simpleOpener.open (&server, fileDir, 240))
{
ArLog::log (ArLog::Normal, "Could not open server port");
exit (2);
}
if (!simpleConnector.connectRobot (&robot))
{
ArLog::log (ArLog::Normal, "Could not connect to robot... exiting");
Aria::exit (3);
}
robot.enableMotors ();
robot.clearDirectMotion ();
robot.com(ArCommands::SIM_RESET);
simpleConnector.setupLaser (&sick);
robot.runAsync (true);
sick.runAsync ();
if (!sick.blockingConnect ())
{
ArLog::log (ArLog::Normal, "Couldn't connect to laser, exiting");
Aria::exit (4);
}
ArUtil::sleep (300);
ArForbiddenRangeDevice forbidden (&arMap);
robot.addRangeDevice (&forbidden);
ArServerInfoRobot serverInfoRobot (&server, &robot);
ArServerInfoSensor serverInfoSensor (&server, &robot);
ArServerInfoLocalization serverInfoLocalization (&server, &robot, &locManager);
ArServerHandlerLocalization serverLocHandler (&server, &robot, &locManager);
ArServerHandlerMap serverMap (&server, &arMap);
ArServerInfoDrawings drawings (&server);
drawings.addRobotsRangeDevices (&robot);
ArServerHandlerCommands commands (&server);
ArServerSimpleComUC uCCommands (&commands, &robot);
ArServerSimpleComMovementLogging loggingCommands (&commands, &robot);
ArServerSimpleComGyro gyroCommands (&commands, &robot, &gyro);
ArServerSimpleComLogRobotConfig configCommands (&commands, &robot);
ArServerModeStop modeStop (&server, &robot);
modeStop.addAsDefaultMode ();
ArSonarAutoDisabler sonarAutoDisabler (&robot);
ArServerModeRatioDrive modeRatioDrive (&server, &robot);
modeRatioDrive.addControlCommands (&commands);
modeRatioDrive.addToConfig (Aria::getConfig (), "Teleop settings");
ArServerModeWander
modeWander (&server, &robot);
ArActionLost actionLostRatioDrive (&locManager, NULL, &modeRatioDrive);
modeRatioDrive.getActionGroup ()->addAction (&actionLostRatioDrive, 110);
ArActionLost
actionLostWander (&locManager, NULL, &modeWander);
modeWander.getActionGroup ()->addAction (&actionLostWander, 110);
ArServerInfoStrings
stringInfo (&server);
Aria::getInfoGroup ()->addAddStringCallback (stringInfo.
getAddStringFunctor ());
Aria::getInfoGroup ()->addStringDouble ("Localization Score", 8,
new ArRetFunctorC < double,
ArLocalizationTask > (&locTask,
&ArLocalizationTask::
getLocalizationScore),
"%.03f");
Aria::getInfoGroup ()->addStringInt ("Laser Packet Count", 10,
new ArRetFunctorC < int, ArSick > (&sick,
&ArSick::
getSickPacCount));
Aria::getInfoGroup ()->addStringInt ("Motor Packet Count", 10,
new ArConstRetFunctorC < int,
ArRobot > (&robot,
&ArRobot::getMotorPacCount));
ArServerHandlerConfig handlerConfig (&server, Aria::getConfig (),
Arnl::getTypicalDefaultParamFileName (),
Aria::getDirectory ());
Aria::getConfig ()->useArgumentParser (&parser);
if (!Aria::getConfig ()->parseFile (Arnl::getTypicalParamFileName ()))
{
ArLog::log (ArLog::Normal, "Trouble loading configuration file, exiting");
Aria::exit (5);
}
if (arMap.getFileName () == NULL || strlen (arMap.getFileName ()) <= 0)
{
ArLog::log(ArLog::Terse, "Warning, no map given. Use the -map command-line argument or modify the config using MobileEyes or by editing the parameter file.");
ArLog::log(ArLog::Terse, "See the documentation, including MAPPING.txt or SONAR_MAPPING.txt.");
}
ArLog::log (ArLog::Normal, "Directory for maps and file serving: %s", fileDir);
ArLog::log (ArLog::Normal, "See the README.txt for more information");
robot.unlock();
locTask.localizeRobotAtHomeBlocking();
server.runAsync();
ArLog::log(ArLog::Normal, "Server now running on port %d. Press Control-C to exit.", server.getTcpPort());
robot.waitForRunExit();
Aria::exit(0);
}