summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhaller2005-04-28 22:31:07 +0000
committerhaller2005-04-28 22:31:07 +0000
commit236cf50a11672fd15ba62f2eca2e9368d2681c1e (patch)
tree7e1793180fdf4cf7e8d44ef3b1974014099f31d3
parent10e9b5ada8232d3ec6320953ad9b6f42bead79ed (diff)
Création de test_motor pour tester la classe motor
Quelques petites modifications Modification du Makefile.defs pour ajouter les objets necessaires
-rw-r--r--2005/i/robert/src/motor/Makefile.defs5
-rw-r--r--2005/i/robert/src/motor/motor.cc11
-rw-r--r--2005/i/robert/src/motor/motor.hh4
-rw-r--r--2005/i/robert/src/motor/test_motor.cc136
4 files changed, 147 insertions, 9 deletions
diff --git a/2005/i/robert/src/motor/Makefile.defs b/2005/i/robert/src/motor/Makefile.defs
index 2491bb5..51c658c 100644
--- a/2005/i/robert/src/motor/Makefile.defs
+++ b/2005/i/robert/src/motor/Makefile.defs
@@ -2,6 +2,9 @@ PROGRAMS += test_motor
motor_OBJECTS = motor.o
-test_motor_OBJECTS = test_motor.o $(motor_OBJECTS)
+test_motor_OBJECTS = test_motor.o $(motor_OBJECTS) $(timer_OBJECTS) \
+ $(config_OBJECTS) $(serial_OBJECTS) \
+ $(asserv_OBJECTS) $(proto_OBJECTS) $(log_OBJECTS) \
+ $(utils_OBJECTS)
test_motor: $(test_motor_OBJECTS)
diff --git a/2005/i/robert/src/motor/motor.cc b/2005/i/robert/src/motor/motor.cc
index 896c7f4..0bc7525 100644
--- a/2005/i/robert/src/motor/motor.cc
+++ b/2005/i/robert/src/motor/motor.cc
@@ -79,12 +79,6 @@ void Motor::recalage(void)
// XXX je ne vois pas là
}
-void Motor::setSpeed(double v)
-{
- asserv_.setSpeed(v,v); /// XXX sur ca?
- idle_ = false;
-}
-
bool Motor::idle(void)
{
return idle_;
@@ -107,6 +101,11 @@ bool Motor::sync(void)
return asserv_.sync();
}
+void Motor::wait(int timeout)
+{
+ asserv_.wait(timeout);
+}
+
void Motor::receiveCounter (double lMotor, double rMotor)
{
}
diff --git a/2005/i/robert/src/motor/motor.hh b/2005/i/robert/src/motor/motor.hh
index e617980..60eb504 100644
--- a/2005/i/robert/src/motor/motor.hh
+++ b/2005/i/robert/src/motor/motor.hh
@@ -62,8 +62,6 @@ class Motor : public Asserv::Receiver
void goTo(double x, double y, double a);
/// Recale le robot
void recalage(void);
- /// Règle la vitesse des moteurs
- void setSpeed(double v);
/// Indique si les moteurs sont occupé ou non
bool idle (void);
/// Execute un déplacement linéaire
@@ -72,6 +70,8 @@ class Motor : public Asserv::Receiver
void rotation(double newA);
/// Syncronisation
bool sync(void);
+ /// On attend...
+ void wait(int timeout);
/// déclaration des fonctions de receiver
void receiveCounter (double lMotor, double rMotor);
void receivePosX (double xPos);
diff --git a/2005/i/robert/src/motor/test_motor.cc b/2005/i/robert/src/motor/test_motor.cc
new file mode 100644
index 0000000..477da41
--- /dev/null
+++ b/2005/i/robert/src/motor/test_motor.cc
@@ -0,0 +1,136 @@
+// test_motor.cc
+// robert - programme du robot 2005 {{{
+//
+// Copyright (C) 2005 Nicolas Haller
+//
+// Robot APB Team/Efrei 2005.
+// 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 "config/config.hh"
+#include "motor/motor.hh"
+#include "timer/timer.hh"
+
+#include <iostream>
+
+/// Affiche un memo de suntaxe.
+ void
+syntax (void)
+{
+ 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;
+}
+
+ int
+main (int argc, char **argv)
+{
+ try
+ {
+ int i;
+ if (argc < 2)
+ {
+ syntax ();
+ return 1;
+ }
+ Config config(argc, argv);
+ Motor motor(config);
+ 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() << std::endl;
+ 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;
+ }
+ 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++;
+ }
+ }
+ catch (const std::exception &e)
+ {
+ std::cerr << e.what () << std::endl;
+ syntax ();
+ return 1;
+ }
+ return 0;
+}