summaryrefslogtreecommitdiff
path: root/2005/i/robert/src/asserv/asserv.hh
blob: 08b8aa013df8c27ff3aaf2a5cda4e04159c75951 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#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 "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 receive (char command, const Frame &frame) = 0;
    };
    // Communication avec l'AVR
    Proto proto_;
    std::string ttyName_;
    // Param�tre de l'avr
    double footing_;
    double epsilon_;
    double accel_;
    double kp_;
    double ki_;
    double kd_;
    double maxSpeed_;
    
    // Syst�me de log.
    Log log_;
  public:
    /// Constructeur.
    Asserv (const Config & config, Receiver & receiver);
    /// Destructeur.
    ~Asserv (void);
    /// 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(int8_t angle);
    void goToPosition(int32_t xPos, int32_t yPos);
    void fuckTheWall(int8_t speed);
    void setSpeed(int8_t xSpeed = 0, int8_t ySpeed = 0);
    void setPwm(int16_t leftPwm = 0, int16_t rightPwm = 0);
    /// Statistiques
    void statCounter(int8_t period = 0);
    void statPosition(int8_t period = 0);
    void statMotor(int8_t period = 0);
    void statPwm(int8_t period = 0);
    void statTimer(int8_t period = 0);
    void statInPort(int8_t period = 0);
    //@{
    /// Change les param�tres de la carte.
    void setXPos(int32_t pos);
    void setYPos(int32_t pos);
    void setAngle(int32_t angle);
    void setFooting(int32_t dist);
    void setEpsilon(int32_t e);
    void setAccel (int accel);
    void setKp (int kp);
    void setKi (int ki);
    void setKd (int kd);
    void setMaxSpeed(int16_t);
    //@}

    /// impl�mentation du proto::Receiver
    void receive (char command, const Frame &frame);

  private:
    /// Charge les donn�es de la classe config 
    void loadConfig(void);
    /// Fonctions de conversion
    int mm2pasW(double dist);
    int mm2pasD(double dist);
    int radTo256(double angle);
    int mms2ppp(double vitesse);
    int rCycl2Pwm(double rCycl);
    


};

#endif // asserv_h