-
Notifications
You must be signed in to change notification settings - Fork 0
#KL25-31 累計距離を測るクラスを作る #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
681c774
add: 走行距離を測定する Mileage クラスを追加
molpui0726 f7c71cf
add: 走行距離を測定する Mileage クラスのテストを追加
molpui0726 ab10b7e
add: Mileage クラスで車輪の半径が必要であるため、走行体の情報をもつヘッダファイルを追加
molpui0726 921af52
update: Docker 環境で clang-format を実行するため、Dockerfile にパッケージを追加
molpui0726 b4c7484
update: make format 実行時に、どのファイルが変更されたかを確認できる文を追加
molpui0726 cb7c283
fix: SystemInfo を相対パスで include していたため、Makefile.inc に common ディレクトリを追加
molpui0726 b256104
update: MotorController でモーターの角位置を int32_t 型で取得しているため、関数の引数として用いるモーター…
molpui0726 acd2222
update: common ディレクトリをインクルード対象のディレクトリとして CMakeLists.txt に追加
molpui0726 5e8cebc
update: 回転角の引数を int32_t に変更
molpui0726 af5efe8
delete: 実行ログ取得フラグは現時点で必要ないため、削除
molpui0726 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| /** | ||
| ** @file Mileage.cpp | ||
| ** @brief 走行距離を計算するクラス | ||
| ** @author molpui0726 | ||
| **/ | ||
|
|
||
| #include "Mileage.h" | ||
| #include "../common/SystemInfo.h" | ||
|
|
||
| double Mileage::calculateWheelMileage(int angle) | ||
| { | ||
| // タイヤの累計走行距離 = 2 * π * タイヤの半径 * (タイヤの回転角度 / 360[deg]) | ||
| return 2.0 * M_PI * RADIUS * static_cast<double>(angle) / 360.0; | ||
| } | ||
|
|
||
| double Mileage::calculateMileage(int rightAngle, int leftAngle) | ||
| { | ||
| // 右タイヤの累計走行距離を計算 | ||
| double rightWheelMileage = calculateWheelMileage(rightAngle); | ||
| // 左タイヤの累計走行距離を計算 | ||
| double leftWheelMileage = calculateWheelMileage(leftAngle); | ||
| // 走行体全体の累計走行距離 = (右タイヤの累計走行距離 + 左タイヤの累計走行距離) / 2 | ||
| return (rightWheelMileage + leftWheelMileage) / 2.0; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| /** | ||
| ** @file Mileage.h | ||
| ** @brief 走行距離を計算するクラス | ||
| ** @author YKhm20020 | ||
| **/ | ||
|
|
||
| #ifndef MILEAGE_H | ||
| #define MILEAGE_H | ||
|
|
||
| #include <cmath> | ||
|
|
||
| class Mileage { | ||
| public: | ||
| /** | ||
| ** @brief タイヤの累計走行距離を計算する | ||
| ** @param angle タイヤの回転角度[deg] | ||
| ** @return タイヤの累計走行距離[mm] | ||
| **/ | ||
| static double calculateWheelMileage(int angle); | ||
molpui0726 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| ** @brief 走行体全体の累計走行距離を計算する | ||
| ** @param rightAngle 右タイヤの回転角度[deg] | ||
| ** @param leftAngle 左タイヤの回転角度[deg] | ||
| ** @return 走行体全体の累計走行距離[mm] | ||
| **/ | ||
| static double calculateMileage(int rightAngle, int leftAngle); | ||
takuchi17 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| private: | ||
| Mileage(); // インスタンス化を禁止する | ||
| }; | ||
| #endif | ||
takuchi17 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| /** | ||
| * @file SystemInfo.h | ||
| * @brief 走行システムで統一する情報をまとめたファイル | ||
| * @author molpui0726 | ||
| */ | ||
|
|
||
| #ifndef SYSTEM_INFO_H | ||
| #define SYSTEM_INFO_H | ||
|
|
||
| static constexpr double RADIUS = 28.0; // 車輪の半径[mm] | ||
| static constexpr double TREAD = 112.0; // 走行体のトレッド幅(両輪の間の距離)[mm] | ||
| static bool shouldGetRunLogs = false; // 実行ログを取得するかのフラグ | ||
takahashitom marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| #endif | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| /** | ||
| * @file MileageTest.cpp | ||
| * @brief 走行距離の測定用クラスのテスト | ||
| * @author molpui0726 | ||
| */ | ||
|
|
||
| #include "Mileage.h" | ||
| #include <cmath> | ||
| #include <gtest/gtest.h> | ||
|
|
||
| namespace etrobocon2025_test { | ||
| TEST(MileageTest, CalculateMileage) | ||
takuchi17 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| double rightAngle = 30.0; | ||
| double leftAngle = 40.0; | ||
|
|
||
| // 計算過程 | ||
| // 1.右車輪の累計走行距離を算出 | ||
| // double rightWheelMileage = 2.0 * rightAngle * radius * M_PI / 360.0; | ||
| // M_PI = 3.14: rightWheelMileage = 2.0 * 30.0 * 28.0 * 3.14 / 360.0 = 14.6533... | ||
| // M_PI = 3.15: rightWheelMileage = 2.0 * 30.0 * 28.0 * 3.15 / 360.0 = 14.70 | ||
| // 2.左車輪の累計走行距離を算出 | ||
| // double leftWheelMileage = 2.0 * leftAngle * radius * M_PI / 360.0; | ||
| // M_PI = 3.14: leftWheelMileage = 2.0 * 40.0 * 28.0 * 3.14 / 360.0 = 19.53777... | ||
| // M_PI = 3.15: leftWheelMileage = 2.0 * 40.0 * 28.0 * 3.15 / 360.0 = 19.60 | ||
| // 3.両車輪の累計走行距離の平均を算出 | ||
| // double expected = (rightWheelMileage + leftWheelMileage) / 2.0; | ||
| // M_PI = 3.14: (14.6533... + 19.5377...) / 2 = 17.09555... | ||
| // M_PI = 3.15: (14.70 + 19.60) / 2 = 17.15 | ||
| double expected_min = 17.09555; | ||
| double expected_max = 17.15; | ||
|
|
||
| // actual: 17.104227 | ||
| double actual = Mileage::calculateMileage(rightAngle, leftAngle); | ||
|
|
||
| // M_PIが3.14で計算した値よりも大きいアサーションと、3.15で計算した値よりも小さいアサーションを両方満たすか | ||
| EXPECT_LT(expected_min, actual); | ||
| EXPECT_GT(expected_max, actual); | ||
| } | ||
|
|
||
| TEST(MileageTest, CalculateMileageMinus) | ||
| { | ||
| double rightAngle = -30.0; | ||
| double leftAngle = -40.0; | ||
| double expected_min = -17.15; | ||
| double expected_max = -17.09555; | ||
| double actual = Mileage::calculateMileage(rightAngle, leftAngle); | ||
| EXPECT_LT(expected_min, actual); | ||
| EXPECT_GT(expected_max, actual); | ||
| } | ||
|
|
||
| TEST(MileageTest, CalculateMileageZero) | ||
| { | ||
| double rightAngle = 0.0; | ||
| double leftAngle = 0.0; | ||
| double expected = 0.0; | ||
| double actual = Mileage::calculateMileage(rightAngle, leftAngle); | ||
| EXPECT_DOUBLE_EQ(expected, actual); | ||
| } | ||
| } // namespace etrobocon2025_test | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.