59 printf(
"Caught signal %d, stopping program!\n", signum);
68 cout <<
"\nLists available rcdynamics data streams of the specified rc_visard IP, " 69 "\nor requests a data stream and either prints received messages or records " 70 "\nthem as csv-file, see -o option." 72 << arg <<
" -v <rcVisardIP> -l | -s <stream> [-a] [-i <networkInterface>]" 73 " [-n <maxNumData>][-t <maxRecTimeSecs>][-o <output_file>]" 77 int main(
int argc,
char* argv[])
81 WSAStartup(MAKEWORD(2, 2), &wsaData);
91 string out_file_name, visard_ip, network_iface =
"", stream_name;
92 unsigned int max_num_recording = 50, max_secs_recording = 5;
93 bool user_autostart =
false;
94 bool user_set_out_file =
false;
95 bool user_set_max_num_msgs =
false;
96 bool user_set_max_recording_time =
false;
97 bool user_set_ip =
false;
98 bool user_set_stream_type =
false;
99 bool only_list_streams =
false;
104 std::string p = argv[i++];
108 only_list_streams =
true;
110 else if (p ==
"-s" && i < argc)
112 stream_name = string(argv[i++]);
113 user_set_stream_type =
true;
117 user_autostart =
true;
119 else if (p ==
"-i" && i < argc)
121 network_iface = string(argv[i++]);
123 else if (p ==
"-v" && i < argc)
125 visard_ip = string(argv[i++]);
128 else if (p ==
"-n" && i < argc)
130 max_num_recording = (
unsigned int)std::max(0, atoi(argv[i++]));
131 user_set_max_num_msgs =
true;
133 else if (p ==
"-t" && i < argc)
135 max_secs_recording = (
unsigned int)std::max(0, atoi(argv[i++]));
136 user_set_max_recording_time =
true;
138 else if (p ==
"-o" && i < argc)
140 out_file_name = string(argv[i++]);
141 user_set_out_file =
true;
157 cerr <<
"Please specify rc_visard IP." << endl;
162 if (!user_set_stream_type && !only_list_streams)
164 cerr <<
"Please specify stream type." << endl;
169 if (!user_set_max_num_msgs && !user_set_max_recording_time)
171 user_set_max_num_msgs =
true;
177 ofstream output_file;
178 if (user_set_out_file)
180 output_file.open(out_file_name);
181 if (!output_file.is_open())
183 cerr <<
"Could not open file '" << out_file_name <<
"' for writing!" << endl;
191 cout <<
"connecting to rc_visard " << visard_ip <<
"..." << endl;
192 auto rc_dynamics = RemoteInterface::create(visard_ip);
196 cout <<
"... system not yet ready. Trying again." << endl;
203 cout <<
"... connected!" << endl;
204 }
catch (exception &e) {
205 cout <<
"ERROR! Could not connect to rc_dynamics module on rc_visard: " << e.what() << endl;
210 if (only_list_streams)
212 auto streams = rc_dynamics->getAvailableStreams();
213 string first_column =
"Available streams:";
214 size_t first_column_width = first_column.length();
215 for (
auto&& s : streams)
216 if (s.length() > first_column_width)
217 first_column_width = s.length();
218 first_column_width += 5;
219 cout << left << setw(first_column_width) << first_column <<
"Protobuf message types:" << endl;
220 for (
auto&& s : streams)
221 cout << left << setw(first_column_width) << s << rc_dynamics->getPbMsgTypeOfStream(s) << endl;
223 cout << endl <<
"rc_dynamics is in state: " << rc_dynamics->getDynamicsState();
224 cout << endl <<
"rc_slam is in state: " << rc_dynamics->getSlamState();
225 cout << endl <<
"rc_stereo_ins is in state: " << rc_dynamics->getStereoInsState() << endl;
228 auto cam2imu = rc_dynamics->getCam2ImuTransform();
229 cout << endl <<
"cam2imu transformation: " << endl << cam2imu.DebugString();
231 cout << endl <<
"WARN: Could not retrieve cam2imu transformation from rc_visard. Feature is not available in that image version." << endl;
232 }
catch (std::exception &e) {
233 cout << endl <<
"ERROR: Could not retrieve cam2imu transformation from rc_visard: " << e.what() << endl;
240 if (user_autostart && stream_name !=
"imu")
244 cout <<
"starting SLAM on rc_visard..." << endl;
245 rc_dynamics->startSlam();
252 cout <<
"SLAM not available!" << endl;
253 cout <<
"starting stereo INS on rc_visard..." << endl;
254 rc_dynamics->start();
258 cout <<
"ERROR! Could not start rc_dynamics module on rc_visard: " << e.what() << endl;
267 unsigned int cnt_msgs = 0;
270 cout <<
"Initializing " << stream_name <<
" data stream..." << endl;
271 auto receiver = rc_dynamics->createReceiverForStream(stream_name, network_iface);
273 unsigned int timeout_millis = 100;
274 receiver->setTimeout(timeout_millis);
275 cout <<
"Listening for " << stream_name <<
" messages..." << endl;
277 chrono::time_point<chrono::system_clock> start = chrono::system_clock::now();
278 chrono::duration<double> elapsed_secs(0);
279 while (!
caught_signal && (!user_set_max_num_msgs || cnt_msgs < max_num_recording) &&
280 (!user_set_max_recording_time || elapsed_secs.count() < max_secs_recording))
282 auto msg = receiver->receive(rc_dynamics->getPbMsgTypeOfStream(stream_name));
285 if (output_file.is_open())
290 output_file << (h << *msg) << endl;
293 output_file << (l << *msg) << endl;
297 cout <<
"received " << stream_name <<
" msg:" << endl << msg->DebugString() << endl;
303 cerr <<
"did not receive any data during last " << timeout_millis <<
" ms." << endl;
305 elapsed_secs = chrono::system_clock::now() - start;
310 cout <<
"Caught exception during streaming, stopping: " << e.what() << endl;
317 if (user_autostart && stream_name !=
"imu")
321 cout <<
"stopping rc_dynamics module on rc_visard..." << endl;
326 cout <<
"Caught exception: " << e.what() << endl;
330 if (output_file.is_open())
333 cout <<
"Recorded " << cnt_msgs <<
" " << stream_name <<
" messages to '" << out_file_name <<
"'." << endl;
337 cout <<
"Received " << cnt_msgs <<
" " << stream_name <<
" messages." << endl;
void printUsage(char *arg)
Print usage of example including command line args.
void signal_callback_handler(int signum)
static bool caught_signal
catching signals for proper program escape
int main(int argc, char *argv[])
struct and methods to "organice" printing of csv-Lines
Thrown if a REST API call is rejected because of 404; i.e. URL not found.