-
Notifications
You must be signed in to change notification settings - Fork 1
/
STM_BLDCMotor.h
112 lines (87 loc) · 1.83 KB
/
STM_BLDCMotor.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
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
// Chiba Institute of Technology
#ifndef STM_BLDCMOTOR_H
#define STM_BLDCMOTOR_H
#include "mbed.h"
/** Class to control a motor on any pin, without using pwm pin
*
* Example:
* @code
* // STM_BLDCMotor Control
* #include "mbed.h"
* #include "STM_BLDCMotor.h"
*
* STM_BLDCMotor motor;
*
* int main(){
* motor.servoOn();
* motor = 0.1; // duty ratio
* }
* @endcode
*/
class STM_BLDCMotor
{
public:
/** Create a new SoftwarePWM object on any mbed pin
*
* @param Pin Pin on mbed to connect PWM device to
*/
STM_BLDCMotor();
void servoOn(void);
void servoOff(void);
void setMaxDutyRatio(float max_ratio);
void setPwmPeriod(double seconds);
void write(double value);
float read();
int getHoleState();
int getState();
void status_changed(void);
int getHoleSensorCount();
void resetHoleSensorCount();
#ifdef MBED_OPERATORS
/** A operator shorthand for write()
*/
STM_BLDCMotor& operator= (float value) {
write(value);
return *this;
}
STM_BLDCMotor& operator= (STM_BLDCMotor& rhs) {
write(rhs.read());
return *this;
}
/** An operator shorthand for read()
*/
operator float() {
return read();
}
#endif
private:
PwmOut uh_;
DigitalOut ul_;
PwmOut vh_;
DigitalOut vl_;
PwmOut wh_;
DigitalOut wl_;
InterruptIn hole1_;
InterruptIn hole2_;
InterruptIn hole3_;
double value_;
double period_sec_;
double max_ratio_;
bool enable_;
int hole_state;
int hole_state_no;
int previous_hole_state_no;
int hole_sensor_count;
int prev_count_diff;
static int switching_table[6][3];
void drive(int u, int v, int w);
enum h_bridge{
UH = 0,
UL,
VH,
VL,
WH,
WL,
};
};
#endif