Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include <rc_dynamics_api/remote_interface.h>
00037
00038 #include <signal.h>
00039
00040 #ifdef WIN32
00041 #include <winsock2.h>
00042 #undef min
00043 #undef max
00044 #endif
00045
00046 using namespace std;
00047 namespace rcdyn = rc::dynamics;
00048
00052 static bool caught_signal = false;
00053 void signal_callback_handler(int signum)
00054 {
00055 printf("Caught signal %d, stopping program!\n", signum);
00056 caught_signal = true;
00057 }
00058
00062 void printUsage(char* arg)
00063 {
00064 cout << "\nStarts rc_visard's dynamics and slam modules for a certain time "
00065 "\nperiod, retrieves the Slam trajectory and simply prints it to std out."
00066 << "\n\nUsage: \n"
00067 << arg << " -v <rcVisardIP> [-t <timePeriodSecs>]" << endl;
00068 }
00069
00070 int main(int argc, char* argv[])
00071 {
00072 #ifdef WIN32
00073 WSADATA wsaData;
00074 WSAStartup(MAKEWORD(2, 2), &wsaData);
00075 #endif
00076
00077
00078 signal(SIGINT, signal_callback_handler);
00079 signal(SIGTERM, signal_callback_handler);
00080
00084 string visardIP, networkIface = "", streamName = "";
00085 bool userSetIp = false;
00086 unsigned int maxTimeSecs = 5;
00087
00088 int i = 1;
00089 while (i < argc)
00090 {
00091 std::string p = argv[i++];
00092
00093 if (p == "-v" && i < argc)
00094 {
00095 visardIP = string(argv[i++]);
00096 userSetIp = true;
00097 }
00098 else if (p == "-t" && i < argc)
00099 {
00100 maxTimeSecs = (unsigned int)std::max(0, atoi(argv[i++]));
00101 }
00102 else if (p == "-h")
00103 {
00104 printUsage(argv[0]);
00105 return EXIT_SUCCESS;
00106 }
00107 else
00108 {
00109 printUsage(argv[0]);
00110 return EXIT_FAILURE;
00111 }
00112 }
00113 if (!userSetIp)
00114 {
00115 cerr << "Please specify rc_visard IP." << endl;
00116 printUsage(argv[0]);
00117 return EXIT_FAILURE;
00118 }
00119
00123 cout << "connecting rc_visard " << visardIP << "..." << endl;
00124 auto rcvisardDynamics = rcdyn::RemoteInterface::create(visardIP);
00125
00126 try
00127 {
00128
00129 cout << "starting rc_dynamics module with slam on rc_visard..." << endl;
00130 rcvisardDynamics->startSlam();
00131 }
00132 catch (exception& e)
00133 {
00134 cout << "ERROR! Could not start rc_dynamics module on rc_visard: " << e.what() << endl;
00135 return EXIT_FAILURE;
00136 }
00137
00141 cout << "running..." << endl;
00142
00143 #ifdef WIN32
00144 Sleep(1000 * maxTimeSecs);
00145 #else
00146 usleep(1000 * 1000 * maxTimeSecs);
00147 #endif
00148
00152 try
00153 {
00154 cout << "stopping rc_dynamics module on rc_visard..." << endl;
00155 rcvisardDynamics->stop();
00156
00157
00158 roboception::msgs::Trajectory traj = rcvisardDynamics->getSlamTrajectory();
00159 cout << "The full trajectory contains " << traj.poses().size() << " waypoints." << endl;
00160
00161
00162 traj = rcvisardDynamics->getSlamTrajectory(rc::TrajectoryTime::RelativeToEnd(1));
00163 cout << "The last second of the trajectory contains " << traj.poses().size() << " waypoints and looks like:" << endl
00164 << traj.DebugString() << endl;
00165 }
00166 catch (exception& e)
00167 {
00168 cout << "ERROR! Could not start rc_dynamics module on rc_visard: " << e.what() << endl;
00169 }
00170
00171 #ifdef WIN32
00172 ::WSACleanup();
00173 #endif
00174
00175 return EXIT_SUCCESS;
00176 }