summaryrefslogtreecommitdiff
path: root/i/marvin/src/motor/test_motor.cc
diff options
context:
space:
mode:
Diffstat (limited to 'i/marvin/src/motor/test_motor.cc')
-rw-r--r--i/marvin/src/motor/test_motor.cc182
1 files changed, 65 insertions, 117 deletions
diff --git a/i/marvin/src/motor/test_motor.cc b/i/marvin/src/motor/test_motor.cc
index c901d69..760dfd6 100644
--- a/i/marvin/src/motor/test_motor.cc
+++ b/i/marvin/src/motor/test_motor.cc
@@ -1,7 +1,7 @@
// test_motor.cc
-// robert - programme du robot 2005 {{{
+// marvin - programme du robot 2006. {{{
//
-// Copyright (C) 2005 Nicolas Haller
+// Copyright (C) 2006 Nicolas Schodet
//
// Robot APB Team/Efrei 2005.
// Web: http://assos.efrei.fr/robot/
@@ -22,130 +22,78 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// }}}
-
-#include "config/config.hh"
-#include "motor/motor.hh"
+#include "motor.hh"
+#include "tester/tester.hh"
#include "timer/timer.hh"
#include <iostream>
+#include <exception>
+#include <iomanip>
-/// Affiche un memo de suntaxe.
- void
-syntax (void)
+class TestMotor : public Tester
{
- std::cout << "test_motor - test la classe motor.\n"
- "Syntaxe : test_motor <...>\n"
- " s <cmd> <args...> envois une commande\n"
- " w <ms> attend pendant un nombre de millisecondes\n"
- " ? affiche cet écran d'aide\n"
- << std::endl;
-}
+ private:
+ Motor motor_;
+ public:
+ /// Constructor.
+ TestMotor (int argc, char **argv)
+ : Tester (argc, argv)
+ { }
+ /// Wait.
+ void wait (int ms)
+ {
+ int t, stop;
+ t = Timer::getProgramTime ();
+ stop = t + ms;
+ while (t < stop)
+ {
+ motor_.wait (stop - t);
+ t = Timer::getProgramTime ();
+ }
+ }
+ /// Called after each command called.
+ void postcall (void)
+ {
+ while (!motor_.wait () || !motor_.finish ())
+ ;
+ }
+ /// Executed before checking/running commands. Good place to add command
+ /// to the interpreter.
+ void preRun (void)
+ {
+ Interpreter &i = getInterpreter ();
+ i.add ("wait", Interpreter::memFunc (*this, &TestMotor::wait),
+ "wait MS\nwait for a delay in millisecond");
+ i.add ("move", Interpreter::memFunc (motor_, &Motor::move),
+ "move T(mm) A(mm)\n"
+ "linear and angular move");
+ i.add ("rotate", Interpreter::memFunc (motor_, &Motor::rotate),
+ "rotate A(rad)\n"
+ "rotate round axis center");
+ i.add ("findHole", Interpreter::memFunc (motor_, &Motor::findHole),
+ "findHole\nfind a hole");
+ i.add ("stop", Interpreter::memFunc (motor_, &Motor::stop),
+ "stop\nguess what");
+ i.add ("_postcall",
+ Interpreter::memFunc (*this, &TestMotor::postcall));
+ }
+ /// Executed after running commands.
+ void postRun (void)
+ {
+ motor_.getAsserv ().reset ();
+ }
+};
- int
+int
main (int argc, char **argv)
{
try
- {
- int i;
- if (argc < 2)
- {
- syntax ();
- return 1;
- }
- Config config (argc, argv);
- Motor motor;
- i = 1;
- while (i < argc)
- {
- switch (argv[i][0])
- {
- case 's':
- {
- switch(argv[++i][0])
- {
- case 'z':
- motor.init();
- break;
- case 's':
- motor.stop();
- break;
- case 'P':
- std::cout << "position:\n" <<
- "X: " << motor.getX() <<
- " Y: " << motor.getY() <<
- " A: " << motor.getA() << std::endl;
- break;
- case 'g':
- if(++i + 2 > argc)
- throw std::runtime_error("syntax error");
- motor.goTo(strtod(argv[i], 0),
- strtod(argv[i + 1], 0),
- strtod(argv[i + 2], 0));
- i += 2;
- break;
- case 'r':
- motor.recalage();
- break;
- case 'I':
- std::cout << "Moteur idle? "
- << (motor.idle() ? "true" : "false")
- << std::endl;
- break;
- case 'l':
- if(++i > argc)
- throw std::runtime_error("syntax error");
- motor.linearMove(strtod(argv[i],0));
- break;
- case 'a':
- if(++i > argc)
- throw std::runtime_error("syntax error");
- motor.rotation(strtod(argv[i], 0));
- break;
- case 'J':
- std::cout << "Etat du Jack: " << (motor.jackState() ? "Retiré" : "Dedans") << std::endl;
- break;
- case 'C':
- std::cout << "Couleur Sélectionné: " << (motor.colorState() ? "Rouge" : "Vert") << std::endl;
- break;
- case 'A':
- if(++i > argc)
- throw std::runtime_error("syntax error");
- motor.setAccel(strtol(argv[0], 0, 10));
- break;
- }
- while(!motor.wait () || !motor.idle ())
- ;
- break;
- }
-
- case 'w':
- {
- int stop, t;
- if (i + 1 >= argc)
- throw std::runtime_error ("syntax error");
- stop = atoi (argv[++i]) + Timer::getProgramTime ();
- t = Timer::getProgramTime ();
- while (t < stop)
- {
- motor.wait (stop - t);
- t = Timer::getProgramTime ();
- }
- break;
- }
- case '?':
- syntax ();
- return 0;
- default:
- throw std::runtime_error ("syntax error");
- }
- i++;
- }
- }
+ {
+ TestMotor tm (argc, argv);
+ tm.run ();
+ }
catch (const std::exception &e)
- {
+ {
std::cerr << e.what () << std::endl;
- syntax ();
- return 1;
- }
- return 0;
+ }
}