summaryrefslogtreecommitdiff
path: root/i/marvin/src/motor/motor.hh
blob: 1c6f403af810029683f35f1c6344374ced5122ef (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
#ifndef motor_hh
#define motor_hh
// motor.hh
// marvin - programme du robot 2006. {{{
//
// Copyright (C) 2006 Nicolas Schodet
//
// 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 "asserv/asserv.hh"

/// Handle movements.
class Motor : public Asserv::Receiver
{
  private:
    Asserv asserv_;
    int seq_;
    bool finish_;
    double x_, y_, a_;
  public:
    /// Constructor.
    Motor (void);
    /// Try to empty emission queue, return true if empty.
    bool sync (void) { return asserv_.sync (); }
    /// Wait until emission queue is empty or timed out.
    bool wait (int timeout = -1) { return asserv_.wait (timeout); }
    /// Get asserv reference to change parameters.
    Asserv &getAsserv (void) { return asserv_; }
    /// True if last long move is finished.
    bool finish (void) const { return finish_; }
    /// Linear and angular move. T(mm) is the linear distance.  A(mm) is the
    /// angular distance which means the arc length.
    void move (double t, double a);
    /// Rotate (rad).
    void rotate (double a);
    /// Find a hole.
    void findHole (void);
    /// Lock good hole (approximatively...)
    void lockGoodHole(void);
    /// Lock ennemy hole (non pas son cul)
    void lockBadHole(void);
    /// Stop now.
    void stop (void);
    /// get the file descriptor
    int getFd(void);
    /// Reset.
    void reset (void);
  private:
    /// Next seq number.
    inline void nextSeq (void);
    /// Implement Asserv::Receiver callbacks.
    void receiveAck (int seq);
    void receiveCounterStat (int l, int r);
    void receivePos (double x, double y, double a);
    void receiveSpeedStat (int t, int a);
    void receivePosStat (int te, int ti, int ae, int ai);
    void receivePwmStat (int l, int r);
    void receiveTimerStat (const int *t, int tn);
    void receiveInPort (unsigned int port);
};

#endif // motor_hh