#KL26-142 目標地点に向かって移動する動作クラスの作成 - #36
Conversation
takuchi17
left a comment
There was a problem hiding this comment.
オドメトリの更新周りが主です。
あと、回頭直進は既に作ってる動作クラスを使ってやる。
There was a problem hiding this comment.
datafilesは変更する必要あった?なければ変更なしで。
| double tolerance = fromString<double>(params[3]); | ||
| return make_unique<RelativeAngleCondition>(robot, targetAngle, tolerance); | ||
| } | ||
| // ↓ 他の条件コマンドはここに追加していく |
| double targetDistance = fromString<double>(params[2]); | ||
| return make_unique<DistanceCondition>(robot, targetDistance); | ||
| } | ||
| case CONDITION_COMMAND::ABSOLUTEANGLE: { |
There was a problem hiding this comment.
| case CONDITION_COMMAND::ABSOLUTEANGLE: { | |
| case CONDITION_COMMAND::ABSOLUTE_ANGLE: { |
| double tolerance = fromString<double>(params[3]); | ||
| return make_unique<AbsoluteAngleCondition>(robot, targetAngle, tolerance); | ||
| } | ||
| case CONDITION_COMMAND::RELATIVEANGLE: { |
There was a problem hiding this comment.
| case CONDITION_COMMAND::RELATIVEANGLE: { | |
| case CONDITION_COMMAND::RELATIVE_ANGLE: { |
| enum class MOTION_COMMAND { STRAIGHT, ABSOLUTEROTATION, RELATIVEROTATION, NONE }; | ||
| // 条件コマンド名を持つ列挙型クラス | ||
| enum class CONDITION_COMMAND { DISTANCE, NONE }; | ||
| enum class CONDITION_COMMAND { DISTANCE, ABSOLUTEANGLE, RELATIVEANGLE, NONE }; |
There was a problem hiding this comment.
| enum class CONDITION_COMMAND { DISTANCE, ABSOLUTEANGLE, RELATIVEANGLE, NONE }; | |
| enum class CONDITION_COMMAND { DISTANCE, ABSOLUTE_ANGLE, RELATIVE_ANGLE, NONE }; |
| * @param left 左エンコーダ値[deg] | ||
| * @param right 右エンコーダ値[deg] | ||
| */ | ||
| void initialize(int32_t left, int32_t right); |
There was a problem hiding this comment.
leftとrightだけじゃ何かよくわからない。
| * @param right 右エンコーダ値[deg] | ||
| * @param heading IMU方位角[deg] | ||
| */ | ||
| void update(int32_t left, int32_t right, double heading); |
| int32_t prevLeft; | ||
| int32_t prevRight; |
| // オドメトリ更新 | ||
| 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; | ||
| } | ||
| } |
There was a problem hiding this comment.
prepareで回頭角とか直進距離を算出して、あとはStraightクラスとRotationクラスを使って順番に動作すればよくない?
オドメトリの更新は全動作クラスで行う方針だし。
となるとBaseMotionでオドメトリの更新処理を書く必要あり。
miyahara046
left a comment
There was a problem hiding this comment.
ごめんなさい中身がほとんどないレビューです。
| double goalX; ///< 目標X座標(mm) | ||
| double goalY; ///< 目標Y座標(mm) | ||
| double tolerance; ///< 到達判定距離(mm) |
There was a problem hiding this comment.
///<この形でのコメントにしてる意図が知りたい
There was a problem hiding this comment.
だいたいchatGPTで作ったので普通にミスです。
| robot.getWheelMotorControllerInstance().setRightPower(turningPower); | ||
| robot.getWheelMotorControllerInstance().setLeftPower(-turningPower); | ||
|
|
||
| // 十分向けたら直進へ |
| /// 回頭・方位補正用PID | ||
| Pid anglePid; | ||
|
|
||
| /// 左右速度PID計算 | ||
| SpeedCalculator speedCalculator; | ||
|
|
||
| /// 現在向くべき目標角度 | ||
| double targetAngle; | ||
|
|
||
| /// 回頭完了と判定する角度誤差(°) | ||
| static constexpr double ANGLE_TOLERANCE = 2.0; |
There was a problem hiding this comment.
個々のコメントの書き方も他のクラスの書き方と合わせてほしい。
変数 //コメント
HaruArima08
left a comment
There was a problem hiding this comment.
とりあえず、細かい箇所のみです。
実際にこの動作クラスを使って走らせた動画があれば、そのリンクを貼ってくれると嬉しいです。
| public: | ||
| /** | ||
| * @brief コンストラクタ | ||
| * @param position 更新対象 |
There was a problem hiding this comment.
| * @param position 更新対象 | |
| * @param position 更新する位置情報 |
| void update(int32_t left, int32_t right, double heading); | ||
|
|
||
| private: | ||
| Position& position; |
| #include <cmath> | ||
| #include "AngleNormalizer.h" | ||
| #include "Mileage.h" |
| double calculateHeading(double goalX, double goalY) const; | ||
|
|
||
| private: | ||
| const Position& position; |
|
|
||
| #include "Navigator.h" | ||
|
|
||
| #include <cmath> |
| namespace { | ||
| constexpr double RAD_TO_DEG = 180.0 / M_PI; | ||
| } |
There was a problem hiding this comment.
SysytemInfoに定義してるのを使う
| double goalX; ///< 目標X座標(mm) | ||
| double goalY; ///< 目標Y座標(mm) | ||
| double tolerance; ///< 到達判定距離(mm) |
There was a problem hiding this comment.
| double goalX; ///< 目標X座標(mm) | |
| double goalY; ///< 目標Y座標(mm) | |
| double tolerance; ///< 到達判定距離(mm) | |
| double goalX; // 目標X座標(mm) | |
| double goalY; // 目標Y座標(mm) | |
| double tolerance; // 到達判定距離(mm) |
チェックリスト
変更点
Positionクラス(自己位置を保持するクラス)
Odometryクラス(モーターの動きから自己位置を更新するクラス)
Navigatorクラス(自分の位置から目標地点への距離と方向を計算するクラス)
GoalNavigationクラス(目標地点へ回頭してから移動する動作クラス)
の追加
それに伴うRobotクラスの更新
Pidクラスにreset()(PIDの内部状態をリセットする)コマンドを追加
(テストはまだです)
動作テスト
実験方法
実験結果
添付資料
https://app.notion.com/p/uom-katlab/3acdd5b1cc188010a209fe2c36806d81?source=copy_link