summaryrefslogtreecommitdiff
path: root/2004/i/nono/src/motor/asserv.h
diff options
context:
space:
mode:
authorschodet2004-02-07 16:55:41 +0000
committerschodet2004-02-07 16:55:41 +0000
commit9fdd6704947174fae292dfc6e14cc1029a7f7a6c (patch)
tree40a4fe775845ececdaf27e82d99d6a06f6b3803e /2004/i/nono/src/motor/asserv.h
parentb673946d76e436c067d24e535b1e0a167b9dfc47 (diff)
Initial revision
Diffstat (limited to '2004/i/nono/src/motor/asserv.h')
-rw-r--r--2004/i/nono/src/motor/asserv.h106
1 files changed, 106 insertions, 0 deletions
diff --git a/2004/i/nono/src/motor/asserv.h b/2004/i/nono/src/motor/asserv.h
new file mode 100644
index 0000000..d6f1da1
--- /dev/null
+++ b/2004/i/nono/src/motor/asserv.h
@@ -0,0 +1,106 @@
+#ifndef asserv_h
+#define asserv_h
+// asserv.h
+// nono - programme du robot 2004. {{{
+//
+// Copyright (C) 2004 Nicolas Schodet
+//
+// Robot APB Team/Efrei 2004.
+// 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 "serial/serial.h"
+
+#include <string>
+#include <queue>
+
+// Class dont on doit dériver pour pouvoir recevoir les informations de la
+// carte d'asservissement.
+class AsservTracker
+{
+ public:
+ // Appelée lors d'une mise à jour des compteurs.
+ virtual void updateCounter (int l, int r) { }
+};
+
+class Asserv
+{
+ // Ligne série.
+ Serial serial_;
+ std::string ttyname_;
+ // Paramètres.
+ int accel_, kp_, ki_, kd_;
+ bool statMotor_, counter_;
+ // File d'emmission.
+ std::queue<std::string> sendQueue_;
+ // Table de conversion en hexa.
+ static const char *hexaTbl_;
+ // Buffer de reception.
+ int inBufSize_, inBufPos_;
+ char *inBuf_;
+ // Anciènne valeur des compteur.
+ bool firstCounter_;
+ int countLeft_, countRight_;
+ // Objet interessé par les stats.
+ AsservTracker &asservTracker_;
+ public:
+ // Constructeur.
+ Asserv (AsservTracker &asservTracker);
+ // Destructeur.
+ ~Asserv (void);
+ // Reset la carte et envois les paramètres.
+ void reset (void);
+ // Active l'asservissement.
+ void go (bool fl = true);
+ // Stop !
+ void stop (void);
+ // Réglage de la vitesse.
+ void speed (int l, int r);
+ // Teste si l'émission est terminée.
+ bool ok (void);
+ // Attend que toute les émissions soit terminées.
+ void waitOk (void);
+ // Lit et traite les messages de la cartes.
+ void read (void);
+ // Change les paramètres de la carte.
+ void setAccel (int accel);
+ int getAccel (void) { return accel_; }
+ void setKp (int kp);
+ void setKi (int ki);
+ void setKd (int kd);
+ void setStatMotor (bool fl = true);
+ void setCounter (bool fl = true);
+ protected:
+ // Envoie un message.
+ void send (char com);
+ void send (char com, bool fl);
+ void send (char com, int a1);
+ void send (char com, int a1, int a2);
+ // Renvois le dernier message.
+ void sendLast (void);
+ // Traite un message.
+ void handleMessage (void);
+ // Traite un message du compteur.
+ void handleCounter (void);
+ // Décode un mot signé (2 octets).
+ int getSignedShort (const char *s) const;
+ // Décode un chiffre hexa.
+ int hex2digit (char c) const;
+};
+
+#endif // asserv_h