-
Notifications
You must be signed in to change notification settings - Fork 0
#KL25-17 モータを動かす #6
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
38 commits
Select commit
Hold shift + click to select a range
6f2770a
add: 実機検証用
nishijima515 072479a
fix: エラー修正
nishijima515 af265c1
update:アームが正のパワー値で上に動くように変更
nishijima515 03e81ff
add: 回転速度、ブレーキ、アームホールド関係の関数の追加
nishijima515 932e54d
add:角位置取得関数の追加
nishijima515 66c6ead
refactor: コメントの修正
nishijima515 4618ece
update: gtestでのincludeディレクトリを追加
nishijima515 7b353bf
add: Controllerクラスのテストを行うためのダミークラスを追加
nishijima515 57294fe
add: Controllerクラスのテストを追加
nishijima515 4d17ac1
add: モータを動かすためのクラスの追加
nishijima515 4ff9805
update: buildを通すため、includeディレクトリを追加
nishijima515 6370360
update: テストを行うためにincludeディレクトリを追加
nishijima515 6ca0f69
add: コントローラクラスのテストを行うためのダミーを追加
nishijima515 def8acb
add: コントローラのテストを追加
nishijima515 6058bc9
refactor: MotorController.hに変更
nishijima515 cca9be6
add: テストで使うため、アームモータのpower値を取得する関数getArmMotorPowerの追加とコメントの修正
nishijima515 7471129
update: MotorControllerTest.cppに変更、power値の確認を行うようにした
nishijima515 ac2accb
refactor: テスト名をアッパーキャメルケースに修正
nishijima515 eeeb1f2
update: リセット系の関数の内部処理を変更
nishijima515 2cc9611
add: モータに設定するpower値の上限の制限が行われているか確認するテストの追加
nishijima515 2e8d882
refactor: include spikeapi.hの削除
nishijima515 f2345fe
update: 回転速度を取得する関数の戻り値の型をintからint32_tに変更
nishijima515 6d11bd6
refactor: 細かな修正
nishijima515 bb8177d
Merge branch 'ticket-KL25-17' into work-KL25-17
nishijima515 12dcb10
refactor: コメントの修正
nishijima515 df396ae
update: リセット系の関数の内部処理変更
nishijima515 9109369
add: テストで使うため、getArmMotorPower関数を追加した
nishijima515 b9beeb4
add: モータに設定するpower値の上限の制限が行われているか確認するテストの追加、テスト名をアッパーキャメルケースに変更
nishijima515 96119d9
delete: 名前の変更によりController系のファイルを削除
nishijima515 1cd59ee
delete: 名前の変更によりController系のファイルを削除
nishijima515 0624961
update: クラス名などのControllerをMotorControllerに変更
nishijima515 6c80cb1
クラス名などのControllerをMotorControllerに変更
nishijima515 165a04c
refactor: フォーマットエラー解消の試み
nishijima515 a69982b
refactor: 細かな修正
nishijima515 e963305
refactor: 細かな修正
nishijima515 d95b758
refactor: インクルードガードを大文字に修正、パワー保持変数の削除
nishijima515 afb8470
Merge branch 'work-KL25-17' into ticket-KL25-17
nishijima515 1271b01
delete: パワー保持変数の削除
nishijima515 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
nishijima515 marked this conversation as resolved.
Outdated
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,165 @@ | ||
| /** | ||
| * @file Controller.cpp | ||
| * @brief モーター制御に用いる関数をまとめたラッパークラス | ||
| * @author nishijima515 | ||
| */ | ||
| #include "Controller.h" | ||
|
|
||
| Controller::Controller() | ||
| : rightWheel(Port::PORT_A), | ||
nishijima515 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
aridome222 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| leftWheel(Port::PORT_B, Motor::EDirection::COUNTERCLOCKWISE), | ||
| armMotor(Port::PORT_C, Motor::EDirection::COUNTERCLOCKWISE) | ||
| { | ||
| } | ||
|
|
||
| // power値の初期化 | ||
| int Controller::powerOfRightWheel = 0.0; | ||
| int Controller::powerOfLeftWheel = 0.0; | ||
| int Controller::powerOfArm = 0.0; | ||
nishijima515 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // モータに設定するpower値の制限 | ||
| int Controller::limitPowerValue(const int inputPower) | ||
| { | ||
| if(inputPower > MOTOR_POWER_MAX) { | ||
| return MOTOR_POWER_MAX; | ||
| } else if(inputPower < MOTOR_POWER_MIN) { | ||
| return MOTOR_POWER_MIN; | ||
| } | ||
| return inputPower; | ||
| } | ||
|
|
||
| // 右モータにpower値をセット | ||
| void Controller::setRightMotorPower(const int power) | ||
| { | ||
| powerOfRightWheel = limitPowerValue(power); | ||
| rightWheel.setPower(powerOfRightWheel); | ||
takahashitom marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| // 左モータにpower値をセット | ||
| void Controller::setLeftMotorPower(const int power) | ||
| { | ||
| powerOfLeftWheel = limitPowerValue(power); | ||
| leftWheel.setPower(powerOfLeftWheel); | ||
| } | ||
|
|
||
| // 右モータのpower値をリセット | ||
| void Controller::resetRightMotorPower() | ||
| { | ||
| powerOfRightWheel = 0; | ||
| rightWheel.setPower(powerOfRightWheel); | ||
| } | ||
|
|
||
| // 左モータのpower値をリセット | ||
| void Controller::resetLeftMotorPower() | ||
| { | ||
| powerOfLeftWheel = 0; | ||
| leftWheel.setPower(powerOfLeftWheel); | ||
| } | ||
|
|
||
| // 右左両モータの状態をリセット | ||
| void Controller::resetWheelsMotorPower() | ||
| { | ||
| powerOfRightWheel = 0; | ||
| powerOfLeftWheel = 0; | ||
| rightWheel.setPower(powerOfRightWheel); | ||
| leftWheel.setPower(powerOfLeftWheel); | ||
| } | ||
aridome222 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // 右タイヤのモータに回転速度をセット | ||
| void Controller::setRightMotorSpeed(int speed) | ||
| { | ||
| rightWheel.setSpeed(speed); | ||
| } | ||
takuchi17 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // 右タイヤのモータに回転速度をセット | ||
nishijima515 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| void Controller::setLeftMotorSpeed(int speed) | ||
| { | ||
| leftWheel.setSpeed(speed); | ||
| } | ||
|
|
||
| // タイヤのモータを停止する | ||
nishijima515 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| void Controller::stopWheelsMotor() | ||
| { | ||
| powerOfRightWheel = 0; | ||
| powerOfLeftWheel = 0; | ||
nishijima515 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| rightWheel.stop(); | ||
| leftWheel.stop(); | ||
| } | ||
|
|
||
| // ブレーキをかけてタイヤのモータを停止する | ||
| void Controller::brakeWheelsMotor() | ||
| { | ||
| powerOfRightWheel = 0; | ||
| powerOfLeftWheel = 0; | ||
nishijima515 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| rightWheel.brake(); | ||
| leftWheel.brake(); | ||
| } | ||
|
|
||
| // アームのモータにpower値をセット | ||
| void Controller::setArmMotorPower(const int power) | ||
| { | ||
| powerOfArm = limitPowerValue(power); | ||
| armMotor.setPower(powerOfArm); | ||
| } | ||
|
|
||
| // アームのモータのpower値をリセット | ||
| void Controller::resetArmMotorPower() | ||
| { | ||
| powerOfArm = 0; | ||
| armMotor.setPower(powerOfArm); | ||
| } | ||
|
|
||
| // アームのモータを停止する | ||
| void Controller::stopArmMotor() | ||
| { | ||
| powerOfArm = 0; | ||
nishijima515 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| armMotor.stop(); | ||
| } | ||
|
|
||
| // アームモータを止めて角度を維持する | ||
| void Controller::holdArmMotor() | ||
| { | ||
| armMotor.hold(); | ||
| } | ||
|
|
||
| // 右タイヤのpower値を取得する | ||
| int Controller::getRightMotorPower() | ||
| { | ||
| return rightWheel.getPower(); | ||
| } | ||
|
|
||
| // 左タイヤのpower値を取得する | ||
| int Controller::getLeftMotorPower() | ||
| { | ||
| return leftWheel.getPower(); | ||
| } | ||
|
|
||
| // 右モータの角位置を取得する | ||
| int32_t Controller::getRightCount() | ||
nishijima515 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| return rightWheel.getCount(); | ||
| } | ||
|
|
||
| // 右モータの角位置を取得する | ||
nishijima515 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| int32_t Controller::getLeftCount() | ||
molpui0726 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| return leftWheel.getCount(); | ||
| } | ||
nishijima515 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // アームモータの角位置を取得する | ||
| int32_t Controller::getArmMotorCount() | ||
| { | ||
| return armMotor.getCount(); | ||
| } | ||
|
|
||
| // 右タイヤモータの回転速度を取得する | ||
| int Controller::getRightMotorSpeed() | ||
nishijima515 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| return rightWheel.getSpeed(); | ||
| } | ||
|
|
||
| // 左タイヤモータの回転速度を取得する | ||
| int Controller::getLeftMotorSpeed() | ||
| { | ||
| return leftWheel.getSpeed(); | ||
| } | ||
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,134 @@ | ||
| /** | ||
| * @file Controller.h | ||
| * @brief モーター制御に用いる関数をまとめたラッパークラス | ||
| * @author nishijima515 | ||
| */ | ||
| #ifndef CONTROLLER_H | ||
| #define CONTROLLER_H | ||
|
|
||
| #include "Motor.h" | ||
|
|
||
| class Controller { | ||
| public: | ||
| /** Power値の上限 */ | ||
| static constexpr int MOTOR_POWER_MAX = 100; | ||
|
|
||
| /** Power値の下限 */ | ||
| static constexpr int MOTOR_POWER_MIN = -100; | ||
|
|
||
| /** | ||
| * コンストラクタ | ||
| */ | ||
| Controller(); | ||
|
|
||
| /** | ||
| * @brief タイヤのモータにPower値をセット | ||
| * @param power Power値 | ||
| */ | ||
nishijima515 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| void setRightMotorPower(const int power); | ||
| void setLeftMotorPower(const int power); | ||
nishijima515 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * @brief タイヤのモータのpower値をリセット | ||
| */ | ||
nishijima515 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| void resetRightMotorPower(); | ||
| void resetLeftMotorPower(); | ||
| void resetWheelsMotorPower(); | ||
|
|
||
nishijima515 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /** | ||
| * @brief タイヤのモータに回転速度をセット | ||
| * @param speed 回転速度 | ||
| */ | ||
nishijima515 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| void setRightMotorSpeed(const int speed); | ||
| void setLeftMotorSpeed(const int speed); | ||
| /** | ||
| * @brief タイヤのモータを停止する | ||
| */ | ||
| void stopWheelsMotor(); | ||
nishijima515 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * @brief ブレーキをかけてタイヤのモータを停止する | ||
| */ | ||
| void brakeWheelsMotor(); | ||
|
|
||
| /** | ||
| * @brief アームのモータにpower値をセット | ||
| * @param power power値 | ||
| */ | ||
| void setArmMotorPower(const int power); | ||
|
|
||
| /** | ||
| * @brief アームのモータのpower値をリセット | ||
| */ | ||
nishijima515 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| void resetArmMotorPower(); | ||
|
|
||
| /** | ||
| * @brief アームのモータを停止する | ||
| */ | ||
| void stopArmMotor(); | ||
|
|
||
| /** | ||
| * アームモータを止めて角度を維持する | ||
| * @return - | ||
| */ | ||
nishijima515 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| void holdArmMotor(); | ||
|
|
||
| /** | ||
| * @brief 右モータの角位置を取得する | ||
| * @return 右モータの角位置 | ||
| */ | ||
nishijima515 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| int32_t getRightCount(); | ||
|
|
||
| /** | ||
| * @brief 左モータの角位置を取得する | ||
| * @return 左モータの角位置 | ||
| */ | ||
| int32_t getLeftCount(); | ||
|
|
||
| /** | ||
| * @brief アームモータの角位置を取得する | ||
| * @return アームモータの角位置 | ||
| */ | ||
| int32_t getArmMotorCount(); | ||
|
|
||
| /** | ||
| * @brief 右タイヤのpower値を取得する | ||
| * @return 右タイヤのpower値 | ||
| */ | ||
| int getRightMotorPower(); | ||
|
|
||
| /** | ||
| * @brief 左タイヤのpower値を取得する | ||
| * @return 左タイヤのpower値 | ||
| */ | ||
| int getLeftMotorPower(); | ||
|
|
||
| /** | ||
| * @brief 右タイヤの回転速度を取得する | ||
| * @return 右タイヤの回転速度 | ||
| */ | ||
| int getRightMotorSpeed(); | ||
|
|
||
| /** | ||
| * @brief 左タイヤの回転速度を取得する | ||
| * @return 左タイヤの回転速度 | ||
| */ | ||
| int getLeftMotorSpeed(); | ||
|
|
||
| private: | ||
| Motor rightWheel; | ||
| Motor leftWheel; | ||
| Motor armMotor; | ||
nishijima515 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| static int powerOfRightWheel; // 右タイヤpower | ||
| static int powerOfLeftWheel; // 左タイヤpower | ||
| static int powerOfArm; // アームpower | ||
takahashitom marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * @brief モータに設定するpower値の制限 | ||
| * @param inputpower 入力されたpower値 | ||
| * @return 制限されたpower値 | ||
| */ | ||
nishijima515 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| int limitPowerValue(const int inputPower); | ||
| }; | ||
|
|
||
| #endif | ||
Oops, something went wrong.
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.