-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHBridgeMotor.h
More file actions
63 lines (51 loc) · 1.3 KB
/
HBridgeMotor.h
File metadata and controls
63 lines (51 loc) · 1.3 KB
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
#ifndef HBridgeMotor_h
#define HBridgeMotor_h
#include "Motor.h"
// Pin modes:
#define ONE_PIN 1
#define TWO_PIN 2
#define HBRIDGE_MOTOR_2K 0
#define HBRIDGE_MOTOR_1KH 1
#define HBRIDGE_MOTOR_1K 2
#define HBRIDGE_MOTOR_2KH 3
struct HBridgeConfig {
// ONE_PIN or TWO_PIN
int pinMode;
// Configuration for directions as bits.
// pin positions:
// 0 0 0 0 0 0 0 0
// | |_ pin1
// |___ pin2
unsigned short bitsForward;
unsigned short bitsReverse;
unsigned short bitsBrake;
unsigned short bitsStop;
};
const HBridgeConfig hBConfigs[] = {
// HBRIDGE_MOTOR_2K
{ONE_PIN,0x0,0x1,0x2,0x3},
// HBRIDGE_MOTOR_1KH
{TWO_PIN,0x1,0x2,0x0,0x0},
// HBRIDGE_MOTOR_1K
// For this motor the PWM logic is reverse, so 0 is max power
{TWO_PIN,0x2,0x1,0x0,0x0},
// HBRIDGE_MOTOR_2KH
{TWO_PIN,0x1,0x2,0x0,0x0}
};
class HBridgeMotor : public Motor {
public:
HBridgeMotor(int motorType);
void setup(MotorConfig motorConfig);
void forward();
void reverse();
void brake();
void stop();
void setPWM(int pwm);
private:
MotorConfig motorConfig;
HBridgeConfig hBConfig;
void writeBits(short bits);
int pwm;
void enable(bool on);
};
#endif