#ifndef asserv_hh #define asserv_hh // asserv.hh // 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 "utils/non_copyable.hh" #include "config/config.hh" #include "proto/proto.hh" #include "log/log.hh" /// Classe de dialogue avec la carte d'asservissement. class Asserv : public NonCopyable, public Proto::Receiver { /// Les clients de Asserv doivent dériver de Receiver. class Receiver { public: /// Recoit un packet. virtual void receiveCounter (double lMotor, double rMotor) = 0; virtual void receivePosition (double command) = 0; virtual void receivePosX (double xPos) = 0; virtual void receivePosY (double yPos) = 0; virtual void receivePosA (double aPos) = 0; virtual void receiveMotor (int oldLSpeed_e, int LSpeed_int, int oldRSpeed_e, int RSpeed_int) = 0; virtual void receivePwm (double leftPwm, double rightPwm) = 0; virtual void receiveTiming (double motorTimer5, double motorTimer4, double motorTimer3, double motorTimer2, double motorTimer1, double motorTimer0 ) = 0; virtual void receiveInPort (double command) = 0; virtual void jaifini (void) = 0; }; // Communication avec l'AVR Proto proto_; std::string ttyName_; Receiver & receiver_; // Paramètre de l'avr int16_t footing_; double epsilon_; double accel_; double kp_; double ki_; double kd_; double maxSpeed_; double maxPwn_; // Stat double pCounter_; double pPosition_; double pMotor_; double pPwm_; double pTiming_; double pStatInPort_; // Unités double mmPpas_; double sPperiod_; double pwmMax_; // Système de log. Log log_; public: /// Constructeur. Asserv (const Config & config, Asserv::Receiver & receiver); /// Reset la carte et envois les paramètres. void reset (void); /// Essaie de purger la liste d'émission et indique si elle est vide. bool sync (void); /// Attend que toute les émissions soit terminées. bool wait (int timeout = -1); /// Commandes asservissement void linearMove(double distance); void angularMove(double angle); void goToPosition(double xPos, double yPos); void fuckTheWall(double speed); void setSpeed(double xSpeed = 0, double ySpeed = 0); void setPwm(double leftPwm = 0, double rightPwm = 0); void finishAck(void); //met le paramètre F à 0 /// Statistiques void statCounter(double period = 0); void statPosition(double period = 0); void statMotor(double period = 0); void statPwm(double period = 0); void statTiming(double period = 0); void statInPort(double period = 0); //@{ /// Change les paramètres de la carte. void setXPos(double pos); void setYPos(double pos); void setAngle(double angle); void setFooting(int16_t dist); void setEpsilon(double e); void setKp (double kp); void setKi (double ki); void setKd (double kd); void setSpeedIntMax (int16_t maxInt); void setAccel (double accel); void setMaxSpeed(double maxSpeed); //@} /// implémentation du proto::Receiver void receive (char command, const Proto::Frame &frame); private: /// Charge les données de la classe config void loadConfig(const Config & config); /// Fonctions de conversion int mm2pasD(double dist); //Format 24/8 int radTo256(double angle, bool format24eme = false); //Format 8 ou 8/24 int mms2ppp(double vitesse); // Format 8 int rCycl2Pwm(double rCycl); // Format 16 int s2period(double period); // Format 8 int mmps2ppperiod(double accel); //Format 8 (1 vitesse par x period) }; #endif // asserv_h // Vérifier le format finale des conversions // Vérifier toutes les commandes passé à l'AVR // Faire la fonction receive