Skip to content

#KL26-142 目標地点に向かって移動する動作クラスの作成 - #36

Open
yutaro-1214 wants to merge 25 commits into
mainfrom
ticket-KL26-142
Open

#KL26-142 目標地点に向かって移動する動作クラスの作成#36
yutaro-1214 wants to merge 25 commits into
mainfrom
ticket-KL26-142

Conversation

@yutaro-1214

@yutaro-1214 yutaro-1214 commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

チェックリスト

  • clang-format している
  • コーディング規約に準じている
  • チケットの完了条件を満たしている

変更点

Positionクラス(自己位置を保持するクラス)
Odometryクラス(モーターの動きから自己位置を更新するクラス)
Navigatorクラス(自分の位置から目標地点への距離と方向を計算するクラス)
GoalNavigationクラス(目標地点へ回頭してから移動する動作クラス)
の追加

それに伴うRobotクラスの更新

Pidクラスにreset()(PIDの内部状態をリセットする)コマンドを追加
(テストはまだです)

動作テスト

実験方法

実験結果

添付資料

https://app.notion.com/p/uom-katlab/3acdd5b1cc188010a209fe2c36806d81?source=copy_link

@yutaro-1214
yutaro-1214 requested a review from a team July 18, 2026 07:40

@takuchi17 takuchi17 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

オドメトリの更新周りが主です。

あと、回頭直進は既に作ってる動作クラスを使ってやる。

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

datafilesは変更する必要あった?なければ変更なしで。

Comment thread modules/EtRobocon2026.cpp

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

変更しない

Comment thread modules/MotionParser.cpp
double tolerance = fromString<double>(params[3]);
return make_unique<RelativeAngleCondition>(robot, targetAngle, tolerance);
}
// ↓ 他の条件コマンドはここに追加していく

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

この行は消しちゃっていい

