-
Notifications
You must be signed in to change notification settings - Fork 0
/
motor.h
103 lines (90 loc) · 2.32 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
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
/*!
* @file motor.h v1.0
* @Copyright © 2019 Kazushi Kurasawa
* @date 2019.03.06
*
* Released under the MIT license.
* see https://opensource.org/licenses/MIT
*/
#ifndef MSLH_MOTOR_H
#define MSLH_MOTOR_H
#include "pwm_out.h"
#include "tim.h"
#include "digital_out.h"
#include "defines.h"
namespace mslh {
/**
* @brief
* This Class, the target of the control is Motor-Driver "DRV8836". <br>
* Turns the motor at the specified PWM ratio.
*
* Example:
* @code
* // The motor is rotated forward and backward at a PWM value of 0.5 (50% output) for
* // 3 seconds each, and then stopped.
*
* #include "motor.h"
*
* using namepsace mslh;
*
* Motor motor(htim1, TIM_CHANNEL_1, GPIOA, GPIO_PIN_6, true);
*
* int main() {
* // Abbreviation Microcomputer startup settings.
*
* MX_TIM1_Init(); //< Need setup HAL motor timer parameters.
* MX_GPIO_Init(); //< Need setup HAL_GPIO for motor _direction.
*
* motor.start(); //< Start drive motor
*
* motor.update(0.5); //< Roted forward with PWM of 50% output.
* HAL_Delay(3000);
*
* motor.update(0.0); //< "0.0" can be entered. In that case, the motor will stop.
* HAL_Delay(3000);
*
* motor.update(-0.5); //< Roted backward with PWM of 50% output.
* HAL_Delay(3000);
*
* motor.stop() //< Stop drive motor.
* }
* @endcode
*/
class Motor {
public:
/**
* @note
* Motor(___ , ___ , ___, ___, bool cw); <br>
*
* @param
* bool cw: The _direction corresponds
* to the forward rotation of your machine.
*/
Motor(TIM_HandleTypeDef &htim_x, uint32_t channel, GPIO_TypeDef *phase_x, uint16_t phase_pin, bool cw);
/**
* @fn Start motor.
*/
void start() const;
/**
* @fn Stop motor.
*/
void stop() const;
/**
* @fn Specifies the PWM of the motor.
*
* @details
* {0.0 < duty_ratio} is PWM of clock wise <br>
* {duty_ratio < 0.0} is PWM of counter clock wise
*
* @param duty_ratio {-1.0 ≦ duty_ratio ≦ 1.0}
*/
void update(float32_t duty_ratio);
private:
GPIO_TypeDef *_phase_x;
const uint16_t _phase_pin;
TIM_HandleTypeDef &_htim_x;
const uint64_t _channel;
const GPIO_PinState _forward_wise;
};
} // namespace mslh
#endif //MSLH_MOTOR_H