|
2 | 2 | * @file MakerBoard.h |
3 | 3 | * @author Yoshinobu Obata |
4 | 4 | * @brief Standard library for メイカーボード |
5 | | - * @version 0.1 |
6 | | - * @date 2024-09-10 |
| 5 | + * @version 1.0.3 |
| 6 | + * @date 2026-01-20 |
7 | 7 | * Change log: |
| 8 | + * 2026-01-20: Added Ultrasonic class for ultrasonic sensor support. |
8 | 9 | * |
9 | | - * @copyright Copyright (c) 2024 Yukai Engineering Inc. |
10 | | - * |
11 | | - */ |
12 | | -#include <Arduino.h> |
13 | | -#include "MakerBoard.h" |
14 | | -#include <MsTimer2.h> |
15 | | - |
16 | | -MakerBoardMotor Motor1(MakerBoard::DCM1_A, MakerBoard::DCM1_B); |
17 | | -MakerBoardMotor Motor2(MakerBoard::DCM2_A, MakerBoard::DCM2_B); |
18 | | -MakerBoardMotor Motor3(MakerBoard::DCM3_A, MakerBoard::DCM3_B); |
19 | | -MakerBoardMotor Motor4(MakerBoard::DCM4_A, MakerBoard::DCM4_B); |
20 | | - |
21 | | -/** |
22 | | - * @brief DCモーターのピン設定.GPIO2〜GPIO9ピンが使用される. |
23 | | - * (Configure the DC motor driver pins from GPIO2 to GPIO9.) |
24 | | - */ |
25 | | -void MakerBoard::motorPinSetup(){ |
26 | | - pinMode(this->DCM1_A, OUTPUT); |
27 | | - pinMode(this->DCM1_B, OUTPUT); |
28 | | - pinMode(this->DCM2_A, OUTPUT); |
29 | | - pinMode(this->DCM2_B, OUTPUT); |
30 | | - pinMode(this->DCM3_A, OUTPUT); |
31 | | - pinMode(this->DCM3_B, OUTPUT); |
32 | | - pinMode(this->DCM4_A, OUTPUT); |
33 | | - pinMode(this->DCM4_B, OUTPUT); |
34 | | -} |
35 | | - |
36 | | -/** |
37 | | - * @brief モーターを回転させ,パルスのトップをカウントする.このメソッドはTIMER_FREQUENCYでタイマー実行されることを想定している. |
38 | | - * (Rotate the motor and count the top of the pulses. This method is assumed to be executed by a timer with TIMER_FREQUENCY.) |
39 | | - * |
40 | | - */ |
41 | | -static void MakerBoard::motorPulseCounter() |
42 | | -{ |
43 | | - Motor1.run(); |
44 | | - Motor2.run(); |
45 | | - Motor3.run(); |
46 | | - Motor4.run(); |
47 | | - Motor1.top_cnt++; |
48 | | - Motor2.top_cnt++; |
49 | | - Motor3.top_cnt++; |
50 | | - Motor4.top_cnt++; |
51 | | - if (Motor1.top_cnt > Motor1.PERIODIC_TIME){ |
52 | | - Motor1.top_cnt = 0; |
53 | | - } |
54 | | - if (Motor2.top_cnt > Motor2.PERIODIC_TIME){ |
55 | | - Motor2.top_cnt = 0; |
56 | | - } |
57 | | - if (Motor3.top_cnt > Motor3.PERIODIC_TIME){ |
58 | | - Motor3.top_cnt = 0; |
59 | | - } |
60 | | - if (Motor4.top_cnt > Motor4.PERIODIC_TIME){ |
61 | | - Motor4.top_cnt = 0; |
62 | | - } |
63 | | -} |
64 | | - |
65 | | -/** |
66 | | - * @brief DCモーターのPWMを生成する.(Set time for DC motor PWM control.) |
67 | | - * |
68 | | - */ |
69 | | -void MakerBoard::motorPWMBegin(){ |
70 | | - // Set DC motor control PWM generation with timer |
71 | | - this->motorPinSetup(); |
72 | | - MsTimer2::set(this->TIMER_FREQUENCY, this->motorPulseCounter); |
73 | | - MsTimer2::start(); |
74 | | -} |
75 | | - |
76 | | -/** |
77 | | - * @brief 超音波センサのコンストラクタ.(Constructor of Ultrasonic sensor.) |
78 | | - */ |
79 | | -MakerBoard::Ultrasonic::Ultrasonic(int TP, int EP) |
80 | | -{ |
81 | | - TP = TP; |
82 | | - EP = EP; |
83 | | -} |
84 | | - |
85 | | -/** |
86 | | - * @brief 超音波センサ(HC-SR04)で距離を測定する.(Measure distance with Ultrasonic sensor.) |
87 | | - */ |
88 | | -long MakerBoard::Ultrasonic::Ranging(){ |
89 | | - pinMode(TP,OUTPUT); |
90 | | - pinMode(EP,INPUT); |
91 | | - |
92 | | - digitalWrite(TP, LOW); |
93 | | - delayMicroseconds(2);/** |
94 | | - * @file MakerBoard.h |
95 | | - * @author Yoshinobu Obata |
96 | | - * @brief Standard library for メイカーボード |
97 | | - * @version 0.1 |
98 | | - * @date 2024-09-10 |
99 | | - * Change log: |
100 | | - * |
101 | | - * @copyright Copyright (c) 2024 Yukai Engineering Inc. |
| 10 | + * @copyright Copyright (c) 2026 Yukai Engineering Inc. |
102 | 11 | * |
103 | 12 | */ |
104 | 13 | #include <Arduino.h> |
@@ -180,14 +89,6 @@ long MakerBoard::Ultrasonic::Ranging(){ |
180 | 89 | delayMicroseconds(10); |
181 | 90 | digitalWrite(TP, LOW); |
182 | 91 |
|
183 | | - long duration = pulseIn(EP,HIGH); |
184 | | - long distance_cm = duration /29 / 2 ; |
185 | | - return distance_cm; |
186 | | -} |
187 | | - digitalWrite(TP, HIGH); |
188 | | - delayMicroseconds(10); |
189 | | - digitalWrite(TP, LOW); |
190 | | - |
191 | 92 | long duration = pulseIn(EP,HIGH); |
192 | 93 | long distance_cm = duration /29 / 2 ; |
193 | 94 | return distance_cm; |
|
0 commit comments