~vibhavp/ubuntu/saucy/urg/merge-from-debian

« back to all changes in this revision

Viewing changes to samples/cpp/mdScan.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Albert Huang
  • Date: 2011-05-20 11:33:03 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20110520113303-u8niofzwzcea0osk
Tags: 0.8.12-1
* New upstream release (closes: #624987)
* Add debian/watch file
* Bump standards-version to 3.9.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*!
 
2
  \example mdScan.cpp
 
3
 
 
4
  \brief Sample to get data using MD command
 
5
 
 
6
  \author Satofumi KAMIMURA
 
7
 
 
8
  $Id: mdScan.cpp 1737 2010-03-06 07:15:19Z satofumi $
 
9
*/
 
10
 
 
11
#include "UrgDevice.h"
 
12
#include "delay.h"
 
13
#include "ticks.h"
 
14
#include <cstdlib>
 
15
#include <cstdio>
 
16
 
 
17
using namespace qrk;
 
18
using namespace std;
 
19
 
 
20
 
 
21
//! main
 
22
int main(int argc, char *argv[])
 
23
{
 
24
  // Change the port name appropriately
 
25
#ifdef WINDOWS_OS
 
26
  const char device[] = "COM3";
 
27
#else
 
28
  const char device[] = "/dev/ttyACM0";
 
29
#endif
 
30
 
 
31
  UrgDevice urg;
 
32
  if (! urg.connect(device)) {
 
33
    printf("UrgDevice::connect: %s\n", urg.what());
 
34
    exit(1);
 
35
  }
 
36
 
 
37
#if 1
 
38
  // Set to MD mode to acquire data
 
39
  urg.setCaptureMode(AutoCapture);
 
40
 
 
41
#else
 
42
  // Mode to get distance data and intensity data
 
43
  urg.setCaptureMode(IntensityCapture);
 
44
  urg.setCaptureSkipLines(2);
 
45
#endif
 
46
  int scan_msec = urg.scanMsec();
 
47
 
 
48
#if 0
 
49
  // Set range of acquisition from the center to left 90 degree.
 
50
  // Set range of acquistion from center to right to 90 degree.
 
51
  // So In total it will be 180 degree.
 
52
  const double rad90 = 90.0 * M_PI / 180.0;
 
53
  urg.setCaptureRange(urg.rad2index(-rad90), urg.rad2index(rad90));
 
54
#endif
 
55
 
 
56
  int pre_timestamp = ticks();
 
57
 
 
58
  // Data is acquired continuously using MD command
 
59
  // but outputs data of specified number of times.
 
60
  enum { CaptureTimes = 10};
 
61
  urg.setCaptureTimes(CaptureTimes);
 
62
  for (int i = 0; i < CaptureTimes;) {
 
63
    long timestamp = 0;
 
64
    vector<long> data;
 
65
 
 
66
    // Get data
 
67
    int n = urg.capture(data, &timestamp);
 
68
    if (n <= 0) {
 
69
      delay(scan_msec);
 
70
      continue;
 
71
    }
 
72
 
 
73
    // Display
 
74
    printf("timestamp: %ld, (%ld), %ld\n",
 
75
           timestamp, ticks(), timestamp - pre_timestamp);
 
76
    pre_timestamp = timestamp;
 
77
#if 0
 
78
    for (int j = 0; j < n; ++j) {
 
79
      // The distance data that are less than urg_minDistance() are shown
 
80
      // as invalide values
 
81
      printf("%d:%ld, ", j, data[j]);
 
82
    }
 
83
    printf("\n");
 
84
#endif
 
85
    ++i;
 
86
  }
 
87
 
 
88
#ifdef MSC
 
89
  getchar();
 
90
#endif
 
91
 
 
92
  return 0;
 
93
}