-
Notifications
You must be signed in to change notification settings - Fork 0
/
MD_mini.hpp
96 lines (81 loc) · 2.49 KB
/
MD_mini.hpp
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
#ifndef _MD_MINI_HPP_
#define _MD_MINI_HPP_
#include "mbed.h"
#include "math.h"
#define PWM_FREQUENCY 0.00005f // PWM 20kHz (1/20000)
#define MAX_POWER 1.0f // モーターの最大出力値
//! MD_mini class for controlling AE-TC78H653FTG motor driver.
/*!
This class provides functions to control the motor driver in PHASE mode.
The pins are connected as follows:
- in1_pin: Motor 1 Forward pin
- in2_pin: Motor 1 Reverse pin
- in3_pin: Motor 2 Forward pin
- in4_pin: Motor 2 Reverse pin
@author awttenani
*/
class MD_mini
{
public:
/*!
* @brief Constructor for initializing motor pins and reverse settings.
*
* The pins are connected to the corresponding motor driver pins:
* - in1_pin: Motor 1 Forward pin
* - in2_pin: Motor 1 Reverse pin
* - in3_pin: Motor 2 Forward pin
* - in4_pin: Motor 2 Reverse pin
*
* @param in1_pin Pin for motor 1 forward.
* @param in2_pin Pin for motor 1 reverse.
* @param reverse1 Reverse mode for motor 1.
* @param in3_pin Pin for motor 2 forward.
* @param in4_pin Pin for motor 2 reverse.
* @param reverse2 Reverse mode for motor 2.
*/
MD_mini(PinName in1_pin, PinName in2_pin, bool reverse1, PinName in3_pin, PinName in4_pin, bool reverse2);
/*!
* @brief Drive only motor 1.
*
* @param power1 Power level for motor 1 (range: -1.0 to 1.0).
*/
void drive_1(float power1);
/*!
* @brief Drive only motor 2.
*
* @param power2 Power level for motor 2 (range: -1.0 to 1.0).
*/
void drive_2(float power2);
/*!
* @brief Drive both motors simultaneously.
*
* @param power1 Power level for motor 1 (range: -1.0 to 1.0).
* @param power2 Power level for motor 2 (range: -1.0 to 1.0).
*/
void drive_both(float power1, float power2);
/*!
* @brief Stop both motors.
*/
void stop();
/*!
* @brief Run both motors at full speed.
*/
void full_speed();
private:
/*!
* @brief Clamps the power value to the maximum allowed power.
*
* @param power The input power level.
* @return Clamped power level within the range [0, MAX_POWER].
*/
float clamp_power(float power);
//! PWM output pins for motor control.
PwmOut in1, in2, in3, in4;
//! Stores the PWM signal values for both motors.
float pwm1, pwm2;
//! Stores power signal values.
float conf_power;
//! Reverse flags for both motors.
bool reverse1, reverse2;
};
#endif