run-test.c
Go to the documentation of this file.
00001 // Copyright (c) 2010-2016 The YP-Spur Authors, except where otherwise indicated.
00002 //
00003 // Permission is hereby granted, free of charge, to any person obtaining a copy
00004 // of this software and associated documentation files (the "Software"), to
00005 // deal in the Software without restriction, including without limitation the
00006 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
00007 // sell copies of the Software, and to permit persons to whom the Software is
00008 // furnished to do so, subject to the following conditions:
00009 //
00010 // The above copyright notice and this permission notice shall be included in
00011 // all copies or substantial portions of the Software.
00012 //
00013 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00014 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00015 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
00016 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00017 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00018 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
00019 // SOFTWARE.
00020 
00021 #include <math.h>
00022 #include <stdio.h>
00023 #include <unistd.h>
00024 #include <ypspur.h>
00025 
00026 int main(int argc, char *argv[])
00027 {
00028   double x, y, theta;
00029 
00030   // Windows環境で標準出力がバッファリングされないように設定
00031   setvbuf(stdout, 0, _IONBF, 0);
00032 
00033   // 初期化
00034   if (Spur_init() < 0)
00035   {
00036     fprintf(stderr, "ERROR : cannot open spur.\n");
00037     return -1;
00038   }
00039 
00040   Spur_set_vel(0.2);
00041   Spur_set_accel(1.0);
00042   Spur_set_angvel(M_PI / 2.0);
00043   Spur_set_angaccel(M_PI / 2.0);
00044 
00045   Spur_set_pos_GL(0, 0, 0);
00046   printf("line\n");
00047   // 走行
00048   Spur_stop_line_GL(1.0, 0, 0);
00049   while (!Spur_over_line_GL(1.0 - 0.005, 0.0, 0.0))
00050     usleep(100000);
00051 
00052   // 回転
00053   printf("spin\n");
00054   Spur_spin_GL(M_PI / 2);
00055   while (!Spur_near_ang_GL(M_PI / 2, M_PI / 18.0))
00056     usleep(100000);
00057 
00058   // ちょっと加速
00059   Spur_set_vel(0.3);
00060   Spur_set_accel(1.0);
00061   Spur_set_angvel(M_PI);
00062   Spur_set_angaccel(M_PI);
00063 
00064   // 走行
00065   Spur_stop_line_GL(1.0, 0.1, M_PI / 2.0);
00066   while (!Spur_over_line_GL(1.0, 0.1 - 0.005, M_PI / 2.0))
00067     usleep(100000);
00068 
00069   // 回転
00070   printf("spin\n");
00071   Spur_spin_GL(M_PI);
00072   while (!Spur_near_ang_GL(M_PI, M_PI / 18.0))
00073     usleep(100000);
00074 
00075   // 走行
00076   printf("line\n");
00077   Spur_stop_line_GL(0, 0.1, M_PI);
00078   while (!Spur_over_line_GL(0.0 + 0.005, 0.1, M_PI))
00079     usleep(100000);
00080 
00081   // 回転
00082   printf("spin\n");
00083   Spur_spin_GL(-M_PI / 2.0);
00084   while (!Spur_near_ang_GL(-M_PI / 2.0, M_PI / 18.0))
00085     usleep(100000);
00086 
00087   // 走行
00088   printf("line\n");
00089   Spur_stop_line_GL(0, 0.0, -M_PI / 2.0);
00090   while (!Spur_over_line_GL(0.0, 0.0 + 0.005, -M_PI / 2.0))
00091     usleep(100000);
00092 
00093   // 回転
00094   printf("spin\n");
00095   Spur_spin_GL(0);
00096   while (!Spur_near_ang_GL(0, M_PI / 18.0))
00097     usleep(100000);
00098 
00099   Spur_stop();
00100   usleep(4000000);
00101   Spur_free();
00102   printf("Hit Ctrl-C to exit.\n");
00103   while (1)
00104   {
00105     Spur_get_pos_GL(&x, &y, &theta);
00106     printf("%f %f %f\n", x, y, theta * 180.0 / M_PI);
00107     usleep(1000000);
00108   }
00109 
00110   return 0;
00111 }


yp-spur
Author(s):
autogenerated on Fri May 10 2019 02:52:19