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

« back to all changes in this revision

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