summaryrefslogtreecommitdiff
path: root/i/marvin/src/asserv/asserv.hh
diff options
context:
space:
mode:
Diffstat (limited to 'i/marvin/src/asserv/asserv.hh')
-rw-r--r--i/marvin/src/asserv/asserv.hh238
1 files changed, 109 insertions, 129 deletions
diff --git a/i/marvin/src/asserv/asserv.hh b/i/marvin/src/asserv/asserv.hh
index b3d3183..86cbb23 100644
--- a/i/marvin/src/asserv/asserv.hh
+++ b/i/marvin/src/asserv/asserv.hh
@@ -1,11 +1,11 @@
#ifndef asserv_hh
#define asserv_hh
// asserv.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.
+// Robot APB Team/Efrei 2006.
// Web: http://assos.efrei.fr/robot/
// Email: robot AT efrei DOT fr
//
@@ -25,135 +25,115 @@
//
// }}}
-#include "utils/non_copyable.hh"
#include "proto/proto.hh"
-#include "log/log.hh"
-/// Classe de dialogue avec la carte d'asservissement.
-class Asserv : public NonCopyable, public Proto::Receiver
+/// Dialog class with the motor control board.
+/// Units:
+/// - step: one step distance.
+/// - period: one motor control sampling period.
+class Asserv : public Proto::Receiver
{
- public:
- /// Les clients de Asserv doivent dériver de Receiver.
- class Receiver
- {
- public:
- virtual ~Receiver(void){};
- /// Recoit un packet.
- virtual void receiveCounter (double lMotor, double rMotor) = 0;
- virtual void receivePosX (double xPos) = 0;
- virtual void receivePosY (double yPos) = 0;
- virtual void receivePosA (double aPos) = 0;
- virtual void receiveSpeedStat (int leftError, int leftInt, int rightError, int rightInt) = 0;
- virtual void receivePwm (double leftPwm, double rightPwm) = 0;
- virtual void receiveTiming (int motorTimer4,
- int motorTimer3, int motorTimer2,
- int motorTimer1,
- int motorTimer0 ) = 0;
- virtual void receiveInPort (int port) = 0;
- virtual void receiveSharp (int sharp1, int sharp2, int sharp3) = 0;
- virtual void receiveTazState(int state, int subState){}; // XXX Vérifier les formats
- virtual void done (void) = 0;
- };
-
- private:
-
- // Communication avec l'AVR
- Proto proto_;
- std::string ttyName_;
- Receiver & receiver_;
- // Paramètre de l'avr
- int footing_; //truc
- double epsilon_; //mm
- int accel_; //unité AVR
- int kp_;
- int ki_;
- int kd_;
- int eSat_;
- int speedIntMax_;
- int dSample_;
- int maxSLin_;//unité AVR
- int maxSRot_;
- bool leftInvPwm_, rightInvPwm_;
- bool useTazFSM_;
- // Stat
- int pCounter_;
- int pPosition_;
- int pMotor_;
- int pPwm_;
- int pTiming_;
- int pStatInPort_;
- int pSharp_;
-
- // Unités
- double mmPpas_;
- double sPperiod_;
- int pwmMax_;
-
- // Système de log.
- Log log_;
- public:
- /// Constructeur.
- Asserv (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);
- /// Récupère le File Descriptor
- int getFd(void);
- /// Commandes asservissement
- void linearMove(double distance);
- void angularMove(double angle);
- void goToPosition(double xPos, double yPos);
- void fuckTheWall(double speed);
- void fuckTheWall(int speed);
- void setSpeed(double xSpeed, double ySpeed);
- void setSpeed(int xSpeed = 0, int ySpeed = 0);
- void setPwm(int leftPwm = 0, int rightPwm = 0);
- void finishAck(void); //met le paramètre F à 0
- /// Statistiques
- void statCounter(int period = 0);
- void statPosition(int period = 0);
- void statMotor(int period = 0);
- void statPwm(int period = 0);
- void statTiming(int period = 0);
- void statInPort(int period = 0);
- void statSharp(int 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 (int kp);
- void setKi (int ki);
- void setKd (int kd);
- void setESat (int eSat);
- void setSpeedIntMax (int maxInt);
- void setDSample(int dSample);
- void setAccel (int accel);
- double getAccel (void);
- void setMaxSpeed(int maxSLin, int maxSRot);
- int getMaxLSpeed(void);
- void setUseTazFSM(bool use);
- void setInvPwm(bool leftInvPwm, bool rightInvPwm);
- //@}
-
- /// implémentation du proto::Receiver
- void receive (char command, const Proto::Frame &frame);
-
- private:
- /// Charge les données de la classe config
- void loadConfig ();
- /// Fonctions de conversion
- int mm2pas(double dist, bool format24eme = false); //Format 24/8 ou 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)
+ public:
+ /// Asserv clients must implement Receiver.
+ class Receiver
+ {
+ public:
+ virtual ~Receiver (void) { }
+ virtual void receiveAck (int seq) = 0;
+ virtual void receiveCounterStat (int l, int r) = 0;
+ virtual void receivePos (double x, double y, double a) = 0;
+ virtual void receiveSpeedStat (int t, int a) = 0;
+ virtual void receivePosStat (int te, int ti, int ae, int ai) = 0;
+ virtual void receivePwmStat (int l, int r) = 0;
+ virtual void receiveTimerStat (const int *t, int tn) = 0;
+ virtual void receiveInPort (unsigned int port) = 0;
+ };
+ private:
+ Proto proto_;
+ std::string tty_;
+ Receiver &receiver_;
+ int intervalCounterStat_, intervalPos_, intervalSpeedStat_,
+ intervalPosStat_, intervalPwmStat_, intervalTimerStat_,
+ intervalInPort_;
+ int footing_;
+ int tAccel_, aAccel_;
+ int tMaxSpeed_, aMaxSpeed_;
+ int tkp_, tki_, tkd_, akp_, aki_, akd_, esat_, isat_;
+ bool lInvertPwm_, rInvertPwm_;
+ double stepPerMm_;
+ public:
+ /// Constructor.
+ Asserv (Asserv::Receiver &receiver);
+ /// 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);
+ /// Récupère le File Descriptor
+ int getFd (void);
+ /// Reset the board and send parameters.
+ void reset (void);
+ /// Set PWM.
+ void setPwm (int l, int r);
+ /// Position consign offset.
+ void positionOffset (double t, double a);
+ /// Set speed.
+ void setSpeed (int t, int a);
+ /// Speed controlled position consign offset.
+ void setSpeedControlled (double t, double a, int seq);
+ /// Find a hole.
+ void findHole (int seq);
+ /// Acknoledge.
+ void ack (int seq);
+ /// Change counter stat interval.
+ void setIntervalCounterStat (int i);
+ /// Change position report interval.
+ void setIntervalPos (int i);
+ /// Change speed stat interval.
+ void setIntervalSpeedStat (int i);
+ /// Change position control stat interval.
+ void setIntervalPosStat (int i);
+ /// Change pwm stat interval.
+ void setIntervalPwmStat (int i);
+ /// Change timer stat interval.
+ void setIntervalTimerStat (int i);
+ /// Change input port report interval.
+ void setIntervalInPort (int i);
+ /// Set current position.
+ void setPos (double x, double y, double a);
+ /// Set current x position.
+ void setXPos (double x);
+ /// Set current y position.
+ void setYPos (double y);
+ /// Set current angle.
+ void setAPos (double a);
+ /// Set footing.
+ void setFooting (int f);
+ /// Set acceleration.
+ void setAccel (int t, int a);
+ /// Set maximum speed for automatic movements.
+ void setMaxSpeed (int t, int a);
+ /// Set motor control coeficients.
+ void setCoef (int tkp, int tki, int tkd, int akp, int aki, int akd,
+ int esat, int isat);
+ /// Set PWM direction.
+ void setPwmDir (bool invertL, bool invertR);
+ /// Store to eeprom.
+ void storeParams (void);
+ /// Clear eeprom.
+ void clearParams (void);
+ /// Implémentation du proto::Receiver.
+ void receive (char command, const Proto::Frame &frame);
+ private:
+ /// Convert mm to steps.
+ int mmToStep (double mm) const;
+ /// Convert steps to mm.
+ double stepToMm (int step) const;
+ /// Convert rad to avr angles.
+ int radToAvr (double a) const;
+ /// Convert avr angles to rad.
+ double avrToRad (int a) const;
+ /// Convert rad to steps.
+ int radToStep (double a) const;
};
#endif // asserv_hh