-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmotor.h
75 lines (62 loc) · 1.74 KB
/
motor.h
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
#include <bcm2835.h>
#include <limits.h>
// motor pins definitions
#define ENABLE 26 // ENABLE HIGH <=> motor disabled
#define STEP_M1 6
#define DIR_M1 5
#define STEP_M2 19
#define DIR_M2 13
//definitions to speed up the code
#define STEP_PIN_M1 (1 << STEP_M1)
#define DIR_PIN_M1 (1 << DIR_M1)
#define PINS_M1 (1 << STEP_M1) | (1 << DIR_M1)
#define STEP_PIN_M2 (1 << STEP_M2)
#define DIR_PIN_M2 (1 << DIR_M2)
#define PINS_M2 (1 << STEP_M2) | (1 << DIR_M2)
// number of steps for one revolution
#define REVOLUTION 3200 // number of steps for one revolution
//debugging
#define DEBUG TRUE
// créer une classe abstraite
class Motor
{
public:
Motor();
~Motor();
bool valid = false;
unsigned int delay = 1<<16; // default delay to be near stop
int steps = 0;
bool dir;
//void run(bool &isvalid, unsigned int &delay, int &steps);
virtual void run() = 0;
private:
// déclaration des méthodes abstraites
//virtual const int &StepPin() const = 0;
//virtual const int &DirPin() const = 0;
protected:
void init();
};
class Motor1 : public Motor
{
public:
inline Motor1(){
init();
}
void run();
protected:
// définition des méthodes abstraites pour appeler StepPin et DirPin
//const int &StepPin() const { return STEP_M1; }
//const int &DirPin() const { return DIR_M1; }
};
class Motor2 : public Motor
{
public:
inline Motor2(){
init();
}
void run();
protected:
// définition des méthodes abstraites pour appeler StepPin et DirPin
//const int &StepPin() const { return STEP_M2; }
//const int &DirPin() const { return DIR_M2; }
};