-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from KatLab-MiyazakiUniv/ticket-KLI-33
close #KLI-33 GitHub Actionsにおけるclang-format実行コマンドの修正
- Loading branch information
Showing
17 changed files
with
748 additions
and
51 deletions.
There are no files selected for viewing
This file contains 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 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 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,88 @@ | ||
/** | ||
* @file Measurer.cpp | ||
* @brief 計測に用いる関数をまとめたラッパークラス | ||
* @author keiya121 | ||
*/ | ||
|
||
#include "Measurer.h" | ||
|
||
Measurer::Measurer() | ||
: colorSensor(PORT_2), | ||
sonarSensor(PORT_3), | ||
leftWheel(PORT_C), | ||
rightWheel(PORT_B), | ||
armMotor(PORT_A) | ||
{ | ||
} | ||
|
||
// 明るさを取得 | ||
// 参考: https://tomari.org/main/java/color/ccal.html | ||
int Measurer::getBrightness() | ||
{ | ||
// RGBモードと光センサモードを併用すると動作が悪くなるためRGBモードで取得する | ||
// 参考: https://qiita.com/kawanon868/items/5d52eb291c3f71af0419 | ||
rgb_raw_t rgb = getRawColor(); | ||
int brightness = std::max({ rgb.r, rgb.g, rgb.b }) * 100 / 255; // 明度を取得して0-100に正規化 | ||
return brightness; | ||
} | ||
|
||
// RGB値を取得 | ||
rgb_raw_t Measurer::getRawColor() | ||
{ | ||
rgb_raw_t rgb; | ||
colorSensor.getRawColor(rgb); | ||
return rgb; | ||
} | ||
|
||
// 左モータ角位置取得 | ||
int Measurer::getLeftCount() | ||
{ | ||
return leftWheel.getCount(); | ||
} | ||
|
||
// 右モータ角位置取得 | ||
int Measurer::getRightCount() | ||
{ | ||
return rightWheel.getCount(); | ||
} | ||
|
||
// アームモータ角位置取得 | ||
int Measurer::getArmMotorCount() | ||
{ | ||
return armMotor.getCount(); | ||
} | ||
|
||
// 正面から見て左ボタンの押下状態を取得 | ||
bool Measurer::getLeftButton() | ||
{ | ||
return ev3_button_is_pressed(LEFT_BUTTON); | ||
} | ||
|
||
// 正面から見て右ボタンの押下状態を取得 | ||
bool Measurer::getRightButton() | ||
{ | ||
return ev3_button_is_pressed(RIGHT_BUTTON); | ||
} | ||
|
||
// 中央ボタンの押下状態を取得 | ||
bool Measurer::getEnterButton() | ||
{ | ||
return ev3_button_is_pressed(ENTER_BUTTON); | ||
} | ||
|
||
// 超音波センサからの距離を取得 | ||
int Measurer::getForwardDistance() | ||
{ | ||
int distance = sonarSensor.getDistance(); | ||
|
||
// センサが認識していない時が-1になる | ||
if(distance == -1) distance = 1000; | ||
|
||
return distance; | ||
} | ||
|
||
// SPIKEの電圧を取得 | ||
double Measurer::getVoltage() | ||
{ | ||
return (double)ev3_battery_voltage_mV() / 1000.0; | ||
} |
This file contains 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,92 @@ | ||
/** | ||
* @file Measurer.h | ||
* @brief 計測に用いる関数をまとめたラッパークラス | ||
* @author keiya121 | ||
*/ | ||
|
||
#ifndef MEASURER_H | ||
#define MEASURER_H | ||
|
||
#include <algorithm> | ||
#include "ev3api.h" | ||
#include "ColorSensor.h" | ||
#include "SonarSensor.h" | ||
#include "Motor.h" | ||
|
||
class Measurer { | ||
public: | ||
/** | ||
* @brief コンストラクタ | ||
*/ | ||
Measurer(); | ||
|
||
/** | ||
* @brief 明るさを取得 | ||
* @return 反射光の強さ(0-100) | ||
*/ | ||
int getBrightness(); | ||
|
||
/** | ||
* @brief RGB値を取得 | ||
* @return RGB値 | ||
*/ | ||
rgb_raw_t getRawColor(); | ||
|
||
/** | ||
* @brief 左モータ角位置取得 | ||
* @return 左モータ角位置[deg] | ||
*/ | ||
int getLeftCount(); | ||
|
||
/** | ||
* @brief 右モータ角位置取得 | ||
* @return 右モータ角位置[deg] | ||
*/ | ||
int getRightCount(); | ||
|
||
/** | ||
* @brief アームモータ角位置取得 | ||
* @return アームモータ角位置[deg] | ||
*/ | ||
int getArmMotorCount(); | ||
|
||
/** | ||
* @brief 正面から見て左ボタンの押下状態を取得 | ||
* @return 左ボタンの押下状態 true:押されてる, false:押されていない | ||
*/ | ||
bool getLeftButton(); | ||
|
||
/** | ||
* @brief 正面から見て右ボタンの押下状態を取得 | ||
* @return 右ボタンの押下状態 true:押されてる, false:押されていない | ||
*/ | ||
bool getRightButton(); | ||
|
||
/** | ||
* @brief 中央ボタンの押下状態を取得 | ||
* @return 中央ボタンの押下状態 true:押されてる, false:押されていない | ||
*/ | ||
bool getEnterButton(); | ||
|
||
/** | ||
* @brief 超音波センサからの距離を取得 | ||
* @return 超音波センサからの距離[cm] | ||
* @note センサが認識していない時は1000を返す | ||
*/ | ||
int getForwardDistance(); | ||
|
||
/** | ||
* @brief SPIKEの電圧を取得 | ||
* @return SPIKEの電圧[V] | ||
*/ | ||
double getVoltage(); | ||
|
||
private: | ||
ev3api::ColorSensor colorSensor; | ||
ev3api::SonarSensor sonarSensor; | ||
ev3api::Motor leftWheel; | ||
ev3api::Motor rightWheel; | ||
ev3api::Motor armMotor; | ||
}; | ||
|
||
#endif |
This file contains 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 |
---|---|---|
|
@@ -48,4 +48,4 @@ void EtRobocon2024::start() | |
// void EtRobocon2024::sigint(int _) | ||
// { | ||
// _exit(0); // システムコールで強制終了 | ||
// } | ||
// } |
This file contains 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,25 @@ | ||
/** | ||
* @file DummyRobot.cpp | ||
* @brief 実機内部の状態を管理するダミーファイル | ||
* @author keiya121 | ||
*/ | ||
|
||
#include "DummyRobot.h" | ||
|
||
// 静的メンバ変数の初期化 | ||
DummyRobot::ButtonState DummyRobot::buttonState = DummyRobot::ButtonState::none; | ||
|
||
// コンストラクタ | ||
DummyRobot::DummyRobot() {} | ||
|
||
// 実機内部のボタンの押下状態を設定する静的メソッド | ||
void DummyRobot::setButtonState(ButtonState state) | ||
{ | ||
buttonState = state; | ||
} | ||
|
||
// 実機内部のボタンの押下状態を取得する静的メソッド | ||
DummyRobot::ButtonState DummyRobot::getButtonState() | ||
{ | ||
return buttonState; | ||
} |
This file contains 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,34 @@ | ||
/** | ||
* @file DummyRobot.h | ||
* @brief 実機内部の状態を管理するダミーファイル | ||
* @author keiya121 | ||
*/ | ||
|
||
#ifndef DUMMYROBOT_H | ||
#define DUMMYROBOT_H | ||
|
||
class DummyRobot { | ||
public: | ||
// 実機内部のボタンの押下状態を表す列挙型 | ||
enum class ButtonState { | ||
left, // 実機の正面から見て左側のボタンが押されている状態 | ||
enter, // 実機の中央ボタンが押されている状態 | ||
right, // 実機の正面から見て右側のボタンが押されている状態 | ||
none // ボタンがいずれも押されていない状態 | ||
}; | ||
|
||
// コンストラクタ | ||
DummyRobot(); | ||
|
||
// 実機内部のボタンの押下状態を設定するメソッド | ||
static void setButtonState(ButtonState state); | ||
|
||
// 実機内部のボタンの押下状態を取得するメソッド | ||
static ButtonState getButtonState(); | ||
|
||
private: | ||
// 実機内部のボタンの押下状態を管理するメンバ変数 | ||
static ButtonState buttonState; | ||
}; | ||
|
||
#endif |
Oops, something went wrong.