-
Notifications
You must be signed in to change notification settings - Fork 0
/
MakisumiACMotor.h
113 lines (90 loc) · 1.94 KB
/
MakisumiACMotor.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
113
// Chiba Institute of Technology
#ifndef MAKISUMI_ACMOTOR_H
#define MAKISUMI_ACMOTOR_H
#include "mbed.h"
/** Class to control a motor on any pin, without using pwm pin
*
* Example:
* @code
* // MakisumiACMotor Control
* #include "mbed.h"
* #include "MakisumiACMotor.h"
*
* MakisumiACMotor acmotor();
*
* int main(){
* int previous_hole_state = 6;
* acmotor.servoOn();
* acmotor = 0.1; // duty ratio
* while(1){
* if (acmotor.getHoleState() != previous_hole_state){
* acmotor.status_changed();
* previous_hole_state = acmotor.getHoleState();
* }
* }
* }
* @endcode
*/
class MakisumiACMotor
{
public:
/** Create a new SoftwarePWM object on any mbed pin
*
* @param Pin Pin on mbed to connect PWM device to
*/
MakisumiACMotor(PinName Ppwm);
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);
#ifdef MBED_OPERATORS
/** A operator shorthand for write()
*/
MakisumiACMotor& operator= (float value) {
write(value);
return *this;
}
MakisumiACMotor& operator= (MakisumiACMotor& rhs) {
write(rhs.read());
return *this;
}
/** An operator shorthand for read()
*/
operator float() {
return read();
}
#endif
private:
InterruptIn pwm_int_;
PwmOut pwm_;
InterruptIn hole1_;
InterruptIn hole2_;
InterruptIn hole3_;
double value_;
double period_sec_;
double max_ratio_;
bool enable_;
int hole_state;
int hole_state_no;
static int switching_table[6][3];
void drive(int u, int v, int w);
void pwmRise(void);
void pwmFall(void);
int on_swtiching_ptn[6];
int off_swtiching_ptn[6];
enum h_bridge{
UH = 0,
UL,
VH,
VL,
WH,
WL,
};
bool underChanging;
};
#endif