Skip to content

Commit 5e2af70

Browse files
KuwamaiShota Aoki
andauthored
ArUcoサンプルとピッキング動作の追加 (#169)
* arucoマーカの認識 * マーカ位置をm系に変換 * マーカ位置姿勢をtfに配信 * tfのsubscribe * マーカ位置が静止していることを検知 * スタイル修正 * picking動作追加 * 不要な記述を削除 * スタイル修正 * 不要な行を削除 * マーカ位置修正 * 把持姿勢の調整 * tf確認用rviz config追加 * URL更新 * マーカ認識位置のオフセットを削除 * Rviz configの切り替えを実装 * デフォルトで起動するスクリプトを修正 Co-authored-by: Shota Aoki <[email protected]> * ArUcoの辞書についてコメント追加 * 変数名修正 * デバッグ用処理を削除 * 変数名変更 * コメント追加 * tfの時間計算を修正 * 現在時刻の取得方法変更 * 不要なモジュールの削除 Co-authored-by: Shota Aoki <[email protected]> * Update README * Update README * PythonExpressionをUnlessConditionに置き換え * 複数マーカに対応 (cherry picked from commit aa3792b54ae873125a34611f93a0fecec57466c6) * 把持対象のframe id変更 * スタイル修正 * 待機姿勢を関節負荷の低いものに変更 * Update README * Update README * スタイル修正 Co-authored-by: Shota Aoki <[email protected]>
1 parent cdfc45d commit 5e2af70

File tree

10 files changed

+1146
-13
lines changed

10 files changed

+1146
-13
lines changed

crane_x7_examples/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ endif()
1717

1818
# find dependencies
1919
find_package(ament_cmake REQUIRED)
20+
find_package(cv_bridge REQUIRED)
2021
find_package(geometry_msgs REQUIRED)
2122
find_package(moveit_ros_planning_interface REQUIRED)
23+
find_package(OpenCV REQUIRED COMPONENTS core)
2224
find_package(rclcpp REQUIRED)
2325
find_package(tf2_geometry_msgs REQUIRED)
2426

@@ -29,12 +31,16 @@ set(executable_list
2931
pose_groupstate
3032
joint_values
3133
pick_and_place
34+
pick_and_place_tf
35+
aruco_detection
3236
)
3337
foreach(loop_var IN LISTS executable_list)
3438
add_executable(${loop_var} src/${loop_var}.cpp)
3539
ament_target_dependencies(${loop_var}
40+
cv_bridge
3641
geometry_msgs
3742
moveit_ros_planning_interface
43+
OpenCV
3844
rclcpp
3945
tf2_geometry_msgs
4046
)

crane_x7_examples/README.md

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,27 @@
22

33
このパッケージはCRANE-X7 ROS 2パッケージのサンプルコード集です。
44

5-
- [crane_x7_examples](#crane_x7_examples)
5+
- [crane\_x7\_examples](#crane_x7_examples)
66
- [準備(実機を使う場合)](#準備実機を使う場合)
77
- [1. CRANE-X7本体をPCに接続する](#1-crane-x7本体をpcに接続する)
88
- [2. USB通信ポートの接続を確認する](#2-usb通信ポートの接続を確認する)
9-
- [3. move_groupとcontrollerを起動する](#3-move_groupとcontrollerを起動する)
10-
- [標準モデルを使用する場合](#標準モデルを使用する場合)
9+
- [3. move\_groupとcontrollerを起動する](#3-move_groupとcontrollerを起動する)
10+
- [標準のCRANE-X7を使用する場合](#標準のcrane-x7を使用する場合)
1111
- [RealSense D435マウンタ搭載モデルを使用する場合](#realsense-d435マウンタ搭載モデルを使用する場合)
1212
- [準備 (Gazeboを使う場合)](#準備-gazeboを使う場合)
13-
- [1. move_groupとGazeboを起動する](#1-move_groupとgazeboを起動する)
13+
- [1. move\_groupとGazeboを起動する](#1-move_groupとgazeboを起動する)
1414
- [サンプルプログラムを実行する](#サンプルプログラムを実行する)
1515
- [Examples](#examples)
16-
- [gripper_control](#gripper_control)
17-
- [pose_groupstate](#pose_groupstate)
18-
- [joint_values](#joint_values)
19-
- [cartesian_path](#cartesian_path)
16+
- [gripper\_control](#gripper_control)
17+
- [pose\_groupstate](#pose_groupstate)
18+
- [joint\_values](#joint_values)
19+
- [cartesian\_path](#cartesian_path)
2020
- [Videos](#videos)
21-
- [pick_and_place](#pick_and_place)
21+
- [pick\_and\_place](#pick_and_place)
2222
- [Videos](#videos-1)
23+
- [aruco\_detection](#aruco_detection)
24+
- [実行手順](#実行手順)
25+
- [Videos](#videos-2)
2326

2427
## 準備(実機を使う場合)
2528

@@ -41,7 +44,7 @@ USB通信ポートの設定については`crane_x7_control`の
4144

4245
### 3. move_groupとcontrollerを起動する
4346

44-
#### 標準モデルを使用する場合
47+
#### 標準のCRANE-X7を使用する場合
4548
次のコマンドでmove_group (`crane_x7_moveit_config`)と
4649
controller (`crane_x7_control`)を起動します。
4750

@@ -196,3 +199,26 @@ CRANE-X7から20cm離れた位置にピッキング対象を設置します。
196199
[![crane_x7_pick_and_place_demo](http://img.youtube.com/vi/_8xBgpgMhk8/hqdefault.jpg)](https://youtu.be/_8xBgpgMhk8)
197200

198201
[back to example list](#examples)
202+
203+
---
204+
205+
### aruco_detection
206+
207+
モノに取り付けたArUcoマーカをカメラで認識し、マーカ位置に合わせて掴むコード例です。[RealSense D435マウンタ](https://github.com/rt-net/crane_x7_Hardware/blob/master/3d_print_parts/v1.0/CRANE-X7_HandA_RealSenseD435マウンタ.stl)搭載モデルで実行することを想定しています。
208+
209+
認識されたマーカの位置姿勢はtfのフレームとして配信されます。
210+
tfの`frame_id`はマーカIDごとに異なりID0のマーカの`frame_id``target_0`になります。掴む対象は`target_0`に設定されています。マーカ認識には[OpenCV](https://docs.opencv.org/4.x/d5/dae/tutorial_aruco_detection.html)を使用しています。
211+
212+
#### 実行手順
213+
1. [aruco_markers.pdf](./aruco_markers.pdf)をA4紙に印刷し、一辺50mmの立方体に取り付けます
214+
1. [「RealSense D435マウンタ搭載モデルを使用する場合」](#realsense-d435マウンタ搭載モデルを使用する場合)の手順でCRANE-X7を起動します
215+
1. 次のコマンドを実行します
216+
```sh
217+
ros2 launch crane_x7_examples camera_example.launch.py example:='aruco_detection'
218+
```
219+
1. マーカのついた立方体をカメラに写る位置に置きます
220+
221+
#### Videos
222+
[![crane_x7_aruco_detection_demo](http://img.youtube.com/vi/eWzmG_jbTmM/hqdefault.jpg)](https://youtu.be/eWzmG_jbTmM)
223+
224+
[back to example list](#examples)

crane_x7_examples/aruco_markers.pdf

28.2 KB
Binary file not shown.
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Copyright 2022 RT Corporation
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import os
16+
17+
from ament_index_python.packages import get_package_share_directory
18+
from crane_x7_description.robot_description_loader import RobotDescriptionLoader
19+
from launch import LaunchDescription
20+
from launch.actions import DeclareLaunchArgument
21+
from launch.substitutions import LaunchConfiguration
22+
from launch_ros.actions import SetParameter
23+
from launch_ros.actions import Node
24+
import yaml
25+
26+
27+
def load_file(package_name, file_path):
28+
package_path = get_package_share_directory(package_name)
29+
absolute_file_path = os.path.join(package_path, file_path)
30+
31+
try:
32+
with open(absolute_file_path, 'r') as file:
33+
return file.read()
34+
except EnvironmentError: # parent of IOError, OSError *and* WindowsError where available
35+
return None
36+
37+
38+
def load_yaml(package_name, file_path):
39+
package_path = get_package_share_directory(package_name)
40+
absolute_file_path = os.path.join(package_path, file_path)
41+
42+
try:
43+
with open(absolute_file_path, 'r') as file:
44+
return yaml.safe_load(file)
45+
except EnvironmentError: # parent of IOError, OSError *and* WindowsError where available
46+
return None
47+
48+
49+
def generate_launch_description():
50+
description_loader = RobotDescriptionLoader()
51+
52+
robot_description_semantic_config = load_file(
53+
'crane_x7_moveit_config', 'config/crane_x7.srdf')
54+
robot_description_semantic = {
55+
'robot_description_semantic': robot_description_semantic_config}
56+
57+
kinematics_yaml = load_yaml('crane_x7_moveit_config', 'config/kinematics.yaml')
58+
59+
declare_example_name = DeclareLaunchArgument(
60+
'example', default_value='aruco_detection',
61+
description=('Set an example executable name: '
62+
'[aruco_detection]')
63+
)
64+
65+
declare_use_sim_time = DeclareLaunchArgument(
66+
'use_sim_time', default_value='false',
67+
description=('Set true when using the gazebo simulator.')
68+
)
69+
70+
picking_node = Node(name="pick_and_place_tf",
71+
package='crane_x7_examples',
72+
executable='pick_and_place_tf',
73+
output='screen',
74+
parameters=[{'robot_description': description_loader.load()},
75+
robot_description_semantic,
76+
kinematics_yaml])
77+
78+
detection_node = Node(name=[LaunchConfiguration('example'), '_node'],
79+
package='crane_x7_examples',
80+
executable=LaunchConfiguration('example'),
81+
output='screen')
82+
83+
return LaunchDescription([
84+
declare_use_sim_time,
85+
SetParameter(name='use_sim_time', value=LaunchConfiguration('use_sim_time')),
86+
picking_node,
87+
detection_node,
88+
declare_example_name
89+
])

0 commit comments

Comments
 (0)