summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--i/marvin/src/asserv/asserv.cc7
-rw-r--r--i/marvin/src/asserv/asserv.hh2
-rw-r--r--i/marvin/src/asserv/test_asserv.cc28
-rw-r--r--i/marvin/src/motor/Makefile.defs7
-rw-r--r--i/marvin/src/motor/motor.cc302
-rw-r--r--i/marvin/src/motor/motor.hh142
-rw-r--r--i/marvin/src/motor/test_motor.cc182
7 files changed, 203 insertions, 467 deletions
diff --git a/i/marvin/src/asserv/asserv.cc b/i/marvin/src/asserv/asserv.cc
index f5321fc..5726dbf 100644
--- a/i/marvin/src/asserv/asserv.cc
+++ b/i/marvin/src/asserv/asserv.cc
@@ -129,6 +129,13 @@ Asserv::speedTo (double t, double a, int seq)
proto_.send ('s', "ddb", mmToStep (t), mmToStep (a), seq);
}
+/// Speed controlled angle consign offset.
+void
+Asserv::speedAngle (double a, int seq)
+{
+ proto_.send ('s', "ddb", 0, radToStep (a), seq);
+}
+
/// Find a hole.
void
Asserv::findHole (int seq)
diff --git a/i/marvin/src/asserv/asserv.hh b/i/marvin/src/asserv/asserv.hh
index 5f59084..0d9f5a2 100644
--- a/i/marvin/src/asserv/asserv.hh
+++ b/i/marvin/src/asserv/asserv.hh
@@ -80,6 +80,8 @@ class Asserv : public Proto::Receiver
void speed (int t, int a);
/// Speed controlled position consign offset.
void speedTo (double t, double a, int seq);
+ /// Speed controlled angle consign offset.
+ void speedAngle (double a, int seq);
/// Find a hole.
void findHole (int seq);
/// Acknoledge.
diff --git a/i/marvin/src/asserv/test_asserv.cc b/i/marvin/src/asserv/test_asserv.cc
index 4742e5d..557add2 100644
--- a/i/marvin/src/asserv/test_asserv.cc
+++ b/i/marvin/src/asserv/test_asserv.cc
@@ -24,6 +24,7 @@
// }}}
#include "asserv.hh"
#include "tester/tester.hh"
+#include "timer/timer.hh"
#include <iostream>
#include <exception>
@@ -54,6 +55,13 @@ class TestAsserv : public Tester, public Asserv::Receiver
ok_ = false;
asserv_.speedTo (t, a, seq_);
}
+ /// Speed controlled angle consign offset, handle seq.
+ void speedAngle (double a)
+ {
+ nextSeq ();
+ ok_ = false;
+ asserv_.speedAngle (a, seq_);
+ }
/// Find a hole, handle seq.
void findHole (void)
{
@@ -61,18 +69,30 @@ class TestAsserv : public Tester, public Asserv::Receiver
ok_ = false;
asserv_.findHole (seq_);
}
+ /// Wait.
+ void wait (int ms)
+ {
+ int t, stop;
+ t = Timer::getProgramTime ();
+ stop = t + ms;
+ while (t < stop)
+ {
+ asserv_.wait (stop - t);
+ t = Timer::getProgramTime ();
+ }
+ }
/// Called after each command called.
void postcall (void)
{
while (!asserv_.wait () || !ok_)
- std::cout << "hop" << std::endl;
+ ;
}
/// Executed before checking/running commands. Good place to add command
/// to the interpreter.
void preRun (void)
{
Interpreter &i = getInterpreter ();
- i.add ("wait", Interpreter::memFunc (asserv_, &Asserv::wait),
+ i.add ("wait", Interpreter::memFunc (*this, &TestAsserv::wait),
"wait MS\nwait for a delay in millisecond");
i.add ("reset", Interpreter::memFunc (asserv_, &Asserv::reset),
"reset\nreset the asserv board");
@@ -88,6 +108,10 @@ class TestAsserv : public Tester, public Asserv::Receiver
i.add ("speedTo", Interpreter::memFunc (*this, &TestAsserv::speedTo),
"speedTo THETA(mm) ANGLE(mm)\n"
"speed consign limited in distance");
+ i.add ("speedAngle",
+ Interpreter::memFunc (*this, &TestAsserv::speedAngle),
+ "speedAngle ANGLE(rad)\n"
+ "speed consign limited in angle");
i.add ("findHole", Interpreter::memFunc (*this, &TestAsserv::findHole),
"findHole\nfind a hole");
i.add ("setPos", Interpreter::memFunc (asserv_, &Asserv::setPos),
diff --git a/i/marvin/src/motor/Makefile.defs b/i/marvin/src/motor/Makefile.defs
index 4867e00..1efcd13 100644
--- a/i/marvin/src/motor/Makefile.defs
+++ b/i/marvin/src/motor/Makefile.defs
@@ -1,8 +1,5 @@
PROGRAMS += test_motor
-motor_OBJECTS = motor.o
+motor_OBJECTS = motor.o $(asserv_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_OBJECTS = test_motor.o $(motor_OBJECTS) $(tester_OBJECTS)
diff --git a/i/marvin/src/motor/motor.cc b/i/marvin/src/motor/motor.cc
index e9c0937..af3d29f 100644
--- a/i/marvin/src/motor/motor.cc
+++ b/i/marvin/src/motor/motor.cc
@@ -1,7 +1,7 @@
// 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,290 +22,104 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// }}}
-
#include "motor.hh"
-#include "config/config.hh"
-
-#include <cmath>
-/// Constructeur
+/// Constructor.
Motor::Motor (void)
- : asserv_(*this), log_("Motor"),idle_(true), doneDone_(false),
- f0Sended_(false), pinUpdated_(false)
-{
- // Get Config
- Config &config = Config::getInstance ();
- // XXX Quant est-il des positions de départ du robot???
- pStatPosition_ = config.get<int>("motor.pStatPosition");
- pStatMotor_ = config.get<int>("motor.pStatMotor");
- posX_ = 65;
- posY_ = -225;
- posA_ = 0;
- asserv_.setXPos(posX_);
- asserv_.setYPos(posY_);
- asserv_.setAngle(posA_);
-}
-
-/// Initialise les moteurs
-void Motor::init (void)
-{
- // on reset la carte
- asserv_.reset();
- // on règle le rafraichissement des positions
- asserv_.statPosition(pStatPosition_);
- asserv_.statMotor(pStatMotor_);
- //log_ ("initialisation") << "Etat" << "Terminée";
-}
-
-// Arrête les moteurs
-void Motor::stop(void)
-{
- asserv_.setSpeed();
- idle_ = true;
-}
-
-double Motor::getX(void)
-{
- return posX_;
-}
-
-double Motor::getY(void)
-{
- return posY_;
-}
-
-double Motor::getA(void)
-{
- return posA_;
-}
-
-void Motor::setPosition(double x, double y, double a) //XXX Faire trois setteur
-{
- asserv_.setXPos(x);
- asserv_.setYPos(y);
- asserv_.setAngle(a);
- posX_ = x;
- posY_ = y;
- posA_ = a;
-}
-
-void
-Motor::setPwm(int leftPwm, int rightPwm)
-{
- asserv_.setPwm (leftPwm, rightPwm);
-}
-
-void Motor::goTo(double x, double y, double a)
-{
-
- //Détermination de la distance à parcourir
- double dist = sqrt((x - posX_) * (x- posX_) + (y - posY_) * (y - posY_));
- //Détermination de l'angle qui va bien
- double angle = acos ((x - posX_) / dist);
- if((y - posY_) < 0)
- angle = -angle;
-
- // On remplie la file
- fOrdre_.push(ordre(true, dist));
- fOrdre_.push(ordre(false, a));
-
- // On execute la première commande
- idle_ = false;
- rotation(angle);
-}
-
-void Motor::recalage(void)
-{
- asserv_.fuckTheWall(-3); // XXX Mettre l'arg en conf
- //log_ ("recalage") << "Vitesse" << "-3";
- idle_ = false;
-}
-
-bool Motor::idle(void)
-{
- return idle_;
-}
-
-void Motor::linearMove(double d)
+ : asserv_ (*this), seq_ (0), finish_ (true), x_ (0.0), y_ (0.0), a_ (0.0)
{
- asserv_.linearMove(d);
- //log_ ("linearMove") << "Valeur" << d;
- idle_ = false;
}
-void Motor::rotation(double newA)
+/// Linear and angular move. T(mm) is the linear distance. A(mm) is the
+/// angular distance which means the arc length.
+void
+Motor::move (double t, double a)
{
- asserv_.angularMove(newA);
- //log_ ("rotation") << "Valeur" << newA;
- idle_ = false;
+ nextSeq ();
+ finish_ = false;
+ asserv_.speedTo (t, a, seq_);
}
-void Motor::setMaxSpeed(int maxLspeed, int maxRspeed)
+/// Rotate (rad).
+void
+Motor::rotate (double a)
{
- asserv_.setMaxSpeed(maxLspeed, maxRspeed);
+ nextSeq ();
+ finish_ = false;
+ asserv_.speedAngle (a, seq_);
}
-void Motor::setAccel(int accel)
+/// Find a hole.
+void
+Motor::findHole (void)
{
- asserv_.setAccel(accel);
-}
-
-int Motor::getMaxLSpeed(void)
-{
- return asserv_.getMaxLSpeed();
-}
-
-bool Motor::sync(void)
-{
- //log_("sync") << "Entré dans sync" << "";
-
- // On regarde si toutes les commandes ont été envoyées et aquittées
- if (asserv_.sync())
- {
- //log_("sync") << "Toutes les commandes ont été envoyés et aquitté" << "";
-
- if(doneDone_) // Si on a reçu des F depuis le dernier sync
- {
- //log_("sync") << "On a des F" << "";
- if(!f0Sended_) // Si on avait pas envoyé de f0
- {
- //log_("sync") << "On envoie le F0" << "";
- asserv_.finishAck();
- f0Sended_ = true;
- }
- else // Si l'AVR vient d'aquitter le F0
- {
- //log_("sync") << "On a déjà envoyé le F0, on s'en fout" << "";
- doneDone_ = false;
- }
- }
- else // Si on a pas reçu de F
- {
- //log_("sync") << "On a pas reçu de F" << "";
- if(f0Sended_) // On peut envoyer une nouvelle commande
- {
- //log_("sync") << "Pret pour un nouveau travail" << "";
- if(fOrdre_.empty()) //Si la pile est vide
- {
- //log_("sync") << "On repasse en Idle" << "";
- idle_ = true; // Les moteurs sont idle
- }
- else
- {
- //log_("sync") << "Prochaine commande de la pile" << "";
- if(fOrdre_.front().ordre_) // Linear Move
- linearMove(fOrdre_.front().arg_);
- else
- rotation(fOrdre_.front().arg_);
- fOrdre_.pop();
- }
- f0Sended_ = false;
- }
- // else
- //log_("sync") << "Le Robot est en activité/pause, on y touche pas" << "";
- }
- return true;
- }
- return false;
+ nextSeq ();
+ finish_ = false;
+ asserv_.findHole (seq_);
}
-bool
-Motor::wait(int timeout)
+/// Stop now.
+void
+Motor::stop (void)
{
- asserv_.wait(timeout);
- return sync ();
+ finish_ = true;
+ asserv_.speed (0, 0);
}
-/// Récupère le File Descriptor
-int Motor::getFd(void)
+/// Next seq number.
+void
+Motor::nextSeq (void)
{
- return asserv_.getFd();
+ seq_++;
+ if (seq_ > 250)
+ seq_ = 1;
}
-bool Motor::jackState(void)
+/// Implement Asserv::Receiver callbacks.
+void
+Motor::receiveAck (int seq)
{
- pinUpdated_ = false;
-/* asserv_.statInPort(8); /// XXX La période est défini comment?? (en dur, et c'est 8 période d'asserv)
- while(!pinUpdated_)
- {
- sync();
- }
- /// On fait fermer sa gueule à l'AVR sur l'epineux sujet du port d'entrée
- asserv_.statInPort(); */
- int temp = pinState_ & 0x0040; // XXX Ouais à tester
- if(temp == 0x0040) // si le jack est retiré
- return true;
- else
- return false;
+ if (seq != seq_)
+ std::cout << "spurious ack received" << std::endl;
+ asserv_.ack (seq);
+ finish_ = true;
}
-bool Motor::colorState (void)
+void
+Motor::receiveCounterStat (int l, int r)
{
- pinUpdated_ = false;
-/* asserv_.statInPort(1); /// XXX La période est défini comment?? (en dur, et c'est 8 période d'asserv)
- while(!pinUpdated_)
- {
- sync();
- } */
- int temp = pinState_ & 0x0002; // XXX Ouais à tester
- if(temp == 0x0002) // si le jack est retiré
- return true;
- else
- return false;
- /// On fait fermer sa gueule à l'AVR sur l'epineux sujet du port d'entrée
- //asserv_.statInPort();
}
-void Motor::receiveCounter (double lMotor, double rMotor)
+void
+Motor::receivePos (double x, double y, double a)
{
+ x_ = x;
+ y_ = y;
+ a_ = a;
}
-void Motor::receivePosX (double xPos)
+void
+Motor::receiveSpeedStat (int t, int a)
{
- posX_ = xPos;
}
-void Motor::receivePosY (double yPos)
+void
+Motor::receivePosStat (int te, int ti, int ae, int ai)
{
- posY_ = yPos;
}
-void Motor::receivePosA (double aPos)
+void
+Motor::receivePwmStat (int l, int r)
{
- posA_ = aPos;
}
-void Motor::receiveSpeedStat (int leftError, int leftInt, int rightError,
- int rightInt)
+void
+Motor::receiveTimerStat (const int *t, int tn)
{
}
-void Motor::receivePwm (double leftPwm, double rightPwm)
+void
+Motor::receiveInPort (unsigned int port)
{
}
-void Motor::receiveTiming (int motorTimer4,
- int motorTimer3, int motorTimer2,
- int motorTimer1, int motorTimer0)
-{
-}
-
-void Motor::receiveInPort (int port)
-{
- pinState_ = port;
- pinUpdated_ = true;
-}
-
-void Motor::receiveSharp (int sharp1, int sharp2, int sharp3)
-{
-}
-
-void Motor::receiveTazState(int state, int subState)
-{
-}
-
-void Motor::done (void)
-{
- //log_("done") << "Passage dans done" << "";
- doneDone_ = true;
-}
diff --git a/i/marvin/src/motor/motor.hh b/i/marvin/src/motor/motor.hh
index 1325c64..509ed8b 100644
--- a/i/marvin/src/motor/motor.hh
+++ b/i/marvin/src/motor/motor.hh
@@ -1,9 +1,9 @@
#ifndef motor_hh
#define motor_hh
// motor.hh
-// 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/
@@ -13,7 +13,7 @@
// 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
@@ -24,104 +24,48 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// }}}
-
#include "asserv/asserv.hh"
-#include <queue>
-
-/// Gère les moteurs de déplacement du robot
+/// Handle movements.
class Motor : public Asserv::Receiver
{
- struct ordre
- {
- // Ordre (true pour linéaire, false pour rotation
- bool ordre_;
- double arg_;
- // Constructeur
- ordre(bool ordre, double arg) { ordre_ = ordre; arg_ = arg; }
- };
- private:
- /// Communication avec l'asservissement
- Asserv asserv_;
- /// Système de log
- Log log_;
- /// Pile de commande
- std::queue<ordre> fOrdre_;
- /// position
- double posX_;
- double posY_;
- double posA_;
- double speed_;
- /// Etat des commandes
- bool idle_;
- /// Drapeau pour quand on a reçu un F
- bool doneDone_;
- /// Drapeau levé quand on a envoyé un "Ta Gueule"
- bool f0Sended_;
- /// Paramètre de conf
- int pStatPosition_;
- int pStatMotor_;
- /// Etat du port d'entrée
- int pinState_;
- bool pinUpdated_;
-
- public:
- /// Constructeur
- Motor (void);
- /// Initialise les moteurs
- void init(void);
- ///Arrête les moteurs
- void stop(void);
- /// Renvoie la position X
- double getX(void);
- /// Renvoie la position Y
- double getY(void);
- /// Renvoie l'angle A
- double getA(void);
- /// On set les positions dans l'avr
- void setPosition(double x, double y, double a);
- /// Ammène le robot à la position x,y
- void goTo(double x, double y, double a);
- /// Recale le robot
- void recalage(void);
- /// Indique si les moteurs sont occupé ou non
- bool idle (void);
- /// Execute un déplacement linéaire
- void linearMove(double d);
- /// Execute une rotation(argument en radian)
- void rotation(double newA);
- /// set de la vitesse des moteurs
- void setMaxSpeed(int maxLspeed, int maxRspeed);
- /// set de l'acceleration des moteurs
- void setAccel(int accel);
- /// récupère la vitesse linéaire maximum
- int getMaxLSpeed(void);
- /// Syncronisation
- bool sync(void);
- /// On attend...
- bool wait(int timeout = -1);
- /// Récupère le File Descriptor
- int getFd(void);
- /// Retoure l'état du jack (false entrée et true sortie)
- bool jackState(void);
- /// Retourne la couleur selectionné
- bool colorState (void);
- /// déclaration des fonctions de receiver
- void receiveCounter (double lMotor, double rMotor);
- void receivePosX (double xPos);
- void receivePosY (double yPos);
- void receivePosA (double aPos);
- void receiveSpeedStat (int leftError, int leftInt, int rightError,
- int rightInt);
- void receivePwm (double leftPwm, double rightPwm);
- // Défini les valeurs de la PWM
- void setPwm(int leftPwm = 0, int rightPwm = 0);
- void receiveTiming (int motorTimer4,
- int motorTimer3, int motorTimer2,
- int motorTimer1, int motorTimer0);
- void receiveInPort (int port);
- void receiveSharp (int sharp1, int sharp2, int sharp3);
- void receiveTazState(int state, int subState); // XXX Vérifier les formats
- void done (void);
+ private:
+ Asserv asserv_;
+ int seq_;
+ bool finish_;
+ double x_, y_, a_;
+ public:
+ /// Constructor.
+ Motor (void);
+ /// Try to empty emission queue, return true if empty.
+ bool sync (void) { return asserv_.sync (); }
+ /// Wait until emission queue is empty or timed out.
+ bool wait (int timeout = -1) { return asserv_.wait (timeout); }
+ /// Get asserv reference to change parameters.
+ Asserv &getAsserv (void) { return asserv_; }
+ /// True if last long move is finished.
+ bool finish (void) const { return finish_; }
+ /// Linear and angular move. T(mm) is the linear distance. A(mm) is the
+ /// angular distance which means the arc length.
+ void move (double t, double a);
+ /// Rotate (rad).
+ void rotate (double a);
+ /// Find a hole.
+ void findHole (void);
+ /// Stop now.
+ void stop (void);
+ private:
+ /// Next seq number.
+ inline void nextSeq (void);
+ /// Implement Asserv::Receiver callbacks.
+ void receiveAck (int seq);
+ void receiveCounterStat (int l, int r);
+ void receivePos (double x, double y, double a);
+ void receiveSpeedStat (int t, int a);
+ void receivePosStat (int te, int ti, int ae, int ai);
+ void receivePwmStat (int l, int r);
+ void receiveTimerStat (const int *t, int tn);
+ void receiveInPort (unsigned int port);
};
-#endif // motor.hh
+
+#endif // motor_hh
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;
+ }
}