//! main int main(int argc, char *argv[]) { #ifdef WINDOWS_OS const char device[] = "COM3"; #else const char device[] = "/dev/ttyACM0"; #endif UrgDevice urg; if (! urg.connect(device)) { printf("UrgDevice::connect: %s\n", urg.what()); exit(1); } vector<string> lines; // Receive version information urg.versionLines(lines); if (lines.empty()) { cerr << "UrgDevice::versionLines: " << urg.what() << endl; exit(1); } // Display for (vector<string>::iterator it = lines.begin(); it != lines.end(); ++it) { cout << *it << endl; } #ifdef MSC getchar(); #endif return 0; }
//! main int main(int argc, char *argv[]) { // Change the port name appropriately #ifdef WINDOWS_OS const char device[] = "COM3"; #else const char device[] = "/dev/ttyACM0"; #endif UrgDevice urg; if (! urg.connect(device)) { printf("UrgDevice::connect: %s\n", urg.what()); exit(1); } // Display parameter information RangeSensorParameter parameters = urg.parameter(); printf("model: %s\n", parameters.model.c_str()); printf("distance_min: %ld\n", parameters.distance_min); printf("distance_max: %ld\n", parameters.distance_max); printf("area_total: %d\n", parameters.area_total); printf("area_min: %d\n", parameters.area_min); printf("area_max: %d\n", parameters.area_max); printf("area_front: %d\n", parameters.area_front); printf("scan_rpm: %d\n", parameters.scan_rpm); #ifdef MSC getchar(); #endif return 0; }
void connect() { qrk::LockGuard guard(urg_mutex); if (! urg.connect(device.c_str())) { printf("UrgDevice::connect: %s\n", urg.what()); exit(1); } }
void update() { qrk::LockGuard guard(urg_mutex); urg.capture(data, ×tamp); vector<float> angles; for (int i=0; i<data.size(); i++) { angles.push_back( urg.index2rad(i)); } urg_data.setData(data); urg_data.setDataAngles(angles); }
//! main int main(int argc, char *argv[]) { if (argc < 3) { cerr << "usage:" << endl << "\t" << argv[0] << " <number of scans> <output file>\n" << endl; exit(1); } int scan_times = atoi(argv[1]); max(scan_times, 0); ofstream fout(argv[2]); if (! fout.is_open()) { perror(argv[2]); } // Search URG port vector<string> ports; findUrgPorts(ports); if (ports.empty()) { cerr << "no ports." << endl; exit(1); } UrgDevice urg; if (! urg.connect(ports[0].c_str())) { cerr << "UrgDevice::connect: " << urg.what() << endl; exit(1); } // Get data by GD command vector<long> data; for (int i = 0; i < scan_times; ++i) { int n = urg.capture(data); if (n < 0) { continue; } outputCsv(fout, data); cout << (i + 1) << " scaned." << endl; } #ifdef MSC getchar(); #endif return 0; }
void setup(const std::string& host, int port){ if ( socket.connect(host.c_str(), port) ) { urg.setConnection(&socket); urg.connect(host.c_str(), port); } }
inline double index2rad(const int index) const { return urg.index2rad(index); }
inline double maxScanAngle() const { return urg.index2rad(urg.maxScanLines()); }
inline int maxScanIndex() const { return urg.maxScanLines(); }
inline long maxDistance() const { return urg.maxDistance(); }
inline long minDistance() const { return urg.minDistance(); }
void disconnect() { urg.disconnect(); }