color_detectionサンプルの追加#183
Conversation
There was a problem hiding this comment.
Pull request overview
Sciurus17向けに、特定色(デフォルト青)の物体を深度画像込みで検出し、TF(target_0)として配信してピッキングにつなぐ color_detection サンプル(C++/Python)を追加するPRです。既存の2D版 color_detection コンポーネントは color_detection_2d にリネームし、追従系launchから参照する構成に整理しています。
Changes:
- C++: 深度+CameraInfoを同期して3D位置を算出しTF配信する
color_detection実行ファイルを追加 - C++: 既存2D検出コンポーネントを
color_detection_2dに改名し、関連launchを更新 - Python:
color_detectionと、それに対応するpick_and_place_tfとカメラ例launchを追加
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 12 comments.
Show a summary per file
| File | Description |
|---|---|
| sciurus17_examples/src/color_detection.cpp | 深度/CameraInfo同期で3D位置を算出しTF配信する新しい実行ファイルノードを実装 |
| sciurus17_examples/src/color_detection_2d.cpp | 既存2D検出を ColorDetection2d としてコンポーネント化 |
| sciurus17_examples/include/sciurus17_examples/color_detection_2d.hpp | ColorDetection2d の新規ヘッダ/ガード名更新 |
| sciurus17_examples/CMakeLists.txt | color_detection_2d をコンポーネント登録、color_detection を実行ファイルとして追加、依存追加 |
| sciurus17_examples/package.xml | image_transport/message_filters/tf2_ros 依存追加 |
| sciurus17_examples/README.md | color_detection サンプル説明を追加 |
| sciurus17_examples/launch/head_camera_tracking.launch.py | 参照コンポーネントを color_detection_2d に更新 |
| sciurus17_examples/launch/chest_camera_tracking.launch.py | 参照コンポーネントを color_detection_2d に更新 |
| sciurus17_examples/launch/example.launch.py | 例示リスト文言を更新 |
| sciurus17_examples/launch/camera_example.launch.py | color_detection を例示リストに追加 |
| sciurus17_examples_py/setup.py | pick_and_place_tf と color_detection エントリポイント追加 |
| sciurus17_examples_py/sciurus17_examples_py/pick_and_place_tf.py | TFターゲットを見てピック&プレースするノードを新規追加 |
| sciurus17_examples_py/sciurus17_examples_py/color_detection.py | Python版の深度同期・3D算出・TF配信ノードを新規追加 |
| sciurus17_examples_py/launch/camera_example.launch.py | Python版のカメラ例launchを新規追加 |
| sciurus17_examples_py/package.xml | Pythonサンプル実行に必要な依存を追加 |
| sciurus17_examples_py/README.md | Python版 color_detection サンプル説明を追加 |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
@Kuwamai レビューをお願いします。 |
| 特定の色の物体を検出して掴むコード例です。 | ||
|
|
||
| - デフォルトでは青い物体の位置をtfのフレームとして配信します。 | ||
| - `target_0`は、カメラ画像の`frame_id`を親フレームとするtfフレームとして配信します。 |
There was a problem hiding this comment.
この文章では配信するフレーム名について説明してほしいです。
親フレームについてはユーザーがサンプルを使う上で影響しないと思うので、言及しなくて大丈夫です。
| cv_depth = self.bridge.imgmsg_to_cv2(depth_msg, desired_encoding=depth_msg.encoding) | ||
|
|
||
| # カメラから把持対象物の表面までの距離 | ||
| depth = cv_depth[int(point[1]), int(point[0])] | ||
| if depth_msg.encoding == '16UC1': | ||
| front_distance = float(depth) / 1000.0 | ||
| elif depth_msg.encoding == '32FC1': | ||
| front_distance = float(depth) | ||
| else: | ||
| self.get_logger().warn(f'Unsupported depth encoding: {depth_msg.encoding}') | ||
| return |
There was a problem hiding this comment.
この部分の実装の背景が知りたいです。
X7の実装では動作しませんでしたか?
There was a problem hiding this comment.
X7の実装のまま動作させたところ、実機では動作したものの、Gazebo上では動作しませんでした。
実機とGazeboでRealsenseのエンコード方式が違っていたため、ひとまずここのサンプル上の条件分岐で対応としたという背景です。
| // 深度画像アクセス用に小数座標を整数インデックスに変換 | ||
| const cv::Point point_int(static_cast<int>(point.x), static_cast<int>(point.y)); | ||
|
|
||
| // エンコーディングの違いによる深度値の取得方法の違いに対応 | ||
| if (depth_msg->encoding == "16UC1") { | ||
| front_distance = cv_depth->image.at<uint16_t>(point_int) / 1000.0; | ||
| } else if (depth_msg->encoding == "32FC1") { | ||
| front_distance = cv_depth->image.at<float>(point_int); | ||
| } else { | ||
| RCLCPP_WARN( | ||
| this->get_logger(), | ||
| "Unsupported depth encoding: %s", | ||
| depth_msg->encoding.c_str()); | ||
| return; | ||
| } |
There was a problem hiding this comment.
Python版にコメントしてしまいましたが、どうようにこちらの意図も知りたいです。
What does this implement/fix?
color_detectionサンプルを追加します。
crane_x7_rosの
color_detectionサンプルをベースに実装しています。移植に加えて、Sciurus17向けに以下の変更・修正を行っています。
sciurus17_examples/src/color_detection_2d.cppcolor_detectionコンポーネントをcolor_detection_2dにリネームしました。ColorDetection2Dに変更しています。head_camera_tracking.launch.py/chest_camera_tracking.launch.pyの component 名・plugin 名も更新しています。sciurus17_examples/src/color_detection.cppcolor_detectionとして、 Sciurus17 のカメラ構成に合わせて調整しました。/head_camera/color/image_raw、/head_camera/aligned_depth_to_color/image_raw、/head_camera/color/camera_infoに変更しています。target_0の TF として配信します。16UC1と32FC1の両方に対応しています。w=1.0を明示しました。cv::moments()の名前空間を明示しました。static_cast<int>にしました。sciurus17_examples/src/pick_and_place_tf.cpppick_and_place_tf.cppを実機/Gazeboでの動作に合わせて調整しました。0.03程度となって青色キューブが把持対象外となってしまうため、0.04から0.02に緩和しています。sciurus17_examples_py/sciurus17_examples_py/color_detection.pycolor_detectionサンプルとして追加しました。16UC1/32FC1の深度画像 encoding に対応しています。target_0の TF として配信します。w=1.0を明示しています。sciurus17_examples_py/sciurus17_examples_py/pick_and_place_tf.pypick_and_place_tf.pyを追加しました。その他
camera_example.launch.pyからcolor_detectionを起動できるようにしました。image_transport、message_filters、image_geometry、tf2_ros、cv_bridgeなど必要な依存関係を追加しています。color_detectionの実行方法と、配信される TF frame の説明を追記しました。Does this close any currently open issues?
しません。
How has this been tested?
実機とGazeboの両方で動作を確認しました。
Any other comments?
なし
Checklists