libs/range_sensor/simple_samples/gdScan.cpp
00001 
00011 #include "UrgDevice.h"
00012 #include <cstdlib>
00013 #include <cstdio>
00014 
00015 using namespace qrk;
00016 using namespace std;
00017 
00018 
00020 int main(int argc, char *argv[])
00021 {
00022   // Change the port name appropriately
00023 #ifdef WINDOWS_OS
00024   const char device[] = "COM3";
00025 #else
00026   const char device[] = "/dev/ttyACM0";
00027 #endif
00028 
00029   UrgDevice urg;
00030   if (! urg.connect(device)) {
00031     printf("UrgDevice::connect: %s\n", urg.what());
00032     exit(1);
00033   }
00034 
00035   // Scans for the number of times specified as in GD command and outputs
00036   // the data.
00037   enum { CaptureTimes = 1 };
00038   for (int i = 0; i < CaptureTimes; ++i) {
00039     long timestamp = 0;
00040     vector<long> data;
00041 
00042     // Get the data
00043     int n = urg.capture(data, &timestamp);
00044 
00045     // Display
00046     printf("timestamp: %ld\n", timestamp);
00047     for (int j = 0; j < n; ++j) {
00048       // The distance data that are less than urg_minDistance() are shown as
00049       // invalide values
00050       printf("%d:%ld, ", j, data[j]); // index, length [mm]
00051     }
00052     printf("\n");
00053   }
00054 
00055 #ifdef MSC
00056   getchar();
00057 #endif
00058 
00059   return 0;
00060 }
 All Classes Namespaces Files Functions Variables Enumerations Enumerator