This repository has been archived by the owner on Dec 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
MegaMotoHB.h
138 lines (119 loc) · 3.71 KB
/
MegaMotoHB.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/********************************************//**
* \file MegaMotoHB.h
* \author Alexander Hogen
* \date 1/11/2017
* \version 0.1
* \brief H-Bridge configuration -- An Arduino
* library to control the MegaMoto motor
* controller family by Robot Power
*
* The MegaMotoHB class is a derived class from
* the MegaMotoBase base class. You should use the
* MegaMotoHB class if your device you are controlling
* is wired in an H-bridge configuration (hence
* the "HB" at the end of the class name). If
* You do not know what this means, then you
* probably haven't checked out the MegaMoto
* User Guide written by the people who made
* it, Robot Power! Go have a look first. Things
* over here might make more sense afterwards.
* Trust me.
*
* NOTE: References to MegaMoto, MegaMoto Plus,
* or Robot Power are either reserved or
* trademarked by Robot Power:
*
* 2745 Martin Way E, Suite D
* Olympia, WA 98506
* http://www.robotpower.com/
*
* I do not own or claim ownership to these names.
*
* Released into the public domain.
*
* [1] "MegaMoto & MegaMoto Plus User Manual," Robot Power,
* Version 1.6, May 28, 2016.
* Avaliable: http://www.robotpower.com/downloads/MegaMoto-user-manual.pdf
***********************************************/
#ifndef MEGAMOTOHB_H
#define MEGAMOTOHB_H
#include "MegaMotoBase.h"
/********************************************//**
* \class MegaMotoHB
* \brief MegaMoto class for H-bridge driving
* configurations.
*
* This is the class used when you are using a
* single motor/device with both (+) and (-)
* terminals hooked up directly to the A and B
* outputs of the MegaMoto controller.
*
* See section "3. Application Configurations"
* in the MegaMoto user manual for more wiring
* information.
*
* Please see the example file(s) for, well...
* examples! ;-)
***********************************************/
class MegaMotoHB : public MegaMotoBase {
public:
// -- Constructors
MegaMotoHB(
unsigned char pin_pwm_a,
unsigned char pin_pwm_b);
MegaMotoHB(
char pin_pwm_a,
char pin_pwm_b,
char pin_enable);
/********************************************//**
* \enum TMegaMotoHBDir
* \brief Defines the three possible output
* directions
*
* Thinking from a single motor wired in H-bridge
* mode, there are three possible directions
*
* \var FWD
* Forward direction: PWM A is on at a duty
* cycle defined by pwm_duty. PWM B is off.
* MegaMoto output MA will have a higher
* potential than MB.
*
* \var REV
* Reverse direction: PWMA is off. PWMB is
* on at a duty cycle defined by pwm_duty.
* MegaMoto output MA will have a higher
* potential than MB.
*
* \var STOP
* Motor is off: PWMA is off. PWMB is off.
* MegaMoto output MA will have the same
* potential as MB (which is 0V).
*
***********************************************/
enum TMegaMotoHBDir {
FWD,
REV,
STOP
};
inline void Fwd( const unsigned char new_pwm_duty )
{ Power( TMegaMotoHBDir::FWD, new_pwm_duty ); }
inline void Rev( const unsigned char new_pwm_duty )
{ Power( TMegaMotoHBDir::REV, new_pwm_duty ); }
inline void Stop()
{ Power( TMegaMotoHBDir::STOP, 0 ); }
void Power(const TMegaMotoHBDir dir, const unsigned char pwm_duty);
void StepPwmDuty( unsigned char pwm_duty_in );
void Kill();
void Disable();
protected:
// Nothing here :-)
private:
/********************************************//**
* \var pwm_duty
* \brief Current PWM duty cycle being output
***********************************************/
unsigned char pwm_duty;
TMegaMotoHBDir current_dir;
};
#endif // MegaMotoHB_h