Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
6f2770a
add: 実機検証用
nishijima515 May 17, 2025
072479a
fix: エラー修正
nishijima515 May 17, 2025
af265c1
update:アームが正のパワー値で上に動くように変更
nishijima515 May 17, 2025
03e81ff
add: 回転速度、ブレーキ、アームホールド関係の関数の追加
nishijima515 May 17, 2025
932e54d
add:角位置取得関数の追加
nishijima515 May 19, 2025
66c6ead
refactor: コメントの修正
nishijima515 May 19, 2025
4618ece
update: gtestでのincludeディレクトリを追加
nishijima515 May 19, 2025
7b353bf
add: Controllerクラスのテストを行うためのダミークラスを追加
nishijima515 May 19, 2025
57294fe
add: Controllerクラスのテストを追加
nishijima515 May 19, 2025
4d17ac1
add: モータを動かすためのクラスの追加
nishijima515 May 19, 2025
4ff9805
update: buildを通すため、includeディレクトリを追加
nishijima515 May 19, 2025
6370360
update: テストを行うためにincludeディレクトリを追加
nishijima515 May 19, 2025
6ca0f69
add: コントローラクラスのテストを行うためのダミーを追加
nishijima515 May 19, 2025
def8acb
add: コントローラのテストを追加
nishijima515 May 19, 2025
6058bc9
refactor: MotorController.hに変更
nishijima515 May 20, 2025
cca9be6
add: テストで使うため、アームモータのpower値を取得する関数getArmMotorPowerの追加とコメントの修正
nishijima515 May 20, 2025
7471129
update: MotorControllerTest.cppに変更、power値の確認を行うようにした
nishijima515 May 20, 2025
ac2accb
refactor: テスト名をアッパーキャメルケースに修正
nishijima515 May 20, 2025
eeeb1f2
update: リセット系の関数の内部処理を変更
nishijima515 May 21, 2025
2cc9611
add: モータに設定するpower値の上限の制限が行われているか確認するテストの追加
nishijima515 May 21, 2025
2e8d882
refactor: include spikeapi.hの削除
nishijima515 May 21, 2025
f2345fe
update: 回転速度を取得する関数の戻り値の型をintからint32_tに変更
nishijima515 May 21, 2025
6d11bd6
refactor: 細かな修正
nishijima515 May 21, 2025
bb8177d
Merge branch 'ticket-KL25-17' into work-KL25-17
nishijima515 May 21, 2025
12dcb10
refactor: コメントの修正
nishijima515 May 21, 2025
df396ae
update: リセット系の関数の内部処理変更
nishijima515 May 21, 2025
9109369
add: テストで使うため、getArmMotorPower関数を追加した
nishijima515 May 21, 2025
b9beeb4
add: モータに設定するpower値の上限の制限が行われているか確認するテストの追加、テスト名をアッパーキャメルケースに変更
nishijima515 May 21, 2025
96119d9
delete: 名前の変更によりController系のファイルを削除
nishijima515 May 21, 2025
1cd59ee
delete: 名前の変更によりController系のファイルを削除
nishijima515 May 21, 2025
0624961
update: クラス名などのControllerをMotorControllerに変更
nishijima515 May 21, 2025
6c80cb1
クラス名などのControllerをMotorControllerに変更
nishijima515 May 21, 2025
165a04c
refactor: フォーマットエラー解消の試み
nishijima515 May 21, 2025
a69982b
refactor: 細かな修正
nishijima515 May 21, 2025
e963305
refactor: 細かな修正
nishijima515 May 21, 2025
d95b758
refactor: インクルードガードを大文字に修正、パワー保持変数の削除
nishijima515 May 21, 2025
afb8470
Merge branch 'work-KL25-17' into ticket-KL25-17
nishijima515 May 21, 2025
1271b01
delete: パワー保持変数の削除
nishijima515 May 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ set(PROJECT_TEST_DIR ${PROJECT_SOURCE_DIR}/tests)
# 必要なインクルードディレクトリの設定 (適宜登録)
set(INCLUDE_DIRS
${PROJECT_MODULE_DIR}
${PROJECT_MODULE_DIR}/API
${PROJECT_TEST_DIR}
${PROJECT_TEST_DIR}/dummy
${PROJECT_TEST_DIR}/helpers
)
)

