libs/range_sensor/simple_samples/mdScan.cpp
00001 
00011 #include "UrgDevice.h"
00012 #include "delay.h"
00013 #include "ticks.h"
00014 #include <cstdlib>
00015 #include <cstdio>
00016 
00017 using namespace qrk;
00018 using namespace std;
00019 
00020 
00022 int main(int argc, char *argv[])
00023 {
00024   // Change the port name appropriately
00025 #ifdef WINDOWS_OS
00026   const char device[] = "COM3";
00027 #else
00028   const char device[] = "/dev/ttyACM0";
00029 #endif
00030 
00031   UrgDevice urg;
00032   if (! urg.connect(device)) {
00033     printf("UrgDevice::connect: %s\n", urg.what());
00034     exit(1);
00035   }
00036 
00037 #if 1
00038   // Set to MD mode to acquire data
00039   urg.setCaptureMode(AutoCapture);
00040 
00041 #else
00042   // Mode to get distance data and intensity data
00043   urg.setCaptureMode(IntensityCapture);
00044   urg.setCaptureSkipLines(2);
00045 #endif
00046   int scan_msec = urg.scanMsec();
00047 
00048 #if 0
00049   // Set range of acquisition from the center to left 90 degree.
00050   // Set range of acquistion from center to right to 90 degree.
00051   // So In total it will be 180 degree.
00052   const double rad90 = 90.0 * M_PI / 180.0;
00053   urg.setCaptureRange(urg.rad2index(-rad90), urg.rad2index(rad90));
00054 #endif
00055 
00056   int pre_timestamp = ticks();
00057 
00058   // Data is acquired continuously using MD command
00059   // but outputs data of specified number of times.
00060   enum { CaptureTimes = 10};
00061   urg.setCaptureTimes(CaptureTimes);
00062   for (int i = 0; i < CaptureTimes;) {
00063     long timestamp = 0;
00064     vector<long> data;
00065 
00066     // Get data
00067     int n = urg.capture(data, &timestamp);
00068     if (n <= 0) {
00069       delay(scan_msec);
00070       continue;
00071     }
00072 
00073     // Display
00074     printf("timestamp: %ld, (%ld), %ld\n",
00075            timestamp, ticks(), timestamp - pre_timestamp);
00076     pre_timestamp = timestamp;
00077 #if 0
00078     for (int j = 0; j < n; ++j) {
00079       // The distance data that are less than urg_minDistance() are shown
00080       // as invalide values
00081       printf("%d:%ld, ", j, data[j]);
00082     }
00083     printf("\n");
00084 #endif
00085     ++i;
00086   }
00087 
00088 #ifdef MSC
00089   getchar();
00090 #endif
00091 
00092   return 0;
00093 }
 All Classes Namespaces Files Functions Variables Enumerations Enumerator