4
\brief Sample to get data using MD command
6
\author Satofumi KAMIMURA
8
$Id: mdScan.cpp 1737 2010-03-06 07:15:19Z satofumi $
11
#include "UrgDevice.h"
22
int main(int argc, char *argv[])
24
// Change the port name appropriately
26
const char device[] = "COM3";
28
const char device[] = "/dev/ttyACM0";
32
if (! urg.connect(device)) {
33
printf("UrgDevice::connect: %s\n", urg.what());
38
// Set to MD mode to acquire data
39
urg.setCaptureMode(AutoCapture);
42
// Mode to get distance data and intensity data
43
urg.setCaptureMode(IntensityCapture);
44
urg.setCaptureSkipLines(2);
46
int scan_msec = urg.scanMsec();
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));
56
int pre_timestamp = ticks();
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;) {
67
int n = urg.capture(data, ×tamp);
74
printf("timestamp: %ld, (%ld), %ld\n",
75
timestamp, ticks(), timestamp - pre_timestamp);
76
pre_timestamp = timestamp;
78
for (int j = 0; j < n; ++j) {
79
// The distance data that are less than urg_minDistance() are shown
81
printf("%d:%ld, ", j, data[j]);