Skip to content

Commit e7b522a

Browse files
added docs for adding robots
1 parent 712a5bf commit e7b522a

File tree

3 files changed

+62
-14
lines changed

3 files changed

+62
-14
lines changed

Assets/Components/Robots/README.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,38 @@
33
# Robots
44
![Robots](/docs/images/robots.jpg)
55

6-
This folder contains the actual robot assets for Franka Panda arm, Dynarm, Anymal, ALMA, and Tytan. It also has the Robot manager script which allows for swapping out different robot assets as well as storing the settings in the player prefs.
6+
This folder contains the actual robot assets for Franka Panda arm, Dynarm, Anymal, and ALMA. It also has the Robot manager script which allows for swapping out different robot assets as well as storing the settings in the player prefs.
7+
8+
9+
## Adding New Robots
10+
11+
To add a new robot to the system you can either import an existing URDF or create a new model from scratch. The current import method is a bit clunky with complex robots that refence multiple packages. If you have a better solution, please let us know!
12+
13+
1. **Convert Xacro to URDF**: Use the [Xacro](https://wiki.ros.org/xacro) tool to convert your Xacro file to a single URDF file. Usually this can be done with the command:
14+
```bash
15+
rosrun xacro xacro --inorder -o <your_robot>.urdf <your_robot>.xacro
16+
```
17+
18+
2. **Add the URDF Importer Package**: Add the [Unity URDF Importer](https://github.com/Unity-Technologies/URDF-Importer) according to the instructions in the repository. This package sometimes causes issues with building to device so if it is no longer needed for your project you can remove it.
19+
20+
3. **Copy Over Files**: The actual importing of the meshes can be tricky as ROS package lookups do not work in Unity. Instead it is recommended to make a working folder where you can copy any neccessary description/urdf packages along with the URDF file. An example of this would be
21+
```
22+
Assets/temp_urdf
23+
├── <your_robot>.urdf
24+
├── <your_robot>_description_package
25+
│ ├── meshes
26+
│ │ ├── <your_robot>.dae
27+
│ │ ├── <your_robot>_link.dae
28+
```
29+
30+
4. **Import the URDF**: Once the files are copied over you can right click on the URDF file and select `Import Robot from Selected URDF File`. This will spawn a new Import Settings window where you then select `Import URDF`. Any missing packages/meshes will be reported in a popup window and can be copied into your working folder. It will likely take a few tries to get all the files in the right place, with the Import Settings window displaying how many links have been loaded at the bottom.
31+
32+
5. **Remove Simulation Components**: If the import is successful it will be added to the scene with the name of the robot. This robot is meant to work with Unity's ROS simulation system and includes a lot of components we do not need for teleoperation. To remove these add the [`URDF Converter`](/home/maximum/unity/unity_ros_teleoperation/Assets/Components/Robots/Scripts/URDFConverter.cs) component to the robot GameObject and press `Convert`. This will remove extra components and GameObjects as well as set the TF Attachment for each link to track the TF tree based on GameObject names. This means the root node of the robot's tf tree will be set to the name of the robot GameObject.
33+
34+
6 . **Add the Robot Manager**: Once the robot been cleaned up, drag the GameObject into the Robots > Prefabs folder to create a robot prefab. The robot prefab in the scene can now be deleted. This prefab can then be added to the `Model Manager` in palmmenu > MenuCanvas > Settings. Here the robot can be added to the Robots array with a custom name, and the prefab can be placed in the `Model Root` field. This will automatically add it to the drop down of robots.
35+
36+
![Model Manager](/docs/images/model_manager.png)
37+
38+
7. **Cleanup**: Lastly, since the prefab now links the UUIDs of the meshes instead of the paths, they can be moved to a folder in the Robots > Meshes. To select all the meshes in the prefab, right click on the prefab and select `Select Dependancies`. This will show all the components referenced by the prefab, you then need to select only the meshes and materials that are unique to the robot and drag these into the meshes folder. You should now be able to delete the working folder and have a cleaned robot prefab.
39+
40+
8. **[Optional] Clean the Meshes**: If your meshes are too high resolution you may have major performance hits when running on headset. The URDF Converter script has a button `Count` which will print out details on how many vertices and triangles are in the meshes. It's recommended to keep the meshes under 300k vertices and 200k triangles. After step 7, you can open the meshes in your new Robots > Meshes folder and edit the meshes in your tool of choice. The recommended tool is [Blender](https://www.blender.org/) which is free and open source. You can use the `Decimate` modifier to reduce the number of vertices in the mesh, or `Limited Dissolve` in the vertex delete menu. These are only starting suggestions, there are numerous online tools and tutorials on simplifiying your meshes.

Assets/Components/Robots/Scripts/URDFConverter.cs

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@ public override void OnInspectorGUI()
1313
{
1414
DrawDefaultInspector();
1515

16-
string res = "0";
17-
GUILayout.Label("Count: " + res);
1816
URDFConverter converter = (URDFConverter)target;
17+
string res = converter.count.ToString();
18+
string meshData = converter.meshData;
19+
GUILayout.Label("Removal Iterations: " + res);
20+
GUILayout.Label(meshData);
21+
1922
if(GUILayout.Button("Convert"))
2023
{
2124
Debug.Log("Converting...");
@@ -24,7 +27,7 @@ public override void OnInspectorGUI()
2427
if(GUILayout.Button("Count"))
2528
{
2629
Debug.Log("Counting...");
27-
res = converter.Count();
30+
converter.Count();
2831
}
2932

3033
}
@@ -33,13 +36,23 @@ public override void OnInspectorGUI()
3336

3437
public class URDFConverter : MonoBehaviour
3538
{
36-
public void Convert(){
39+
[HideInInspector]
40+
public int count = 0;
41+
[HideInInspector]
42+
public string meshData = "Run Count() to get mesh data";
3743

38-
int count = Convert("", transform);
39-
Debug.Log("Removed " + count + " missing scripts");
44+
public void Convert(){
45+
// Run convert until there is nothing lest to remove or 100 times
46+
int removed = 1;
47+
int i = 0;
48+
for(i=0; i < 100 && removed > 0; i++){
49+
removed = Convert("", transform);
50+
Debug.Log("Removed " + removed + " extra objects");
51+
}
52+
count = i-1;
4053
}
4154

42-
public string Count(){
55+
public void Count(){
4356
// counts the tris and verts in this object and all children
4457
int tris = 0;
4558
int verts = 0;
@@ -53,18 +66,19 @@ public string Count(){
5366
path = mf.transform.name;
5467
}
5568
}
56-
string res = "Verts: " + verts + " Tris: " + tris + " Max Tris: " + maxTris + " Path: " + path;
69+
string res = "Verts: " + verts.ToString("N0") + " Tris: " + tris.ToString("N0") + " Max Tris: " + maxTris.ToString("N0") + " Path: " + path;
5770
Debug.Log(res);
58-
return res;
71+
72+
meshData = res;
5973
}
6074

6175

6276
int Convert(string path, Transform o)
6377
{
64-
int count = 1;
78+
count = 0;
6579
if(o.name == "Collisions" || o.name == "Plugins"){
6680
DestroyImmediate(o.gameObject);
67-
return 0;
81+
return 1;
6882
}
6983
else if(!(o.name == "Visuals" || o.name == "unnamed"))
7084
{
@@ -77,7 +91,7 @@ int Convert(string path, Transform o)
7791
t.SetParent(o.parent);
7892
}
7993
DestroyImmediate(o.gameObject);
80-
return 0;
94+
return 1;
8195
}
8296

8397
// if mesh in name return
@@ -89,7 +103,7 @@ int Convert(string path, Transform o)
89103
DestroyImmediate(c);
90104
}
91105
}
92-
return 0;
106+
return 1;
93107
}
94108

95109

docs/images/model_manager.png

209 KB
Loading

0 commit comments

Comments
 (0)