File: gdCaptureSample.cpp

package info (click to toggle)
urg 0.8.11-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 3,212 kB
  • ctags: 1,605
  • sloc: sh: 10,014; cpp: 6,459; ansic: 2,419; makefile: 203
file content (59 lines) | stat: -rw-r--r-- 1,124 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*!
  \example gdCaptureSample.cpp

  \brief Sample to get data using GD command

  \author Satofumi KAMIMURA

  $Id: gdCaptureSample.cpp 1683 2010-02-10 10:28:05Z satofumi $
*/

#include "UrgCtrl.h"
#include <cstdlib>
#include <cstdio>

using namespace qrk;
using namespace std;


//! main
int main(int argc, char *argv[])
{
#ifdef WINDOWS_OS
  const char device[] = "COM3";
#else
  const char device[] = "/dev/ttyACM0";
#endif

  UrgCtrl urg;
  if (! urg.connect(device)) {
    printf("UrgCtrl::connect: %s\n", urg.what());
    exit(1);
  }

  // Scans for the number of times specified as in GD command and outputs
  // the data.
  enum { CaptureTimes = 1 };
  for (int i = 0; i < CaptureTimes; ++i) {
    long timestamp = 0;
    vector<long> data;

    // Get the data
    int n = urg.capture(data, &timestamp);

    // Display
    printf("timestamp: %ld\n", timestamp);
    for (int j = 0; j < n; ++j) {
      // The distance data that are less than urg_minDistance() are shown as
      // invalide values
      printf("%d:%ld, ", j, data[j]);
    }
    printf("\n");
  }

#ifdef MSC
  getchar();
#endif

  return 0;
}