# ソースファイルの登録 (適宜登録)
file(GLOB_RECURSE PROJECT_SOURCES
Expand All @@ -53,6 +56,11 @@ file(GLOB TEST_SOURCES "${PROJECT_TEST_DIR}/*Test.cpp")

# テスト実行可能ファイルの作成
add_executable(${PROJECT_NAME}_test ${TEST_SOURCES})
target_include_directories(${PROJECT_NAME}_test
PRIVATE
${PROJECT_TEST_DIR}/dummy # spikeapi ダミー用
)

target_link_libraries(${PROJECT_NAME}_test
PRIVATE
${PROJECT_NAME}_impl
Expand All @@ -61,4 +69,4 @@ target_link_libraries(${PROJECT_NAME}_test

# テストの登録
include(GoogleTest)
gtest_discover_tests(${PROJECT_NAME}_test)
gtest_discover_tests(${PROJECT_NAME}_test)
7 changes: 6 additions & 1 deletion Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ SRCLANG := c++

APPL_LIBS += -lm

APPL_DIRS += $(mkfile_path)modules
APPL_DIRS += \
$(mkfile_path)modules\
$(mkfile_path)modules/API



INCLUDES += \
-I$(mkfile_path)modules\
-I$(mkfile_path)modules/API
165 changes: 165 additions & 0 deletions modules/API/Controller.cpp
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),
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;

// モータに設定する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);
}

// 左モータに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);
}

// 右タイヤのモータに回転速度をセット
void Controller::setRightMotorSpeed(int speed)
{
rightWheel.setSpeed(speed);
}

// 右タイヤのモータに回転速度をセット
void Controller::setLeftMotorSpeed(int speed)
{
leftWheel.setSpeed(speed);
}

// タイヤのモータを停止する
void Controller::stopWheelsMotor()
{
powerOfRightWheel = 0;
powerOfLeftWheel = 0;
rightWheel.stop();
leftWheel.stop();
}

// ブレーキをかけてタイヤのモータを停止する
void Controller::brakeWheelsMotor()
{
powerOfRightWheel = 0;
powerOfLeftWheel = 0;
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;
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()
{
return rightWheel.getCount();
}

// 右モータの角位置を取得する
int32_t Controller::getLeftCount()
{
return leftWheel.getCount();
}

// アームモータの角位置を取得する
int32_t Controller::getArmMotorCount()
{
return armMotor.getCount();
}

// 右タイヤモータの回転速度を取得する
int Controller::getRightMotorSpeed()
{
return rightWheel.getSpeed();
}

// 左タイヤモータの回転速度を取得する
int Controller::getLeftMotorSpeed()
{
return leftWheel.getSpeed();
}
134 changes: 134 additions & 0 deletions modules/API/Controller.h
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値
*/
void setRightMotorPower(const int power);
void setLeftMotorPower(const int power);

/**
* @brief タイヤのモータのpower値をリセット
*/
void resetRightMotorPower();
void resetLeftMotorPower();
void resetWheelsMotorPower();

/**
* @brief タイヤのモータに回転速度をセット
* @param speed 回転速度
*/
void setRightMotorSpeed(const int speed);
void setLeftMotorSpeed(const int speed);
/**
* @brief タイヤのモータを停止する
*/
void stopWheelsMotor();

/**
* @brief ブレーキをかけてタイヤのモータを停止する
*/
void brakeWheelsMotor();

/**
* @brief アームのモータにpower値をセット
* @param power power値
*/
void setArmMotorPower(const int power);

/**
* @brief アームのモータのpower値をリセット
*/
void resetArmMotorPower();

/**
* @brief アームのモータを停止する
*/
void stopArmMotor();

/**
* アームモータを止めて角度を維持する
* @return -
*/
void holdArmMotor();

/**
* @brief 右モータの角位置を取得する
* @return 右モータの角位置
*/
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;
static int powerOfRightWheel; // 右タイヤpower
static int powerOfLeftWheel; // 左タイヤpower
static int powerOfArm; // アームpower

/**
* @brief モータに設定するpower値の制限
* @param inputpower 入力されたpower値
* @return 制限されたpower値
*/
int limitPowerValue(const int inputPower);
};

#endif
Loading