All Classes Namespaces Files Functions Variables Enumerations Enumerator Pages
index_convert.c
1 
13 #include "urg_ctrl.h"
14 #include "math_utils.h"
15 #include <stdio.h>
16 #include <stdlib.h>
17 
18 
19 static void urg_exit(urg_t *urg, const char *message)
20 {
21  printf("%s: %s\n", message, urg_error(urg));
22  urg_disconnect(urg);
23 
24 #ifdef MSC
25  getchar();
26 #endif
27  exit(1);
28 }
29 
30 
32 int main(int argc, char *argv[])
33 {
34  //const char device[] = "COM3"; /* Example for Windows */
35  const char device[] = "/dev/ttyACM0"; /* Example for Linux */
36 
37  int ret = 0;
38  int n;
39  int i;
40 
41  /* Connection */
42  urg_t urg;
43  ret = urg_connect(&urg, device, 115200);
44  if (ret < 0) {
45  urg_exit(&urg, "urg_connect()");
46  }
47 
48  /* Outputs the angle of each index */
49  n = urg_dataMax(&urg);
50  for (i = 0; i < n; i += 8) {
51  double radian = urg_index2rad(&urg, i);
52  int degree = urg_index2deg(&urg, i);
53  printf("%03d, %d [deg], %.1f [rad], %d, %d\n", i, degree, radian,
54  urg_deg2index(&urg, degree), urg_rad2index(&urg, radian));
55  }
56 
57  return 0;
58 }