4
\brief Sample of 2D representation of URG data
6
\author Satofumi KAMIMURA
8
$Id: convert_2d.c 1733 2010-03-06 01:19:49Z satofumi $
17
static void urg_exit(urg_t *urg, const char *message)
19
printf("%s: %s\n", message, urg_error(urg));
30
int main(int argc, char *argv[])
33
const char device[] = "COM3"; /* For Windows */
35
const char device[] = "/dev/ttyACM0"; /* For Linux */
49
ret = urg_connect(&urg, device, 115200);
51
urg_exit(&urg, "urg_connect()");
54
/* Reserve for Reception data */
55
data_max = urg_dataMax(&urg);
56
data = (long*)malloc(sizeof(long) * data_max);
58
perror("data buffer");
62
/* Request for GD data */
63
ret = urg_requestData(&urg, URG_GD, URG_FIRST, URG_LAST);
65
urg_exit(&urg, "urg_requestData()");
69
n = urg_receiveData(&urg, data, data_max);
71
urg_exit(&urg, "urg_receiveData()");
74
/* Output as 2 dimensional data */
75
/* Consider front of URG as positive direction of X axis */
76
min_length = urg_minDistance(&urg);
77
max_length = urg_maxDistance(&urg);
78
for (i = 0; i < n; ++i) {
80
long length = data[i];
82
/* Neglect the out of range values */
83
if ((length <= min_length) || (length >= max_length)) {
87
x = (int)(length * cos(urg_index2rad(&urg, i)));
88
y = (int)(length * sin(urg_index2rad(&urg, i)));
90
printf("%d\t%d\t# %d, %ld\n", x, y, i, length);