Skip to content

Commit f7bd9ab

Browse files
committed
Initial commit
1 parent f7f7529 commit f7bd9ab

File tree

527 files changed

+45777
-4
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

527 files changed

+45777
-4
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.DS_Store
2+
.swp
3+
.idea
4+
.vscode/
5+
.vsconfig

Documentation/0_ros_setup.md

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Object Pose Estimation Tutorial: Part 0
2+
3+
This page provides steps on how to manually set up a catkin workspace for the Pose Estimation tutorial.
4+
5+
1. Navigate to the `object_pose_estimation/` directory of this downloaded repository. This directory will be used as the ROS catkin workspace.
6+
7+
2. Copy or download this directory to your ROS operating system if you are doing ROS operations in another machine, VM, or container.
8+
9+
3. If the following packages are not already installed on your ROS machine, run the following commands to install them:
10+
11+
```bash
12+
sudo apt-get update && sudo apt-get upgrade
13+
sudo apt-get install python3-pip ros-noetic-robot-state-publisher ros-noetic-moveit ros-noetic-rosbridge-suite ros-noetic-joy ros-noetic-ros-control ros-noetic-ros-controllers ros-noetic-tf* ros-noetic-gazebo-ros-pkgs ros-noetic-joint-state-publisher
14+
sudo pip3 install rospkg numpy jsonpickle scipy easydict torch==1.7.1+cu101 torchvision==0.8.2+cu101 torchaudio==0.7.2 -f https://download.pytorch.org/whl/torch_stable.html
15+
```
16+
17+
> Note: If you encounter errors installing Pytorch via the above `pip3` command, try the following instead:
18+
> ```bash
19+
> sudo pip3 install rospkg numpy jsonpickle scipy easydict torch==1.7.1 torchvision==0.8.2 torchaudio==0.7.2 -f https://download.pytorch.org/whl/torch_stable.html
20+
> ```
21+
22+
23+
Most of the ROS setup has been provided via the `ur3_moveit` package. This section will describe the provided files.
24+
25+
4. If you have not already built and sourced the ROS workspace since importing the new ROS packages, navigate to your ROS workplace, and run:
26+
27+
```bash
28+
catkin_make
29+
source devel/setup.bash
30+
```
31+
32+
Ensure there are no unexpected errors.
33+
34+
The ROS parameters will need to be set to your configuration in order to allow the server endpoint to fetch values for the TCP connection.
35+
36+
5. Navigate to your ROS workspace (e.g. `~/catkin_ws`). Assign the ROS IP in the `params.yaml` file as follows:
37+
38+
```bash
39+
echo "ROS_IP: $(hostname -I)" > src/ur3_moveit/config/params.yaml
40+
```
41+
42+
>Note: You can also manually assign this value by navigating to the `src/ur3_moveit/config/params.yaml` file and opening it for editing.
43+
>```yaml
44+
>ROS_IP: <your ROS IP>
45+
>```
46+
>e.g.
47+
>```yaml
48+
>ROS_IP: 10.0.0.250
49+
>```
50+
51+
> Note: Learn more about the server endpoint and ROS parameters [here](https://github.com/Unity-Technologies/Unity-Robotics-Hub/blob/main/tutorials/ros_unity_integration/server_endpoint.md).
52+
53+
This YAML file is a rosparam set from the launch files provided for this tutorial, which has been copied below for reference. Additionally, the `server_endpoint`, `pose estimation`, and `mover` nodes are launched from this file.
54+
55+
```xml
56+
<launch>
57+
<rosparam file="$(find ur3_moveit)/config/params.yaml" command="load"/>
58+
'<include file="$(find ur3_moveit)/launch/demo.launch" />
59+
<node name="server_endpoint" pkg="ur3_moveit" type="server_endpoint.py" args="--wait" output="screen" respawn="true" />
60+
<node name="pose_estimation" pkg="ur3_moveit" type="pose_estimation_script.py" args="--wait" output="screen"/>
61+
<node name="mover" pkg="ur3_moveit" type="mover.py" args="--wait" output="screen" respawn="true" respawn_delay="2.0"/>
62+
</launch>
63+
```
64+
65+
>Note: The launch files for this project are available in the package's launch directory, i.e. `src/ur3_moveit/launch/`.
66+
67+
The ROS workspace is now ready to accept commands! Return to [Part 4: Set up the Unity side](4_pick_and_place.md#step-3) to continue the tutorial.

Documentation/1_set_up_the_scene.md

+188
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
# Object Pose Estimation Tutorial: Part 1
2+
3+
In this first part of the tutorial, we will start by downloading and installing the Unity Editor. We will install our project's dependencies: the Perception, URDF, and TCP Connector packages. We will then use a set of provided prefabs to easily prepare a simulated environment containing a table, a cube, and a working robot arm.
4+
5+
6+
**Table of Contents**
7+
- [Requirements](#reqs)
8+
- [Create a New Project](#step-1)
9+
- [Download the Perception, the URDF and the TCP connector Packages](#step-2)
10+
- [Setup the Ground Truth Render Feature](#step-3)
11+
- [Setup the Scene](#step-4)
12+
13+
---
14+
15+
### <a name="reqs">Requirements</a>
16+
17+
To follow this tutorial you need to **clone** this repository even if you want to create your Unity project from scratch.
18+
19+
20+
> Note For Windows users: You need to have a software enabling you to run bash files. One option is to download [GIT](https://git-scm.com/downloads). During installation of GIT, add GIT Bash to windows context menu by selecting its option. After installation, right click in your folder, and select [GIT Bash Here](Images/0_GIT_installed.png).
21+
22+
1. Open a terminal and put yourself where you want to host the repository.
23+
```bash
24+
git clone https://github.com/Unity-Technologies/Unity-Robotics-Hub.git
25+
```
26+
27+
Then we need to be in the `Unity-Robotics-Hub/tutorials/object_pose_estimation` folder and generate the contents of the `universal_robot`, `moveit_msgs`, `ros_tcp_endpoint`, and the `robotiq` folders.
28+
```bash
29+
cd Unity-Robotics-Hub/tutorials/object_pose_estimation
30+
./submodule.sh
31+
```
32+
33+
2. [Install Unity `2020.2.*`.](install_unity.md)
34+
35+
36+
### <a name="step-1">Create a New Project</a>
37+
When you first run Unity, you will be asked to open an existing project, or create a new one.
38+
39+
1. Open Unity and create a new project using the **Universal Render Pipeline**. Name your new project _**Pose Estimation Tutorial**_, and specify a desired location as shown below.
40+
41+
<p align="center">
42+
<img src="Images/1_create_new_project.png" align="center" width=950/>
43+
</p>
44+
45+
### <a name="step-2">Download the Perception, the URDF and the TCP connector Packages</a>
46+
47+
Once your new project is created and loaded, you will be presented with the Unity Editor interface. From this point on, whenever we refer to the "editor", we mean the Unity Editor.
48+
49+
#### How to install packages
50+
We will need to download and install several packages. In general, packages can be installed in Unity with the following steps:
51+
52+
- From the top menu bar, open _**Window**_ -> _**Package Manager**_. As the name suggests, the _**Package Manager**_ is where you can download new packages, update or remove existing ones, and access a variety of information and additional actions for each package.
53+
54+
- Click on the _**+**_ sign at the top-left corner of the _**Package Manager**_ window and then choose the option _**Add package from git URL...**_.
55+
56+
- Enter the package address and click _**Add**_. It will take some time for the manager to download and import the package.
57+
58+
Installing the different packages may take some time (few minutes).
59+
60+
<p align="center">
61+
<img src="Gifs/1_package_imports.gif"/>
62+
</p>
63+
64+
65+
#### Install Dependencies
66+
Install the following packages with the provided git URLs:
67+
68+
1. [Perception package](https://github.com/Unity-Technologies/com.unity.perception) - `[email protected]`
69+
* This will help us collect training data for our machine learning model.
70+
71+
2. [URDF Importer package](https://github.com/Unity-Technologies/URDF-Importer) - `https://github.com/Unity-Technologies/URDF-Importer.git#v0.1.2`
72+
* This package will help us import a robot into our scene from a file in the [Unified Robot Description Format (URDF)](http://wiki.ros.org/urdf).
73+
74+
3. [TCP Connector package](https://github.com/Unity-Technologies/ROS-TCP-Connector) - `https://github.com/Unity-Technologies/ROS-TCP-Connector.git#v0.1.2`
75+
* This package will enable a connection between ROS and Unity.
76+
77+
>Note: If you encounter a Package Manager issue, check the [Troubleshooting Guide](troubleshooting.md) for potential solutions.
78+
79+
### <a name="step-3">Set up Ground Truth Render Feature</a>
80+
81+
The Hierarchy, Scene View, Game View, Play/Pause/Step toolbar, Inspector, Project, and Console windows of the Unity Editor have been highlighted below for reference, based on the default layout. Custom Unity Editor layouts may vary slightly. A top menu bar option is available to re-open any of these windows: Window > General.
82+
83+
<p align="center">
84+
<img src="Images/1_scene_overview.png"/>
85+
</p>
86+
87+
88+
The perception packages relies on a "ground truth render feature" to save out labeled images as training data. You don't need to worry about the details, but follow the steps below to add this component:
89+
90+
1. The _**Project**_ tab contains a search bar; use it to find the file named `ForwardRenderer`, and click on the file named `ForwardRenderer.asset` as shown below:
91+
92+
<p align="center">
93+
<img src="Images/1_forward_renderer.png"/>
94+
</p>
95+
96+
2. Click on the found file to select it. Then, from the _**Inspector**_ tab of the editor, click on the _**Add Renderer Feature**_ button, and select _**Ground Truth Renderer Feature**_ from the dropdown menu:
97+
98+
<p align="center">
99+
<img src="Images/1_forward_renderer_inspector.png" width=430 height=350/>
100+
</p>
101+
102+
103+
### <a name="step-4">Set up the Scene</a>
104+
105+
#### The Scene
106+
Simply put in Unity, a `Scene` contains any object that exists in the world. This world can be a game, or in this case, a data-collection-oriented simulation. Every new project contains a Scene named SampleScene, which is automatically opened when the project is created. This Scene comes with several objects and settings that we do not need, so let's create a new one.
107+
108+
1. In the _**Project**_ tab, right-click on the `Assets > Scenes` folder and click _**Create -> Scene**_. Name this new Scene `TutorialPoseEstimation` and double-click on it to open it.
109+
110+
The _**Hierarchy**_ tab of the editor displays all the Scenes currently loaded, and all the objects currently present in each loaded Scene, as shown below:
111+
<p align="center">
112+
<img src="Images/1_hierarchy.png" width=500 height=200/>
113+
</p>
114+
115+
As seen above, the new Scene already contains a camera (`Main Camera`) and a light (`Directional Light`). We will now modify the camera's field of view and position to prepare it for the tutorial.
116+
117+
2. Still in the _**Inspector**_ tab of the `Main Camera`, modify the camera's `Position` and `Rotation` to match the values shown below. This orients the camera so that it will have a good view of the objects we are about to add to the scene.
118+
119+
<p align="center">
120+
<img src="Images/1_camera_settings.png" height=117 width=500/>
121+
</p>
122+
123+
3. Click on `Directional Light` and in the _**Inspector**_ tab, modify the light's `Position` and `Rotation` to match the screenshot below.
124+
125+
<p align="center">
126+
<img src="Images/1_directional_light.png" height=217 width=500/>
127+
</p>
128+
129+
#### Adding Tutorial Files
130+
Now it is time to add some more objects to our scene. Before doing so, we need to import some folders containing the required assets.
131+
132+
4. Download [TutorialAssets.zip](https://github.com/Unity-Technologies/Unity-Robotics-Hub/releases/download/Pose-Estimation/TutorialAssets.zip), and unzip it. It should contain the following subfolders: `Materials`, `Prefabs`, `RosMessages`, `Scripts`, `URDFs`.
133+
134+
5. Drag and Drop the `TutorialAssets` folder onto the `Assets` folder in the _**Project**_ tab.
135+
136+
Your `Assets` folder should like this:
137+
138+
<p align="center">
139+
<img src="Images/1_assets_preview.png"/>
140+
</p>
141+
142+
#### Using Prefabs
143+
Unity’s [Prefab](https://docs.unity3d.com/2020.2/Documentation/Manual/Prefabs.html) system allows you to create, configure, and store a **GameObject** complete with all its components, property values, and child **GameObjects** as a reusable **Asset**. It is a convenient way to store complex objects.
144+
145+
A prefab is just a file, and you can easily create an instance of the object in the scene from a prefab by dragging it into the _**Hierarchy panel**_.
146+
147+
For your convenience, we have provided prefabs for most of the components of the scene (the cube, goal, table, and floor).
148+
149+
6. In the _**Project**_ tab, go to `Assets > TutorialAssets > Prefabs > Part1` and drag and drop the `Cube` prefab inside the _**Hierarchy panel**_.
150+
151+
7. Repeat the action with the `Goal`, `Table` and the `Floor`.
152+
153+
154+
<p align="center">
155+
<img src="Gifs/1_import_prefabs.gif"/>
156+
</p>
157+
158+
>Note: If you encounter an issue with the imported prefab materials, check the [Troubleshooting Guide](troubleshooting.md) for potential solutions.
159+
160+
161+
#### Importing the Robot
162+
Finally we will add the robot and the URDF files in order to import the UR3 Robot.
163+
164+
8. In the _**Project**_ tab, go to `Assets > TutorialAssets > URDFs > ur3_with_gripper` and right click on the `ur3_with_gripper.urdf` file and select `Import Robot From Selected URDF file`. A window will pop up, keep the default **Y Axis** type in the Import menu and the **Mesh Decomposer** to `VHACD`. Then, click Import URDF. These set of actions are showed in the following video.
165+
166+
>Note Unity uses a left-handed coordinate system in which the y-axis points up. However, many robotics packages use a right-handed coordinate system in which the z-axis or x-axis points up. For this reason, it is important to pay attention to the coordinate system when importing URDF files or interfacing with other robotics software.
167+
168+
>Note: VHACD algorithm produces higher quality convex hull for collision detection than the default algorithm.
169+
170+
<p align="center">
171+
<img src="Gifs/1_URDF_importer.gif" width=800 height=548/>
172+
</p>
173+
174+
>Note: If you encounter an issue with importing the robot, check the [Troubleshooting Guide](troubleshooting.md) for potential solutions.
175+
176+
#### Setting up the Robot
177+
178+
9. Select the `ur3_with_gripper` GameObject and in the _**Inspector**_ view, go to the `Controller` script and set the `Stiffness` to **10000**, the `Damping` to **1000** and the `Force Limit` to **1000**. These are physics properties that control how the robot moves.
179+
180+
10. In the _**Hierarchy**_ tab, select the `ur3_with_gripper` GameObject and click on the arrow on the left, then click on the arrow on the left of `world`, then on `base_link`. In the `Articulation Body` component, toggle on `Immovable` for the `base link`. This will fix the robot base to its current position.
181+
182+
<p align="center">
183+
<img src="Gifs/1_robot_settings.gif" width=800 height=465/>
184+
</p>
185+
186+
187+
### Proceed to [Part 2](2_set_up_the_data_collection_scene.md).
188+

0 commit comments

Comments
 (0)