int main(int argc, char **argv) { std::string str; int ret; // connection to the robot ArTcpConnection con; // the robot ArRobot robot; // ake the joydrive object, which also creates its own thread Joydrive joyd(&robot); // the connection handler ConnHandler ch(&robot, &joyd); // init aria, which will make a dedicated signal handling thread Aria::init(Aria::SIGHANDLE_THREAD); // open the connection with default args, exit if it fails if ((ret = con.open()) != 0) { str = con.getOpenMessage(ret); printf("Open failed: %s\n", str.c_str()); Aria::shutdown(); return 1; } // set the connection on the robot robot.setDeviceConnection(&con); // run the robot in its own thread robot.runAsync(false); // have the robot connect asyncronously (so its loop is still running) // if this fails it means that the robot isn't running in its own thread if (!robot.asyncConnect()) { printf( "asyncConnect failed because robot is not running in its own thread.\n"); Aria::shutdown(); return 1; } // now we just wait for the robot to be done running printf("Waiting for the robot's run to exit.\n"); robot.waitForRunExit(); // then we exit printf("exiting main\n"); Aria::exit(0); // exit program return 0; }
int main(int argc, char **argv) { // just some stuff for returns std::string str; int ret; // robots connection ArSerialConnection con; // the robot, this turns state reflection off ArRobot robot(NULL, false); // the joydrive as defined above, this also adds itself as a user task Joydrive joyd(&robot); // mandatory init Aria::init(); // open the connection, if it fails, exit if ((ret = con.open()) != 0) { str = con.getOpenMessage(ret); printf("Open failed: %s\n", str.c_str()); Aria::shutdown(); return 1; } // set the connection o nthe robot robot.setDeviceConnection(&con); // connect, if we fail, exit if (!robot.blockingConnect()) { printf("Could not connect to robot... exiting\n"); Aria::shutdown(); return 1; } // turn off the sonar, enable the motors, turn off amigobot sounds robot.comInt(ArCommands::SONAR, 0); robot.comInt(ArCommands::ENABLE, 1); robot.comInt(ArCommands::SOUNDTOG, 0); // run, if we lose connection to the robot, exit robot.run(true); // shutdown and go away Aria::shutdown(); return 0; }
int main(int argc, char **argv) { std::string str; int ret; // connection ArTcpConnection con; // robot, this starts it with state reflecting turned off ArRobot robot(NULL, false); // make the joydrive instance, which adds its task to the robot Joydrive joyd(&robot); // mandatory aria initialization Aria::init(); // open the connection, if it fails, exit if ((ret = con.open()) != 0) { str = con.getOpenMessage(ret); printf("Open failed: %s\n", str.c_str()); Aria::exit(1); return 1; } // set the robots connection robot.setDeviceConnection(&con); // try to connect, if we fail exit if (!robot.blockingConnect()) { printf("Could not connect to robot... exiting\n"); Aria::exit(1); return 1; } // turn off sonar, turn the motors on, turn off amigobot sound robot.comInt(ArCommands::SONAR, 0); robot.comInt(ArCommands::ENABLE, 1); robot.comInt(ArCommands::SOUNDTOG, 0); // run the robot, true so that if connection is lost the run stops robot.run(true); // now exit Aria::exit(0); // exit program return 0; }
int main(int argc, char **argv) { std::string str; int ret; int num; ArPose pose; Aria::init(); if (argc != 2) { printf("Usage is '%s <num>' where <num> is one of:\n", argv[0]); printf("1 Moves the robot back to the origin.\n"); printf("2 Moves the robot +1 meter in X direction.\n"); printf("3 Does a transform test, going from the origin to robot and back.\n"); printf("4 Does a transform test with a point 1 meter to the -x from the robot (ie left).\n"); printf("5 Does a transform, prints out sonar plar reading before and after.\n"); printf("6 Disconnects the robot, and reconnects to it.\n"); exit(1); } num = atoi(argv[1]); ArTcpConnection con; ArRobot robot(NULL, false); Joydrive joyd(&robot, num); ArFunctorC<Joydrive> driveCB(&joyd, &Joydrive::drive); ArSonarDevice sonar; if ((ret = con.open()) != 0) { str = con.getOpenMessage(ret); printf("Open failed: %s\n", str.c_str()); Aria::shutdown(); return 1; } robot.addUserTask("joydrive", 50, &driveCB); robot.addRangeDevice(&sonar); robot.setDeviceConnection(&con); pose.setPose(4000, 2000, 90); robot.moveTo(pose); pose = robot.getPose(); printf("Position set to, before connect.\n"); pose.log(); if (!robot.blockingConnect()) { printf("Could not connect to robot... exiting\n"); Aria::shutdown(); return 1; } pose = robot.getPose(); printf("Position robot at, after connect.\n"); pose.log(); //printf("Position being reset to 0.\n"); //pose.setPose(0, 0, 0); //robot.moveTo(pose); //robot.comInt(ArCommands::SONAR, 0); robot.comInt(ArCommands::ENABLE, 1); robot.comInt(ArCommands::SOUNDTOG, 0); robot.run(true); Aria::shutdown(); return 0; }