OpenRRのサンプルを動かす

### はじめに
OpenRRはRustでロボットを操作するためのフレームワークです。
このフレームワークを使用すると例えば、Rustのコマンドから多軸ロボットの軌道計画を行うことができます。
そしてこの軌道をRustのシミュレーターやROSなどに出力することができます。
今回このOpenRRの使い方を学ぶためサンプルの実行方法をまとめました。

# 環境
使用した環境です。

- ubuntu 18.04
- ROS melodic
- OpenRR v0.0.5

# 準備
1. OpenRRの環境構築:https://qiita.com/OTL/items/3df938f61a4520c10b70

2. 設定ファイル等取得のため[OpenRR](https://github.com/openrr/openrr.git)をホームディレクトリにクローン

```
cd ~/
git clone https://github.com/openrr/openrr.git
```

# サンプルの実行

次にサンプルを実行します。

## サンプル 1 

### 動作

1.urdfのシミュレーターの立ち上げ

```
cd openrr
urdf-viz ./openrr-planner/sample.urdf
```
2.コマンドの送信

```
openrr_apps_robot_command \
  --config-path=./openrr-apps/config/sample_robot_client_config_for_urdf_viz.toml \
  load_commands ./openrr-apps/command/sample_cmd_urdf_viz.txt
```

# 詳細

1.toml形式の方はロボットの設定を記載します。ROS対応をする場合にもこのファイルに設定を記載します。

```toml:./openrr-apps/config/sample_robot_client_config_for_urdf_viz.toml
[[urdf_viz_clients_configs]]
name = "arm"
joint_names = ["l_shoulder_yaw", "l_shoulder_pitch", "l_shoulder_roll", "l_elbow_pitch", "l_wrist_yaw", "l_wrist_pitch"]

[openrr_clients_config]
urdf_path = "../../openrr-planner/sample.urdf"
self_collision_check_pairs = ["l_shoulder_yaw:l_gripper_linear1"]

[[openrr_clients_config.collision_check_clients_configs]]
name = "arm_collision_checked"
client_name = "arm"

[[openrr_clients_config.ik_clients_configs]]
name = "arm_ik"
client_name = "arm_collision_checked"
solver_name = "arm_ik_solver"

[[openrr_clients_config.joints_poses]]
pose_name = "zero"
client_name = "arm_collision_checked"
positions = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]

[openrr_clients_config.ik_solvers_configs.arm_ik_solver]
ik_target = "l_tool_fixed"
```
2.txtファイルの方には送信するコマンドを記載します。

```txt:./openrr-apps/command/sample_cmd_urdf_viz.txt
openrr_apps_robot_command list

openrr_apps_robot_command send_joints_pose arm_collision_checked zero

openrr_apps_robot_command send_joints arm -j 0=1.2 1=-1.2 2=0.0 3=1.2 4=0.0 5=0.0
openrr_apps_robot_command send_joints arm -j 0=0.0 1=0.0 2=0.0 3=0.0 4=0.0 5=0.0

openrr_apps_robot_command send_joints arm_collision_checked -j 0=1.2 1=-1.2 2=0.0 3=1.2 4=0.0 5=0.0
openrr_apps_robot_command send_joints arm_collision_checked -j 0=0.0 1=0.0 2=0.0 3=0.0 4=0.0 5=0.0

openrr_apps_robot_command send_joints arm_ik -j 0=1.2 1=-1.2 2=0.0 3=1.2 4=0.0 5=0.0
openrr_apps_robot_command send_joints arm_ik -j 0=0.0 1=0.0 2=0.0 3=0.0 4=0.0 5=0.0

openrr_apps_robot_command get_state arm
openrr_apps_robot_command get_state arm_collision_checked
openrr_apps_robot_command get_state arm_ik

openrr_apps_robot_command send_joints arm_ik -j 0=1.2 1=-1.2 2=0.0 3=1.2 4=0.0 5=0.0
openrr_apps_robot_command get_state arm_ik
openrr_apps_robot_command move_ik arm_ik --x=0.7 --y=0.1 --z=0.5 --roll==0.0 --pitch=0.0 --yaw=-1.1
openrr_apps_robot_command get_state arm_ik
openrr_apps_robot_command move_ik arm_ik --x=0.9 --y=0.4 --z=0.5 --roll==0.0 --pitch=0.0 --yaw=0.0
openrr_apps_robot_command get_state arm_ik

openrr_apps_robot_command get_navigation_current_pose
openrr_apps_robot_command send_base_velocity 1.0 2.0 1.57 -d 3.0
openrr_apps_robot_command send_base_velocity 0.0 0.0 0.0 -d 3.0
openrr_apps_robot_command send_navigation_goal 0.0 0.0 0.0

openrr_apps_robot_command speak "This is sample robot"

openrr_apps_robot_command execute_command -- date
```

### 結果
<iframe width="560" height="315" src="https://www.youtube.com/embed/B9qARPg3LSY" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>


## サンプル 2
### 準備

次はUR10をRUSTシミュレーター上で動かします。

1.まずuniversal_robotのパッケージをインストールします
https://github.com/ros-industrial/universal_robot

2.またUR10で使用する設定ファイル内の、urdfファイルへのパスは次のように設定されていて、これに合うようにホームディレクトリにURのリポジトリをクローンまたはパスの変更を行います。[設定ファイル](https://github.com/openrr/openrr/blob/main/openrr-apps/config/ur10_robot_client_config_for_urdf_viz.toml)

![Screenshot from 2021-04-07 05-15-52.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/589906/fac5086d-88e3-4938-76a2-37b5b4b0f503.png)



```txt:ホームディレクトリへのクローン
cd ~/
git clone https://github.com/ros-industrial/universal_robot.git
```

### 動作

```
cd ~/openrr
urdf-viz $(rospack find ur_description)/urdf/ur10_robot.urdf.xacro &
openrr_apps_robot_command   --config-path=./openrr-apps/config/ur10_robot_client_config_for_urdf_viz.toml   load_commands ./openrr-apps/command/ur10_cmd_urdf_viz.txt
```

### 詳細

```toml:./openrr-apps/config/ur10_robot_client_config_for_urdf_viz.toml
[[urdf_viz_clients_configs]]
name = "arm"
joint_names = ["shoulder_pan_joint", "shoulder_lift_joint", "elbow_joint", "wrist_1_joint", "wrist_2_joint", "wrist_3_joint"]

[openrr_clients_config]
urdf_path = "../../../universal_robot/ur_description/urdf/ur10_robot.urdf.xacro"
self_collision_check_pairs = ["shoulder_pan_joint:elbow_joint"]

[[openrr_clients_config.collision_check_clients_configs]]
name = "arm_collision_checked"
client_name = "arm"

[[openrr_clients_config.ik_clients_configs]]
name = "arm_ik"
client_name = "arm_collision_checked"
solver_name = "arm_ik_solver"

[openrr_clients_config.ik_solvers_configs.arm_ik_solver]
ik_target = "ee_fixed_joint"

[[openrr_clients_config.joints_poses]]
pose_name = "zero"
client_name = "arm_collision_checked"
positions = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]

[[openrr_clients_config.joints_poses]]
pose_name = "ready"
client_name = "arm_collision_checked"
positions = [0.0, -0.7, 1.4, -0.7, 1.57, -3.14]
```

```txt:./openrr-apps/command/ur10_cmd_urdf_viz.txt
openrr_apps_robot_command list

openrr_apps_robot_command send_joints_pose arm_collision_checked ready
openrr_apps_robot_command send_joints_pose arm_collision_checked zero

openrr_apps_robot_command send_joints arm -j 0=0.0 1=-0.7 2=1.4 3=-2.27 4=0.0 5=0.0
openrr_apps_robot_command send_joints arm -j 0=0.0 1=0.0  2=0.0 3=0.0   4=0.0 5=0.0

openrr_apps_robot_command send_joints arm_collision_checked -j 0=0.0 1=-0.7 2=1.4 3=-2.27 4=0.0 5=0.0
openrr_apps_robot_command send_joints arm_collision_checked -j 0=0.0 1=0.0  2=0.0 3=0.0   4=0.0 5=0.0

openrr_apps_robot_command send_joints arm_ik -j 0=0.0 1=-0.7 2=1.4 3=-2.27 4=0.0 5=0.0
openrr_apps_robot_command send_joints arm_ik -j 0=0.0 1=0.0  2=0.0 3=0.0   4=0.0 5=0.0

openrr_apps_robot_command get_state arm
openrr_apps_robot_command get_state arm_collision_checked
openrr_apps_robot_command get_state arm_ik

openrr_apps_robot_command send_joints arm_ik -j 0=0.0 1=-0.7 2=1.4 3=-0.3 4=1.57 5=-3.14
openrr_apps_robot_command get_state arm_ik
openrr_apps_robot_command move_ik arm_ik --x=0.8 --y=0.1
openrr_apps_robot_command get_state arm_ik
openrr_apps_robot_command move_ik arm_ik --x=1.0 --y=0.25
openrr_apps_robot_command get_state arm_ik

openrr_apps_robot_command get_navigation_current_pose
openrr_apps_robot_command send_base_velocity 1.0 2.0 1.57 -d 3.0
openrr_apps_robot_command send_base_velocity 0.0 0.0 0.0 -d 3.0
openrr_apps_robot_command send_navigation_goal 0.0 0.0 0.0

openrr_apps_robot_command speak "This is U R 10"

openrr_apps_robot_command execute_command -- date
openrr_apps_robot_command execute_command -- ls -a

```


### 結果
<iframe width="560" height="315" src="https://www.youtube.com/embed/k2y6UchAyAU" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
# 参考

[openrr/openrr-appsのREADME.md](https://github.com/openrr/openrr/tree/main/openrr-apps)