// test_robot.cc // nono - programme du robot 2004. {{{ // // Copyright (C) 2004 Nicolas Schodet // // Robot APB Team/Efrei 2004. // Web: http://assos.efrei.fr/robot/ // Email: robot AT efrei DOT fr // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // // }}} #include "date/date.h" #include "io/analog_servo_pp.h" #include "io/analog_cmd.h" #include "io/gpio_asserv.h" #include "io/gpio_concat.h" #include "io/gpio_servo_pp.h" #include "io/gpio_cmd.h" #include "io/gpio_param.h" #include "io/servo.h" #include "io/servo_cmd.h" #include "motor/asserv.h" #include "motor/motor_cmd.h" #include "motor/motor.h" #include "motor/movement_reposition.h" #include #include #include #include void syntax (void) { std::cout << "test_robot - teste tout le robot.\n" << motorHelp << gpioHelp << servoHelp << analogHelp << " p \n" " Mouvement de repositionnement.\n" " T Démarre la tempo de fin de match.\n" " attend (ms)\n" " ? cet ecran d'aide" << std::endl; } int main (int argc, char **argv) { try { Motor m; GpioServoPp gspp; AnalogServoPp ana (gspp); GpioAsserv ga (m.getAsserv ()); GpioConcat gc (ga, gspp, ga.getNbIo ()); GpioParam gp (gc); int i = 1; while (i < argc) { if (!gpioCmd (argc, argv, i, gp) && !servoCmd (argc, argv, i, gspp) && !analogCmd (argc, argv, i, ana) && !motorCmd (argc, argv, i, m)) { switch (argv[i][0]) { case '?': syntax (); return 0; case 'p': { i++; double s; if (i >= argc) break; s = atof (argv[i++]); int gpil, gpir; if (i >= argc) break; gpil = gp.getByName (argv[i++]); if (i >= argc) break; gpir = gp.getByName (argv[i++]); int anal, anar; if (i >= argc) break; anal = ana.getByName (argv[i++]); if (i >= argc) break; anar = ana.getByName (argv[i++]); std::cout << "test: reposition " << s << ' ' << gpil << ' ' << gpir << ' ' << anal << ' ' << anar << std::endl; /// HACK Movement *mov = new MovementReposition (s, gp, gpil, gpir, ana, anal, anar); m.addMovement (mov); } break; case 'T': i++; Date::getInstance ().startRound (); break; case 'P': { i++; double a; char c; if (i >= argc) break; c = argv[i++][0]; if (i >= argc) break; a = atof (argv[i++]); switch (c) { case 'x': m.getTracker ().adjustX (a); break; case 'y': m.getTracker ().adjustY (a); break; case 'a': m.getTracker ().adjustAngle (a); break; } } break; default: int s; s = atoi (argv[i++]); if (s == 0) { syntax (); return 1; } cout << "test: sleep " << s << endl; int start; start = Date::getInstance ().start (); while (Date::getInstance ().start () < start + s) { m.ok (); gspp.update (); Date::wait (50); } break; } } while (!m.end ()) { m.waitOk (); gspp.update (); if (Date::getInstance ().round () > 90000) return 0; } } return 0; } catch (const std::exception &e) { std::cerr << e.what () << std::endl; return 1; } }