summaryrefslogtreecommitdiff
path: root/i/marvin/src/asserv/asserv.hh
blob: 0d9f5a2fe966c4af27e7087e82756994aa347ae7 (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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#ifndef asserv_hh
#define asserv_hh
// asserv.hh
// marvin - programme du robot 2006. {{{
//
// Copyright (C) 2006 Nicolas Schodet
//
// Robot APB Team/Efrei 2006.
//        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 "proto/proto.hh"

/// Dialog class with the motor control board.
/// Units:
///  - step: one step distance.
///  - period: one motor control sampling period.
class Asserv : public Proto::Receiver
{
  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_, tMaxSpeedSlow_, aMaxSpeedSlow_;
    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 pwm (int l, int r);
    /// Position consign offset.
    void offset (double t, double a);
    /// Set speed.
    void speed (int t, int a);
    /// Speed controlled position consign offset.
    void speedTo (double t, double a, int seq);
    /// Speed controlled angle consign offset.
    void speedAngle (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 setAngle (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, int ts, int as);
    /// 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