Skip to content

Commit 4cd7461

Browse files
fix: variable name collision
1 parent 1140936 commit 4cd7461

File tree

2 files changed

+94
-1
lines changed

2 files changed

+94
-1
lines changed

src/MakerBoard.cpp

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,105 @@ long MakerBoard::Ultrasonic::Ranging(){
8989
pinMode(TP,OUTPUT);
9090
pinMode(EP,INPUT);
9191

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.
102+
*
103+
*/
104+
#include <Arduino.h>
105+
#include "MakerBoard.h"
106+
#include <MsTimer2.h>
107+
108+
MakerBoardMotor Motor1(MakerBoard::DCM1_A, MakerBoard::DCM1_B);
109+
MakerBoardMotor Motor2(MakerBoard::DCM2_A, MakerBoard::DCM2_B);
110+
MakerBoardMotor Motor3(MakerBoard::DCM3_A, MakerBoard::DCM3_B);
111+
MakerBoardMotor Motor4(MakerBoard::DCM4_A, MakerBoard::DCM4_B);
112+
113+
/**
114+
* @brief DCモーターのピン設定.GPIO2〜GPIO9ピンが使用される.
115+
* (Configure the DC motor driver pins from GPIO2 to GPIO9.)
116+
*/
117+
void MakerBoard::motorPinSetup(){
118+
pinMode(this->DCM1_A, OUTPUT);
119+
pinMode(this->DCM1_B, OUTPUT);
120+
pinMode(this->DCM2_A, OUTPUT);
121+
pinMode(this->DCM2_B, OUTPUT);
122+
pinMode(this->DCM3_A, OUTPUT);
123+
pinMode(this->DCM3_B, OUTPUT);
124+
pinMode(this->DCM4_A, OUTPUT);
125+
pinMode(this->DCM4_B, OUTPUT);
126+
}
127+
128+
/**
129+
* @brief モーターを回転させ,パルスのトップをカウントする.このメソッドはTIMER_FREQUENCYでタイマー実行されることを想定している.
130+
* (Rotate the motor and count the top of the pulses. This method is assumed to be executed by a timer with TIMER_FREQUENCY.)
131+
*
132+
*/
133+
static void MakerBoard::motorPulseCounter()
134+
{
135+
Motor1.run();
136+
Motor2.run();
137+
Motor3.run();
138+
Motor4.run();
139+
Motor1.top_cnt++;
140+
Motor2.top_cnt++;
141+
Motor3.top_cnt++;
142+
Motor4.top_cnt++;
143+
if (Motor1.top_cnt > Motor1.PERIODIC_TIME){
144+
Motor1.top_cnt = 0;
145+
}
146+
if (Motor2.top_cnt > Motor2.PERIODIC_TIME){
147+
Motor2.top_cnt = 0;
148+
}
149+
if (Motor3.top_cnt > Motor3.PERIODIC_TIME){
150+
Motor3.top_cnt = 0;
151+
}
152+
if (Motor4.top_cnt > Motor4.PERIODIC_TIME){
153+
Motor4.top_cnt = 0;
154+
}
155+
}
156+
157+
/**
158+
* @brief DCモーターのPWMを生成する.(Set time for DC motor PWM control.)
159+
*
160+
*/
161+
void MakerBoard::motorPWMBegin(){
162+
// Set DC motor control PWM generation with timer
163+
this->motorPinSetup();
164+
MsTimer2::set(this->TIMER_FREQUENCY, this->motorPulseCounter);
165+
MsTimer2::start();
166+
}
167+
168+
MakerBoard::Ultrasonic::Ultrasonic(int Trig_Pin, int Echo_Pin)
169+
{
170+
pinMode(Trig_Pin,OUTPUT);
171+
pinMode(Echo_Pin,INPUT);
172+
TP = Trig_Pin;
173+
EP = Echo_Pin;
174+
}
175+
176+
long MakerBoard::Ultrasonic::Ranging(){
92177
digitalWrite(TP, LOW);
93178
delayMicroseconds(2);
94179
digitalWrite(TP, HIGH);
95180
delayMicroseconds(10);
96181
digitalWrite(TP, LOW);
97182

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+
98191
long duration = pulseIn(EP,HIGH);
99192
long distance_cm = duration /29 / 2 ;
100193
return distance_cm;

src/MakerBoard.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class MakerBoard
4949

5050
class Ultrasonic {
5151
public:
52-
Ultrasonic(int TP, int EP);
52+
Ultrasonic(int Trig_Pin, int Echo_Pin);
5353
long Ranging();
5454
private:
5555
int TP;

0 commit comments

Comments
 (0)