run-test.c
Go to the documentation of this file.
1 // Copyright (c) 2010-2016 The YP-Spur Authors, except where otherwise indicated.
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to
5 // deal in the Software without restriction, including without limitation the
6 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7 // sell copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 // SOFTWARE.
20 
21 #include <math.h>
22 #include <stdio.h>
23 #include <unistd.h>
24 #include <ypspur.h>
25 
26 int main(int argc, char *argv[])
27 {
28  double x, y, theta;
29 
30  // Windows環境で標準出力がバッファリングされないように設定
31  setvbuf(stdout, 0, _IONBF, 0);
32 
33  // 初期化
34  if (Spur_init() < 0)
35  {
36  fprintf(stderr, "ERROR : cannot open spur.\n");
37  return -1;
38  }
39 
40  Spur_set_vel(0.2);
41  Spur_set_accel(1.0);
42  Spur_set_angvel(M_PI / 2.0);
43  Spur_set_angaccel(M_PI / 2.0);
44 
45  Spur_set_pos_GL(0, 0, 0);
46  printf("line\n");
47  // 走行
48  Spur_stop_line_GL(1.0, 0, 0);
49  while (!Spur_over_line_GL(1.0 - 0.005, 0.0, 0.0))
50  usleep(100000);
51 
52  // 回転
53  printf("spin\n");
54  Spur_spin_GL(M_PI / 2);
55  while (!Spur_near_ang_GL(M_PI / 2, M_PI / 18.0))
56  usleep(100000);
57 
58  // ちょっと加速
59  Spur_set_vel(0.3);
60  Spur_set_accel(1.0);
61  Spur_set_angvel(M_PI);
62  Spur_set_angaccel(M_PI);
63 
64  // 走行
65  Spur_stop_line_GL(1.0, 0.1, M_PI / 2.0);
66  while (!Spur_over_line_GL(1.0, 0.1 - 0.005, M_PI / 2.0))
67  usleep(100000);
68 
69  // 回転
70  printf("spin\n");
71  Spur_spin_GL(M_PI);
72  while (!Spur_near_ang_GL(M_PI, M_PI / 18.0))
73  usleep(100000);
74 
75  // 走行
76  printf("line\n");
77  Spur_stop_line_GL(0, 0.1, M_PI);
78  while (!Spur_over_line_GL(0.0 + 0.005, 0.1, M_PI))
79  usleep(100000);
80 
81  // 回転
82  printf("spin\n");
83  Spur_spin_GL(-M_PI / 2.0);
84  while (!Spur_near_ang_GL(-M_PI / 2.0, M_PI / 18.0))
85  usleep(100000);
86 
87  // 走行
88  printf("line\n");
89  Spur_stop_line_GL(0, 0.0, -M_PI / 2.0);
90  while (!Spur_over_line_GL(0.0, 0.0 + 0.005, -M_PI / 2.0))
91  usleep(100000);
92 
93  // 回転
94  printf("spin\n");
95  Spur_spin_GL(0);
96  while (!Spur_near_ang_GL(0, M_PI / 18.0))
97  usleep(100000);
98 
99  Spur_stop();
100  usleep(4000000);
101  Spur_free();
102  printf("Hit Ctrl-C to exit.\n");
103  while (1)
104  {
105  Spur_get_pos_GL(&x, &y, &theta);
106  printf("%f %f %f\n", x, y, theta * 180.0 / M_PI);
107  usleep(1000000);
108  }
109 
110  return 0;
111 }
#define Spur_init()
Definition: ypspur.h:31
#define Spur_set_pos_GL(x, y, th)
Definition: ypspur.h:71
int main(int argc, char *argv[])
Definition: run-test.c:26
#define Spur_set_angaccel(w)
Definition: ypspur.h:78
#define Spur_set_accel(v)
Definition: ypspur.h:77
#define Spur_spin_GL(th)
Definition: ypspur.h:59
#define Spur_free()
Definition: ypspur.h:35
#define Spur_stop_line_GL(x, y, th)
Definition: ypspur.h:47
#define Spur_near_ang_GL(th, d)
Definition: ypspur.h:99
#define Spur_stop()
Definition: ypspur.h:34
#define Spur_set_angvel(w)
Definition: ypspur.h:76
#define Spur_over_line_GL(x, y, th)
Definition: ypspur.h:104
#define Spur_set_vel(v)
Definition: ypspur.h:75
#define Spur_get_pos_GL(x, y, th)
Definition: ypspur.h:86


yp-spur
Author(s):
autogenerated on Sat May 11 2019 02:08:24