-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhokuyo_acq.cc
83 lines (69 loc) · 1.83 KB
/
hokuyo_acq.cc
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include "hokuyo.hh"
#include <iostream>
#include <sys/time.h>
#include <time.h>
#include <math.h>
using namespace std;
static bool keypressed()
{
int in = fileno(stdin);
fd_set set;
FD_ZERO(&set);
FD_SET(in, &set);
timeval timeout = { 0, 0 };
if (select(in + 1, &set, NULL, NULL, &timeout) == 0)
return false;
return true;
}
int main (int argc, const char** argv){
if (argc<2){
printf( "Usage: %s [-uri] <device> ", argv[0]);
return 0;
}
URG urg;
if (string(argv[1]) == "-uri")
{
urg.openURI(argv[2]);
}
else
{
if (!urg.setBaudrate(115200))
{
cerr << "cannot set baudrate: " << urg.errorString() << endl;
perror("errno is");
return 1;
}
if (!urg.open(argv[1]))
{
cerr << "cannot open device: " << urg.errorString() << endl;
perror("errno is");
return 1;
}
}
cerr << urg.getInfo() << endl;
if (!urg.startAcquisition(0))
{
cerr << "cannot start acquisition: " << urg.errorString() << endl;
perror("errno is");
return 1;
}
base::samples::LaserScan scan;
cout << "# timestamp is in milliseconds, angles are in radians and ranges in millimeters." << endl;
cout << "# timestamp angle_min angle_resolution range_count range0 range1 ..." << endl;
while(!keypressed())
{
if (!urg.readRanges(scan))
{
cerr << "failed acquisition" << endl;
break;
}
float res = scan.angular_resolution;
float min = scan.start_angle;
cout << base::Time::now().toMilliseconds() << " " << scan.time.toMilliseconds() << " " << min << " " << res << " " << scan.ranges.size();
for (size_t i = 0; i < scan.ranges.size(); ++i)
cout << " " << scan.ranges[i];
cout << endl;
}
urg.stopAcquisition();
urg.close();
}