Skip to content

Commit aed6727

Browse files
KuraZuzuCopilot
andauthored
color_detectionサンプルの追加 (#183)
* [WIP]color_detectionコンポーネントをcolor_detection2にリネーム * [WIP]color_detectionの実装 * launchのメッセージやREADME.mdを更新 * Python版をcrane_x7_rosから移植 * トピックをS17に向けたものにして構文ミスも修正 * pick_and_place_tf.py と camera用のluanchの追加 * README追記 * typo修正 Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * typo修正 Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * READMEのframe_idに関する表現の繻子栄 * Python版のREADMEのframe_idの表現も修正 * 現状だと高すぎて対象範囲に入らないため、把持対象の範囲を0.04->0.02mmに緩和 * Realsense実機とGazebo上でのエンコーディングの違いを吸収 * coments()をcv::moments()へと名前空間の明示 * 暗黙的な型変換を明示的なキャストに修正 * クォータニオンのデフォルトに恒等回転(w=1.0)を明示。Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * HSV変換時に共有されたROS画像バッファを書き換えないようにする Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Python版にもクォータニオンの恒常姿勢のデフォルト値を追加 Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * CIに従ってコードフォーマット修正 * CollorDetection2Dのクラス名の修正 * README内でのサンプル説明の表現修正 * 深度フォーマットについてのコメントを追加 * python版でjoint_valuesを受け取って範囲外であれば補正する処理の削除 --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent 5b4d668 commit aed6727

17 files changed

Lines changed: 1046 additions & 131 deletions

sciurus17_examples/CMakeLists.txt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,22 @@ find_package(cv_bridge REQUIRED)
2222
find_package(geometry_msgs REQUIRED)
2323
find_package(control_msgs REQUIRED)
2424
find_package(image_geometry REQUIRED)
25+
find_package(image_transport REQUIRED)
26+
find_package(message_filters REQUIRED)
2527
find_package(moveit_ros_planning_interface REQUIRED)
2628
find_package(OpenCV REQUIRED COMPONENTS core)
2729
find_package(pcl_conversions REQUIRED)
2830
find_package(pcl_ros REQUIRED)
2931
find_package(rclcpp REQUIRED)
32+
find_package(tf2_ros REQUIRED)
3033
find_package(tf2_geometry_msgs REQUIRED)
3134
find_package(rclcpp_action REQUIRED)
3235
find_package(rclcpp_components REQUIRED)
3336

3437
include_directories(include)
3538

3639
set(components_list
37-
color_detection
40+
color_detection_2d
3841
neck_jt_control
3942
object_tracker
4043
waist_jt_control
@@ -51,18 +54,21 @@ foreach(loop_var IN LISTS components_list)
5154
cv_bridge
5255
geometry_msgs
5356
image_geometry
57+
image_transport
58+
message_filters
5459
OpenCV
5560
rclcpp
61+
tf2_ros
5662
control_msgs)
5763
endforeach()
5864

59-
rclcpp_components_register_nodes(color_detection "sciurus17_examples::ColorDetection")
65+
rclcpp_components_register_nodes(color_detection_2d "sciurus17_examples::ColorDetection2D")
6066
rclcpp_components_register_nodes(neck_jt_control "sciurus17_examples::NeckJtControl")
6167
rclcpp_components_register_nodes(object_tracker "sciurus17_examples::ObjectTracker")
6268
rclcpp_components_register_nodes(waist_jt_control "sciurus17_examples::WaistJtControl")
6369

6470
install(TARGETS
65-
color_detection
71+
color_detection_2d
6672
neck_jt_control
6773
object_tracker
6874
waist_jt_control
@@ -121,6 +127,7 @@ set(executable_list
121127
pick_and_place_right_arm_waist
122128
pick_and_place_left_arm
123129
pick_and_place_tf
130+
color_detection
124131
point_cloud_detection
125132
)
126133
foreach(loop_var IN LISTS executable_list)
@@ -131,11 +138,14 @@ foreach(loop_var IN LISTS executable_list)
131138
cv_bridge
132139
geometry_msgs
133140
image_geometry
141+
image_transport
142+
message_filters
134143
moveit_ros_planning_interface
135144
OpenCV
136145
pcl_ros
137146
pcl_conversions
138147
rclcpp
148+
tf2_ros
139149
tf2_geometry_msgs
140150
control_msgs
141151
)

sciurus17_examples/README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
- [pick\_and\_place\_left\_arm](#pick_and_place_left_arm)
2020
- [head\_camera\_tracking](#head_camera_tracking)
2121
- [chest\_camera\_tracking](#chest_camera_tracking)
22+
- [color\_detection](#color_detection)
2223
- [point\_cloud\_detection](#point_cloud_detection)
2324

2425
## Setup
@@ -289,12 +290,31 @@ ros2 launch sciurus17_examples chest_camera_tracking.launch.py
289290
290291
---
291292
293+
### color_detection
294+
295+
特定の色の物体を検出して掴むコード例です。
296+
297+
- デフォルトでは青い物体の位置をtfのフレームとして配信します。
298+
- 検出した物体のフレーム名は `target_0` です。
299+
- 色の検出にはOpenCVを使用しています。
300+
- 検出した物体の距離は深度画像から取得します。
301+
302+
次のコマンドを実行します。
303+
304+
```sh
305+
ros2 launch sciurus17_examples camera_example.launch.py example:='color_detection'
306+
```
307+
308+
[Back to example list](#examples)
309+
310+
---
311+
292312
### point_cloud_detection
293313
294314
点群から物体を検出して掴むコード例です。
295315
296316
- 検出された物体位置はtfのフレームとして配信されます。
297-
- tfの`frame_id`は検出された順に`target_0``target_1``target_2`に設定されます
317+
- 検出した物体のフレーム名は `target_0``target_1``target_2`です
298318
- 掴む対象はSciurus17前方の0.3 mの範囲にある`target_0`に設定されています。
299319
- 物体検出には[Point Cloud Library](https://pointclouds.org/)を使用しています。
300320

sciurus17_examples/include/sciurus17_examples/color_detection.hpp renamed to sciurus17_examples/include/sciurus17_examples/color_detection_2d.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#ifndef SCIURUS17_EXAMPLES__COLOR_DETECTION_HPP_
16-
#define SCIURUS17_EXAMPLES__COLOR_DETECTION_HPP_
15+
#ifndef SCIURUS17_EXAMPLES__COLOR_DETECTION_2D_HPP_
16+
#define SCIURUS17_EXAMPLES__COLOR_DETECTION_2D_HPP_
1717

1818
#include "rclcpp/rclcpp.hpp"
1919
#include "geometry_msgs/msg/point_stamped.hpp"
@@ -23,10 +23,10 @@
2323
namespace sciurus17_examples
2424
{
2525

26-
class ColorDetection : public rclcpp::Node
26+
class ColorDetection2D : public rclcpp::Node
2727
{
2828
public:
29-
explicit ColorDetection(const rclcpp::NodeOptions & options);
29+
explicit ColorDetection2D(const rclcpp::NodeOptions & options);
3030

3131
private:
3232
rclcpp::Subscription<sensor_msgs::msg::Image>::SharedPtr image_subscription_;
@@ -39,4 +39,4 @@ class ColorDetection : public rclcpp::Node
3939

4040
} // namespace sciurus17_examples
4141

42-
#endif // SCIURUS17_EXAMPLES__COLOR_DETECTION_HPP_
42+
#endif // SCIURUS17_EXAMPLES__COLOR_DETECTION_2D_HPP_

sciurus17_examples/launch/camera_example.launch.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ def generate_launch_description():
2525
declare_example_name = DeclareLaunchArgument(
2626
'example',
2727
default_value='point_cloud_detection',
28-
description=('Set an example executable name: [point_cloud_detection]'),
28+
description=(
29+
'Set an example executable name: '
30+
'[color_detection, point_cloud_detection]'
31+
),
2932
)
3033

3134
declare_use_sim_time = DeclareLaunchArgument(

sciurus17_examples/launch/chest_camera_tracking.launch.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ def generate_launch_description():
3535
output='screen',
3636
composable_node_descriptions=[
3737
ComposableNode(
38-
name='color_detection',
38+
name='color_detection_2d',
3939
namespace='chest_camera_tracking',
4040
package='sciurus17_examples',
41-
plugin='sciurus17_examples::ColorDetection',
41+
plugin='sciurus17_examples::ColorDetection2D',
4242
remappings=[('/image_raw', '/chest_camera/image_raw')],
4343
extra_arguments=[{'use_intra_process_comms': True}],
4444
),

sciurus17_examples/launch/example.launch.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ def generate_launch_description():
2828
description=(
2929
'Set an example executable name: '
3030
'[gripper_control, pose_groupstate, joint_values, neck_control, waist_control,'
31-
'pick_and_place_right_arm_waist, pick_and_place_left_arm]'
31+
'pick_and_place_right_arm_waist, pick_and_place_left_arm, head_camera_tracking, '
32+
'chest_camera_tracking]'
3233
),
3334
)
34-
3535
declare_use_sim_time = DeclareLaunchArgument(
3636
'use_sim_time',
3737
default_value='false',

sciurus17_examples/launch/head_camera_tracking.launch.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ def generate_launch_description():
3535
output='screen',
3636
composable_node_descriptions=[
3737
ComposableNode(
38-
name='color_detection',
38+
name='color_detection_2d',
3939
namespace='head_camera_tracking',
4040
package='sciurus17_examples',
41-
plugin='sciurus17_examples::ColorDetection',
41+
plugin='sciurus17_examples::ColorDetection2D',
4242
remappings=[('/image_raw', '/head_camera/color/image_raw')],
4343
extra_arguments=[{'use_intra_process_comms': True}],
4444
),

sciurus17_examples/package.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,14 @@
2222
<depend>cv_bridge</depend>
2323
<depend>geometry_msgs</depend>
2424
<depend>image_geometry</depend>
25+
<depend>image_transport</depend>
26+
<depend>message_filters</depend>
2527
<depend>libopencv-dev</depend>
2628
<depend>moveit_ros_planning_interface</depend>
2729
<depend>pcl_ros</depend>
2830
<depend>rclcpp</depend>
2931
<depend>rclcpp_components</depend>
32+
<depend>tf2_ros</depend>
3033
<depend>tf2_geometry_msgs</depend>
3134

3235
<test_depend>ament_lint_auto</test_depend>

0 commit comments

Comments
 (0)