本文整理汇总了C++中ArRobot::addDisconnectOnErrorCB方法的典型用法代码示例。如果您正苦于以下问题:C++ ArRobot::addDisconnectOnErrorCB方法的具体用法?C++ ArRobot::addDisconnectOnErrorCB怎么用?C++ ArRobot::addDisconnectOnErrorCB使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArRobot
的用法示例。
在下文中一共展示了ArRobot::addDisconnectOnErrorCB方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(void)
{
int ret;
std::string str;
CBTest cbTest;
ArFunctorC<CBTest> connectCB(&cbTest, &CBTest::connected);
ArFunctorC<CBTest> failedConnectCB(&cbTest, &CBTest::failedConnect);
ArFunctorC<CBTest> disconnectCB(&cbTest, &CBTest::disconnected);
ArFunctorC<CBTest> disconnectErrorCB(&cbTest, &CBTest::disconnectedError);
ArSerialConnection con;
ArRobot robot;
printf("If a robot is attached to your port you should see:\n");
printf("Failed connect, Connected, Disconnected Error, Connected, Disconnected\n");
printf("If no robot is attached you should see:\n");
printf("Failed connect, Failed connect, Failed connect\n");
printf("-------------------------------------------------------\n");
ArLog::init(ArLog::None, ArLog::Terse);
srand(time(NULL));
robot.setDeviceConnection(&con);
robot.addConnectCB(&connectCB, ArListPos::FIRST);
robot.addFailedConnectCB(&failedConnectCB, ArListPos::FIRST);
robot.addDisconnectNormallyCB(&disconnectCB, ArListPos::FIRST);
robot.addDisconnectOnErrorCB(&disconnectErrorCB, ArListPos::FIRST);
// this should fail since there isn't an open port yet
robot.blockingConnect();
if ((ret = con.open()) != 0)
{
str = con.getOpenMessage(ret);
printf("Open failed: %s\n", str.c_str());
exit(0);
}
robot.blockingConnect();
con.close();
robot.loopOnce();
if ((ret = con.open()) != 0)
{
str = con.getOpenMessage(ret);
printf("Open failed: %s\n", str.c_str());
exit(0);
}
robot.blockingConnect();
robot.disconnect();
exit(0);
}
示例2: 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");
//.........这里部分代码省略.........
示例3: main
//.........这里部分代码省略.........
ArLaserConnector laserConnector(&parser, &robot, &robotConnector);
#endif
// used to connect to camera PTZ control
ArPTZConnector ptzConnector(&parser, &robot);
#ifdef ARNL_MULTIROBOT
// Used to connect to a "central server" which can be used as a proxy
// for multiple robot servers, and as a way for them to also communicate with
// each other. (objects implementing some of these inter-robot communication
// features are created below).
// NOTE: If the central server is running on the same host as robot server(s),
// then you must use the -serverPort argument to instruct these robot-control
// server(s) to use different ports than the default 7272, since the central
// server will use that port.
ArClientSwitchManager clientSwitch(&server, &parser);
#endif
// 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