//* NAV Course connection handler utility class - implementation file *

#include "nav_aria_chandler.h" #include <iostream> // The constructor, note the use of contructor chaining to initalize the callbacks. ConnHandler::ConnHandler(ArRobot *robot) : myRobot(robot), // set the robot pointer myConnectedCB(this, &ConnHandler::connected), myConnFailCB(this, &ConnHandler::connFail), myDisconnectedCB(this, &ConnHandler::disconnected), isOk(false) { // add the callbacks to the robot myRobot->addConnectCB(&myConnectedCB, ArListPos::FIRST); myRobot->addFailedConnectCB(&myConnFailCB, ArListPos::FIRST); myRobot->addDisconnectNormallyCB(&myDisconnectedCB, ArListPos::FIRST); myRobot->addDisconnectOnErrorCB(&myDisconnectedCB, ArListPos::FIRST); } // just exit if the connection failed void ConnHandler::connFail(void) { isOk=false; myRobot->stopRunning(); Aria::shutdown(); std::cerr << "Connection to the physical robot failed!" << std::endl; } // turn on motors and sonar when connected void ConnHandler::connected(void) { myRobot->enableMotors(); // enable motors myRobot->enableSonar(); // enable sonars isOk=true; } // lost connection, so just exit void ConnHandler::disconnected(void) { isOk=false; std::cerr << "Lost connection to the physical robot!" << std::endl; }