All Classes Namespaces Files Functions Variables Enumerations Enumerator Pages
mdCaptureSample.cpp
1 
11 #include "UrgCtrl.h"
12 #include "delay.h"
13 #include "getTicks.h"
14 #include <cstdlib>
15 
16 using namespace qrk;
17 using namespace std;
18 
19 
21 int main(int argc, char *argv[])
22 {
23  //const char device[] = "COM3";
24  const char device[] = "/dev/ttyACM0";
25 
26  UrgCtrl urg;
27  if (! urg.connect(device)) {
28  printf("UrgCtrl::connect: %s\n", urg.what());
29  exit(1);
30  }
31 
32 #if 1
33  // Set to MD mode to acquire data
35 
36 #else
37  // Mode to get distance data and intensity data
39  urg.setCaptureSkipLines(2);
40 #endif
41  int scan_msec = urg.scanMsec();
42 
43 #if 0
44  // Set range of acquisition from the center to left 90 degree.
45  // Set range of acquistion from center to right to 90 degree.
46  // So In total it will be 180 degree.
47  const double rad90 = 90.0 * M_PI / 180.0;
48  urg.setCaptureRange(urg.rad2index(-rad90), urg.rad2index(rad90));
49 #endif
50 
51  int pre_timestamp = getTicks();
52 
53  // Data is acquired continuously using MD command
54  // but outputs data of specified number of times.
55  enum { CaptureTimes = 10 };
56  urg.setCaptureTimes(CaptureTimes);
57  for (int i = 0; i < CaptureTimes;) {
58  long timestamp = 0;
59  vector<long> data;
60 
61  // Get data
62  int n = urg.capture(data, &timestamp);
63  if (n <= 0) {
64  delay(scan_msec);
65  continue;
66  }
67 
68  // Display
69  printf("timestamp: %ld, (%d), %ld\n",
70  timestamp, getTicks(), timestamp - pre_timestamp);
71  pre_timestamp = timestamp;
72 #if 0
73  for (int j = 0; j < n; ++j) {
74  // The distance data that are less than urg_minDistance() are shown as invalide values
75  printf("%d:%ld, ", j, data[j]);
76  }
77  printf("\n");
78 #endif
79  ++i;
80  }
81  return 0;
82 }