Comment thread modules/MotionParser.cpp
double targetDistance = fromString<double>(params[2]);
return make_unique<DistanceCondition>(robot, targetDistance);
}
case CONDITION_COMMAND::ABSOLUTEANGLE: {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
case CONDITION_COMMAND::ABSOLUTEANGLE: {
case CONDITION_COMMAND::ABSOLUTE_ANGLE: {

Comment thread modules/MotionParser.cpp
double tolerance = fromString<double>(params[3]);
return make_unique<AbsoluteAngleCondition>(robot, targetAngle, tolerance);
}
case CONDITION_COMMAND::RELATIVEANGLE: {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
case CONDITION_COMMAND::RELATIVEANGLE: {
case CONDITION_COMMAND::RELATIVE_ANGLE: {

Comment thread modules/MotionParser.h
enum class MOTION_COMMAND { STRAIGHT, ABSOLUTEROTATION, RELATIVEROTATION, NONE };
// 条件コマンド名を持つ列挙型クラス
enum class CONDITION_COMMAND { DISTANCE, NONE };
enum class CONDITION_COMMAND { DISTANCE, ABSOLUTEANGLE, RELATIVEANGLE, NONE };

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
enum class CONDITION_COMMAND { DISTANCE, ABSOLUTEANGLE, RELATIVEANGLE, NONE };
enum class CONDITION_COMMAND { DISTANCE, ABSOLUTE_ANGLE, RELATIVE_ANGLE, NONE };

Comment thread modules/calculators/Odometry.h Outdated
* @param left 左エンコーダ値[deg]
* @param right 右エンコーダ値[deg]
*/
void initialize(int32_t left, int32_t right);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leftとrightだけじゃ何かよくわからない。

Comment thread modules/calculators/Odometry.h Outdated
* @param right 右エンコーダ値[deg]
* @param heading IMU方位角[deg]
*/
void update(int32_t left, int32_t right, double heading);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

こっちも

Comment thread modules/calculators/Odometry.h Outdated
Comment on lines +45 to +46
int32_t prevLeft;
int32_t prevRight;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これも

Comment thread modules/motions/GoalNavigation.cpp Outdated
Comment on lines +56 to +103
// オドメトリ更新
robot.getOdometry().update(robot.getWheelMotorControllerInstance().getLeftCount(),
robot.getWheelMotorControllerInstance().getRightCount(),
robot.getIMUControllerInstance().getAzimuth());

// 現在位置から目標方向を毎周期更新
targetAngle = robot.getNavigator().calculateHeading(goalX, goalY);

double currentAngle = robot.getIMUControllerInstance().getAzimuth();

double angleDeviation = AngleNormalizer::normalizeAngle(targetAngle - currentAngle);

switch(state) {
//--------------------------------------------------
// 回頭
//--------------------------------------------------
case State::ROTATE: {
double turningPower = anglePid.calculatePid(angleDeviation);

robot.getWheelMotorControllerInstance().setRightPower(turningPower);
robot.getWheelMotorControllerInstance().setLeftPower(-turningPower);

// 十分向けたら直進へ
if(std::fabs(angleDeviation) <= ANGLE_TOLERANCE) {
anglePid.reset(); // PIDの内部状態をリセット
state = State::STRAIGHT;
}

break;
}

//--------------------------------------------------
// 直進
//--------------------------------------------------
case State::STRAIGHT: {
double requiredRightPower = speedCalculator.calculateRightMotorPower();

double requiredLeftPower = speedCalculator.calculateLeftMotorPower();

double turningPower = anglePid.calculatePid(angleDeviation);

robot.getWheelMotorControllerInstance().setRightPower(requiredRightPower + turningPower);

robot.getWheelMotorControllerInstance().setLeftPower(requiredLeftPower - turningPower);

break;
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prepareで回頭角とか直進距離を算出して、あとはStraightクラスとRotationクラスを使って順番に動作すればよくない?

オドメトリの更新は全動作クラスで行う方針だし。
となるとBaseMotionでオドメトリの更新処理を書く必要あり。

@miyahara046 miyahara046 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ごめんなさい中身がほとんどないレビューです。

Comment on lines +43 to +45
double goalX; ///< 目標X座標(mm)
double goalY; ///< 目標Y座標(mm)
double tolerance; ///< 到達判定距離(mm)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

///<この形でのコメントにしてる意図が知りたい

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

だいたいchatGPTで作ったので普通にミスです。

Comment thread modules/motions/GoalNavigation.cpp Outdated
robot.getWheelMotorControllerInstance().setRightPower(turningPower);
robot.getWheelMotorControllerInstance().setLeftPower(-turningPower);

// 十分向けたら直進へ

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// 目標方位に達したらとかじゃない?

Comment thread modules/motions/GoalNavigation.h Outdated
Comment on lines +87 to +97
/// 回頭・方位補正用PID
Pid anglePid;

/// 左右速度PID計算
SpeedCalculator speedCalculator;

/// 現在向くべき目標角度
double targetAngle;

/// 回頭完了と判定する角度誤差(°)
static constexpr double ANGLE_TOLERANCE = 2.0;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

個々のコメントの書き方も他のクラスの書き方と合わせてほしい。
変数 //コメント

@HaruArima08 HaruArima08 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

とりあえず、細かい箇所のみです。
実際にこの動作クラスを使って走らせた動画があれば、そのリンクを貼ってくれると嬉しいです。

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これで暫定のPIDは決まった感じ?

public:
/**
* @brief コンストラクタ
* @param position 更新対象

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param position 更新対象
* @param position 更新する位置情報

Comment thread modules/calculators/Odometry.h Outdated
void update(int32_t left, int32_t right, double heading);

private:
Position& position;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

コメント入れる

Comment on lines +8 to +10
#include <cmath>
#include "AngleNormalizer.h"
#include "Mileage.h"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.hに置く

Comment thread modules/calculators/Navigator.h Outdated
double calculateHeading(double goalX, double goalY) const;

private:
const Position& position;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

コメント入れる


#include "Navigator.h"

#include <cmath>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.hに置く

Comment thread modules/calculators/Navigator.cpp Outdated
Comment on lines +11 to +13
namespace {
constexpr double RAD_TO_DEG = 180.0 / M_PI;
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SysytemInfoに定義してるのを使う

Comment on lines +43 to +45
double goalX; ///< 目標X座標(mm)
double goalY; ///< 目標Y座標(mm)
double tolerance; ///< 到達判定距離(mm)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
double goalX; ///< 目標X座標(mm)
double goalY; ///< 目標Y座標(mm)
double tolerance; ///< 到達判定距離(mm)
double goalX; // 目標X座標(mm)
double goalY; // 目標Y座標(mm)
double tolerance; // 到達判定距離(mm)

@yutaro-1214
yutaro-1214 requested a review from a team July 29, 2026 07:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants