Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

moveit_pyでロボットを動かすサンプルを追加します #164

Merged
merged 48 commits into from
Dec 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
7fdbb47
jazzyでビルドが通るように修正
chama1176 Jul 8, 2024
40749ac
capabilitiesに対応
chama1176 Jul 9, 2024
1491067
gz-sim対応
chama1176 Jul 9, 2024
45d2ccb
OMPLの設定ファイルを追加
chama1176 Jul 12, 2024
537cc7d
doc, ciをJazzy対応
chama1176 Jul 17, 2024
3531db7
Revert "jazzyでビルドが通るように修正"
chama1176 Jul 18, 2024
43216c2
誤ってフォーマッターをかけてしまっていたので修正します
chama1176 Jul 18, 2024
3e9401e
usb camの依存パッケージのバージョンについて記載
chama1176 Jul 18, 2024
fa714c2
Merge branch 'feature/support-jazzy' into feature/add-ompl-config
chama1176 Jul 18, 2024
5f62ad7
リリースされるまでバージョン指定を入れておく
chama1176 Jul 19, 2024
adc8fea
two handsをompl設定に追加
chama1176 Jul 19, 2024
e96d86a
MoveitConfigsBuilder周辺の記載を変更
chama1176 Jul 19, 2024
231905b
add mock components support
chama1176 Jul 26, 2024
3648242
登録位置への移動サンプル
chama1176 Aug 14, 2024
677fa63
グリッパー開閉を確認
chama1176 Aug 16, 2024
4532f55
一通りの流れを再現
chama1176 Aug 16, 2024
7d556fe
ファイル構成を変更
chama1176 Aug 16, 2024
c56f72a
licence
chama1176 Aug 19, 2024
a14f513
add gripper_control example
chama1176 Aug 19, 2024
b80158e
utilsを分離
chama1176 Aug 20, 2024
3d11203
左右腕が違ったので反転
chama1176 Oct 10, 2024
f6d932b
Merge remote-tracking branch 'origin/ros2' into feature/moveit_py
chama1176 Nov 28, 2024
9cd5055
mergeを修正
chama1176 Nov 28, 2024
ab8fb76
不要なものを削除
chama1176 Nov 28, 2024
fe33346
flake8通るように修正
chama1176 Nov 28, 2024
dba255f
add neck sample
chama1176 Nov 28, 2024
fd14a8f
fix format
chama1176 Nov 28, 2024
6cc7b78
add waist sample
chama1176 Nov 28, 2024
65036d6
add right arm waist sample
chama1176 Nov 28, 2024
8870b7d
READMEを修正
chama1176 Nov 29, 2024
f930b5d
fix copyright
chama1176 Nov 29, 2024
040742a
Update sciurus17_examples_py/sciurus17_examples_py/gripper_control.py
chama1176 Dec 17, 2024
0bba2e1
Update sciurus17_examples_py/sciurus17_examples_py/neck_control.py
chama1176 Dec 17, 2024
9947152
Update sciurus17_examples_py/README.md
chama1176 Dec 17, 2024
cfd079c
Update sciurus17_examples_py/README.md
chama1176 Dec 17, 2024
5e5a529
Update sciurus17_examples_py/sciurus17_examples_py/pick_and_place_rig…
chama1176 Dec 17, 2024
cbac826
Update sciurus17_examples_py/sciurus17_examples_py/waist_control.py
chama1176 Dec 17, 2024
4ac913c
Update sciurus17_examples_py/sciurus17_examples_py/pick_and_place_lef…
chama1176 Dec 17, 2024
070dd63
Update sciurus17_examples_py/sciurus17_examples_py/pick_and_place_lef…
chama1176 Dec 17, 2024
1046138
Update sciurus17_examples_py/sciurus17_examples_py/pick_and_place_rig…
chama1176 Dec 17, 2024
a950e98
Update sciurus17_examples_py/sciurus17_examples_py/pick_and_place_rig…
chama1176 Dec 17, 2024
896b049
Update sciurus17_examples_py/sciurus17_examples_py/pick_and_place_lef…
chama1176 Dec 17, 2024
67ed12e
レビュー指摘事項に対応
chama1176 Dec 18, 2024
b16cede
指摘事項を修正
chama1176 Dec 23, 2024
96f2f82
flake8通るように修正
chama1176 Dec 23, 2024
453edd8
Update sciurus17_examples_py/package.xml
chama1176 Dec 24, 2024
d985051
add author tag
chama1176 Dec 24, 2024
e1e67ba
READMEに追加
chama1176 Dec 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ ros2 launch sciurus17_examples example.launch.py example:='gripper_control'
- sciurus17_examples
- [README](./sciurus17_examples/README.md)
- Sciurus17のサンプルコード集です
- sciurus17_examples_py
- [README](./sciurus17_examples_py/README.md)
- Sciurus17のPythonサンプルコード集です
- sciurus17_gazebo
- Sciurus17のGazeboシミュレーションパッケージです
- sciurus17_moveit_config
Expand Down
122 changes: 122 additions & 0 deletions sciurus17_examples_py/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# sciurus17_examples_py

このパッケージはSciurus17 ROS 2パッケージのPythonサンプルコード集です。

- [sciurus17\_examples](#sciurus17_examples)
chama1176 marked this conversation as resolved.
Show resolved Hide resolved
- [起動方法](#起動方法)
- [サンプルプログラムを実行する](#サンプルプログラムを実行する)
- [Gazeboでサンプルプログラムを実行する場合](#gazeboでサンプルプログラムを実行する場合)
- [Examples](#examples)
- [gripper\_control](#gripper_control)
- [neck\_control](#neck_control)
- [waist\_control](#waist_control)
- [pick\_and\_place\_right\_arm\_waist](#pick_and_place_right_arm_waist)
- [pick\_and\_place\_left\_arm](#pick_and_place_left_arm)

## 起動方法
Sciurus17の起動方法は[sciurus17_examplesのREADME](../sciurus17_examples/README.md)を参照してください。

## サンプルプログラムを実行する

準備ができたらサンプルプログラムを実行します。
例えばグリッパを開閉するサンプルは次のコマンドで実行できます。

```sh
ros2 launch sciurus17_examples_py example.launch.py example:='gripper_control'
```

終了するときは`Ctrl+c`を入力します。

### Gazeboでサンプルプログラムを実行する場合

Gazeboでサンプルプログラムを実行する場合は`use_sim_time`オプションを付けます。

```sh
ros2 launch sciurus17_examples_py example.launch.py example:='gripper_control' use_sim_time:='true'
```

## Examples

`demo.launch`を実行している状態で各サンプルを実行できます。

- [gripper\_control](#gripper_control)
- [neck\_control](#neck_control)
- [waist\_control](#waist_control)
- [pick\_and\_place\_right\_arm\_waist](#pick_and_place_right_arm_waist)
- [pick\_and\_place\_left\_arm](#pick_and_place_left_arm)

実行できるサンプルの一覧は、`example.launch.py`にオプション`-s`を付けて実行することで表示できます。

```sh
ros2 launch sciurus17_examples_py example.launch.py -s
```

### gripper_control

ハンドを開閉させるコード例です。

次のコマンドを実行します。

```sh
ros2 launch sciurus17_examples_py example.launch.py example:='gripper_control'
```

[back to example list](#examples)

---

### neck_control

首を上下左右へ動かすコード例です。

次のコマンドを実行します。

```sh
ros2 launch sciurus17_examples_py example.launch.py example:='neck_control'
```

[back to example list](#examples)

---

### waist_control

腰を左右へひねる動作をするコード例です。

次のコマンドを実行します。

```sh
ros2 launch sciurus17_examples_py example.launch.py example:='waist_control'
```

[back to example list](#examples)

---

### pick_and_place_right_arm_waist

右手でターゲットを掴んで動かすコード例です。腰の回転も使用します。

次のコマンドを実行します。

```sh
ros2 launch sciurus17_examples_py example.launch.py example:='pick_and_place_right_arm_waist'
```

[back to example list](#examples)

---

### pick_and_place_left_arm

左手でターゲットを掴んで動かすコード例です。

次のコマンドを実行します。

```sh
ros2 launch sciurus17_examples_py example.launch.py example:='pick_and_place_left_arm'
```

[back to example list](#examples)

---
26 changes: 26 additions & 0 deletions sciurus17_examples_py/config/sciurus17_moveit_py_examples.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
planning_scene_monitor_options:
name: "planning_scene_monitor"
robot_description: "robot_description"
joint_state_topic: "/joint_states"
attached_collision_object_topic: "/moveit_cpp/planning_scene_monitor"
publish_planning_scene_topic: "/moveit_cpp/publish_planning_scene"
monitored_planning_scene_topic: "/moveit_cpp/monitored_planning_scene"
wait_for_initial_state_timeout: 10.0

planning_pipelines:
pipeline_names: ["ompl"]

plan_request_params:
planning_attempts: 1
planning_pipeline: ompl
max_velocity_scaling_factor: 1.0
max_acceleration_scaling_factor: 1.0

ompl_rrtc_default: # Namespace for individual plan request
plan_request_params: # PlanRequestParameters similar to the ones that are used by the single pipeline planning of moveit_cpp
planning_attempts: 1 # Number of attempts the planning pipeline tries to solve a given motion planning problem
planning_pipeline: ompl # Name of the pipeline that is being used
planner_id: "RRTConnectkConfigDefault" # Name of the specific planner to be used by the pipeline
max_velocity_scaling_factor: 1.0 # Velocity scaling parameter for the trajectory generation algorithm that is called (if configured) after the path planning
max_acceleration_scaling_factor: 1.0 # Acceleration scaling parameter for the trajectory generation algorithm that is called (if configured) after the path planning
planning_time: 1.0 # Time budget for the motion plan request. If the planning problem cannot be solved within this time, an empty solution with error code is returned
76 changes: 76 additions & 0 deletions sciurus17_examples_py/launch/example.launch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Copyright 2024 RT Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import Node
from moveit_configs_utils import MoveItConfigsBuilder
from sciurus17_description.robot_description_loader import RobotDescriptionLoader


def generate_launch_description():

description_loader = RobotDescriptionLoader()
declare_loaded_description = DeclareLaunchArgument(
'loaded_description',
default_value=description_loader.load(),
description='Set robot_description text. \
It is recommended to use RobotDescriptionLoader() \
in sciurus17_description.')

Kuwamai marked this conversation as resolved.
Show resolved Hide resolved
moveit_config = (MoveItConfigsBuilder('sciurus17').planning_scene_monitor(
publish_robot_description=True,
publish_robot_description_semantic=True,
).moveit_cpp(file_path=get_package_share_directory('sciurus17_examples_py') +
'/config/sciurus17_moveit_py_examples.yaml').to_moveit_configs())

moveit_config.robot_description = {
'robot_description': LaunchConfiguration('loaded_description')
}

moveit_config.move_group_capabilities = {'capabilities': ''}

declare_example_name = DeclareLaunchArgument(
'example',
default_value='gripper_control',
description=('Set an example executable name: '
'[gripper_control, neck_control, waist_control, '
'pick_and_place_right_arm_waist, pick_and_place_left_arm]'))

declare_use_sim_time = DeclareLaunchArgument(
'use_sim_time', default_value='false',
description=('Set true when using the gazebo simulator.')
)

# 下記Issue対応のためここでパラメータを設定する
# https://github.com/moveit/moveit2/issues/2940#issuecomment-2401302214
config_dict = moveit_config.to_dict()
config_dict.update({'use_sim_time': LaunchConfiguration('use_sim_time')})

example_node = Node(
name=[LaunchConfiguration('example'), '_node'],
package='sciurus17_examples_py',
executable=LaunchConfiguration('example'),
output='screen',
parameters=[config_dict],
)

return LaunchDescription([
declare_loaded_description,
declare_use_sim_time,
declare_example_name,
example_node
])
25 changes: 25 additions & 0 deletions sciurus17_examples_py/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>sciurus17_examples_py</name>
<version>0.1.0</version>
Kuwamai marked this conversation as resolved.
Show resolved Hide resolved
<description>Python examples of Sciurus17 ROS package</description>
<maintainer email="[email protected]">RT Corporation</maintainer>
<license>Apache License 2.0</license>

Kuwamai marked this conversation as resolved.
Show resolved Hide resolved
<author email="[email protected]">chama1176</author>

<exec_depend>rclpy</exec_depend>
<exec_depend>std_msgs</exec_depend>
<exec_depend>moveit</exec_depend>
<exec_depend>moveit_py</exec_depend>

<test_depend>ament_copyright</test_depend>
<test_depend>ament_flake8</test_depend>
<test_depend>ament_pep257</test_depend>
<test_depend>python3-pytest</test_depend>

<export>
<build_type>ament_python</build_type>
</export>
</package>
Empty file.
Empty file.
132 changes: 132 additions & 0 deletions sciurus17_examples_py/sciurus17_examples_py/gripper_control.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
# Copyright 2024 RT Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import math


# moveit python library
from moveit.core.robot_state import RobotState
from moveit.planning import (
MoveItPy,
PlanRequestParameters,
)
# generic ros libraries
import rclpy
from rclpy.logging import get_logger

from sciurus17_examples_py.utils import plan_and_execute


def main(args=None):
rclpy.init(args=args)
logger = get_logger('moveit_py.gripper_control')

# instantiate MoveItPy instance and get planning component
sciurus17 = MoveItPy(node_name='gripper_control')
logger.info('MoveItPy instance created')

# 腕制御用 planning component
arm = sciurus17.get_planning_component('two_arm_group')
# 左グリッパ制御用 planning component
l_gripper = sciurus17.get_planning_component('l_gripper_group')
# 右グリッパ制御用 planning component
r_gripper = sciurus17.get_planning_component('r_gripper_group')

robot_model = sciurus17.get_robot_model()
Kuwamai marked this conversation as resolved.
Show resolved Hide resolved

plan_request_params = PlanRequestParameters(
sciurus17,
'ompl_rrtc_default',
)
gripper_plan_request_params = PlanRequestParameters(
sciurus17,
'ompl_rrtc_default',
)
# 動作速度の調整
plan_request_params.max_acceleration_scaling_factor = 0.1 # Set 0.0 ~ 1.0
plan_request_params.max_velocity_scaling_factor = 0.1 # Set 0.0 ~ 1.0
# 動作速度の調整
gripper_plan_request_params.max_acceleration_scaling_factor = 0.1 # Set 0.0 ~ 1.0
gripper_plan_request_params.max_velocity_scaling_factor = 0.1 # Set 0.0 ~ 1.0

# グリッパの開閉角
R_GRIPPER_CLOSE = math.radians(0.0)
R_GRIPPER_OPEN = math.radians(40.0)
L_GRIPPER_CLOSE = math.radians(0.0)
L_GRIPPER_OPEN = math.radians(-40.0)

# SRDFに定義されている'two_arm_init_pose'の姿勢にする
arm.set_start_state_to_current_state()
arm.set_goal_state(configuration_name='two_arm_init_pose')
plan_and_execute(
sciurus17,
arm,
logger,
single_plan_parameters=plan_request_params,
)

# 右グリッパ開閉
for _ in range(2):
r_gripper.set_start_state_to_current_state()
robot_state = RobotState(robot_model)
robot_state.set_joint_group_positions('r_gripper_group', [R_GRIPPER_OPEN])
r_gripper.set_goal_state(robot_state=robot_state)
plan_and_execute(
sciurus17,
r_gripper,
logger,
single_plan_parameters=gripper_plan_request_params,
)

r_gripper.set_start_state_to_current_state()
robot_state = RobotState(robot_model)
robot_state.set_joint_group_positions('r_gripper_group', [R_GRIPPER_CLOSE])
r_gripper.set_goal_state(robot_state=robot_state)
plan_and_execute(
sciurus17,
r_gripper,
logger,
single_plan_parameters=gripper_plan_request_params,
)

# 左グリッパ開閉
for _ in range(2):
l_gripper.set_start_state_to_current_state()
robot_state = RobotState(robot_model)
robot_state.set_joint_group_positions('l_gripper_group', [L_GRIPPER_OPEN])
l_gripper.set_goal_state(robot_state=robot_state)
plan_and_execute(
sciurus17,
l_gripper,
logger,
single_plan_parameters=gripper_plan_request_params,
)

l_gripper.set_start_state_to_current_state()
robot_state = RobotState(robot_model)
robot_state.set_joint_group_positions('l_gripper_group', [L_GRIPPER_CLOSE])
l_gripper.set_goal_state(robot_state=robot_state)
plan_and_execute(
sciurus17,
l_gripper,
logger,
single_plan_parameters=gripper_plan_request_params,
)

# Finish with error. Related Issue
# https://github.com/moveit/moveit2/issues/2693
rclpy.shutdown()


if __name__ == '__main__':
main()
Loading
Loading