From 7d1f86949f4b72895aaf675a1f001d834160369b Mon Sep 17 00:00:00 2001 From: haller Date: Sun, 24 Apr 2005 21:27:07 +0000 Subject: Début d'implémentation des fonctions Y'a encore du boulot --- 2005/i/robert/src/motor/motor.cc | 153 +++++++++++++++++++++++++++++++++++++++ 2005/i/robert/src/motor/motor.hh | 32 +++++++- 2 files changed, 182 insertions(+), 3 deletions(-) (limited to '2005/i/robert/src/motor') diff --git a/2005/i/robert/src/motor/motor.cc b/2005/i/robert/src/motor/motor.cc index 6809acd..3b48104 100644 --- a/2005/i/robert/src/motor/motor.cc +++ b/2005/i/robert/src/motor/motor.cc @@ -23,3 +23,156 @@ // // }}} +#include "motor.hh" + +/// Constructeur +Motor::Motor (const Config & config) // XXX Voir si besoin de config + :asserv_(config, *this), idle_(true) +{ +} + +/// Initialise les moteurs +void Motor::init (void) +{ + // on reset la carte + asserv_.reset(); + // On stop le moteur + stop(); + // on règle le rafraichissement des positions + asserv_.statPosition(1); /// XXX Le temps combien et réglé ou?? + asserv_.statMotor(1); + // on remet les position à 0 XXX à 0? + posX_ = posY_ = posA_ = 0; + // on regarde si les moteurs sont idle + while (!idle()) {} // XXX humhum? +} + +// Arrête les moteurs +void Motor::stop(void) +{ + asserv_.setSpeed(0,0); + // XXX Peut-on lui dire d'oublier une commande? + while(!idle()){} ///XXX vaut mieux appeler la commande ou la var? +} + +double Motor::getX(void) +{ + sync(); // XXX attendre true?? + return posX_; +} + +double Motor::getY(void) +{ + sync(); + return posY_; +} + +double Motor::getA(void) +{ + sync(); + return posA_; +} + +void Motor::goTo(double x, double y, double a) +{ + // XXX Méthode carré ou pas? +} + +void Motor::recalage(void) +{ + // XXX je ne vois pas là +} + +void Motor::setSpeed(double v) +{ + asserv_.setSpeed(v,v); /// XXX sur ca? + idle_ = false; + sync(); // XXX avant ou après? +} + +bool Motor::idle(void) +{ + sync(); + return idle_; +} + +void Motor::linearMove(double d) +{ + sync(); + asserv_.linearMove(d); + idle_ = false; +} + +void Motor::rotation(double newA) //Est-ce un nouveau angle asb ou rel?? +{ + sync(); + asserv_.angularMove(newA); + idle_ = false; +} + +bool Motor::sync(void) +{ + return asserv_.sync(); +} + +void Motor::receiveCounter (double lMotor, double rMotor) +{ + /// XXX que faire +} + +void Motor::receivePosX (double xPos) +{ + posX_ = xPos; +} + +void Motor::receivePosY (double yPos) +{ + posY_ = yPos; +} + +void Motor::receivePosA (double aPos) +{ + posA_ = aPos; +} + +void Motor::receiveSpeedStat (int leftError, int leftInt, int rightError, + int rightInt) +{ + if(leftInt == 0 && rightInt == 0) // XXX c'est bon ca? + idle_ = true; + else + idle_ = false; +} + +void Motor::receivePwm (double leftPwm, double rightPwm) +{ + // XXX que faire?? +} + +void Motor::receiveTiming (int motorTimer4, + int motorTimer3, int motorTimer2, + int motorTimer1, int motorTimer0) +{ + // XXX Que faire??? +} + +void Motor::receiveInPort (int port) +{ + // XXX Que faire? +} + +void Motor::receiveSharp (int sharp1, int sharp2, int sharp3) +{ + // XXX Que faire? +} + +void Motor::receiveTazState(int state, int subState) +{ + // XXX Que faire? +} + +void Motor::done (void) +{ + idle_ = true; + asserv_.finishAck(); +} diff --git a/2005/i/robert/src/motor/motor.hh b/2005/i/robert/src/motor/motor.hh index 22298e0..f81af49 100644 --- a/2005/i/robert/src/motor/motor.hh +++ b/2005/i/robert/src/motor/motor.hh @@ -26,14 +26,21 @@ // }}} #include "config/config.hh" +#include "asserv/asserv.hh" /// Gère les moteurs de déplacement du robot -class Motor +class Motor : public Asserv::Receiver { private: + /// Communication avec l'asservissement + Asserv asserv_; + /// position double posX_; double posY_; + double posA_; double speed_; + /// Etat des commandes + bool idle_; public: /// Constructeur @@ -46,8 +53,10 @@ class Motor double getX(void); /// Renvoie la position Y double getY(void); + /// Renvoie l'angle A + double getA(void); /// Ammène le robot à la position x,y - void goTo(double x, double y); + void goTo(double x, double y, double a); /// Recale le robot void recalage(void); /// Règle la vitesse des moteurs @@ -57,6 +66,23 @@ class Motor /// Execute un déplacement linéaire void linearMove(double d); /// Execute une rotation(argument en radian) - void rotation(double a); + void rotation(double newA); + /// Syncronisation + bool sync(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); + 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); }; #endif // motor.hh -- cgit v1.2.3