Skip to content

Commit 8989199

Browse files
Autumn60Deric-W
andauthored
feat: packaging (#1)
* remove scripts for creating an asset package * replace asset with package This allows better reuse, samples and tests. Furthermore, the packaging of `ros2-for-unity.xml` is now being done by Unity as well as setting up the path and doing integrity checks. * update README * add samples The old examples where moved into the new ones. * add missing .meta files * rename Scripts to Runtime It seems that this is closer to the recommended layout * rename pkg Signed-off-by: Autumn60 <harada.akiro@gmail.com> --------- Signed-off-by: Autumn60 <harada.akiro@gmail.com> Co-authored-by: Eric Wolf <ewolf@advitec.de>
1 parent 096e46c commit 8989199

File tree

75 files changed

+2102
-1491
lines changed

Some content is hidden

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

75 files changed

+2102
-1491
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ log
33
build
44
.idea
55
src/ros2cs
6-
**/metadata*.xml
76
src/Ros2ForUnity/Plugins
87
!src/Ros2ForUnity/Plugins/.gitkeep
8+
src/Ros2ForUnity/Resources/ros2-for-unity.xml

README-UBUNTU.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,7 @@ Start with installation of dependencies. Make sure to complete each step of `ros
4040
./build.sh
4141
```
4242
* You can add `--clean-install` flag to make sure your installation directory is cleaned before deploying.
43-
* Unity Asset is ready to import into your Unity project. You can find it in `install/asset/` directory.
44-
* (optionally) To create `.unitypackage` in `install/unity_package`
45-
```bash
46-
create_unity_package.sh -u <your-path-to-unity-editor-executable>
47-
```
48-
> *NOTE* Unity license is required.
43+
* Unity package is ready to import into your Unity project. You can find it in `install/package/` directory.
4944
5045
## OS-Specific usage remarks
5146

README-WINDOWS.md

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,7 @@ It is necessary to complete all the steps for `ros2cs` [Prerequisites](https://g
4242
./build.ps1
4343
```
4444
* You can build with `-clean_install` to make sure your installation directory is cleaned before deploying.
45-
* Unity Asset is ready to import into your Unity project. You can find it in `install/asset/` directory.
46-
* (optionally) To create `.unitypackage` in `install/unity_package`
47-
```powershell
48-
create_unity_package.ps1
49-
```
50-
> *NOTE* Please provide path to your Unity executable when prompted. Unity license is required. In case your Unity license has expired, the `create_unity_package.ps1` won't throw any errors but `Ros2ForUnity.unitypackage` won't be generated too.
45+
* Unity package is ready to import into your Unity project. You can find it in `install/package/` directory.
5146
5247
## Build troubleshooting
5348
@@ -85,9 +80,7 @@ pip install numpy
8580

8681
## OS-Specific usage remarks
8782

88-
> If the Asset is built with `-standalone` flag (the default), then nothing extra needs to be done.
83+
> If the package is built with `-standalone` flag (the default), then nothing extra needs to be done.
8984
Otherwise, you have to source your ros distribution before launching either Unity3D Editor or Application.
9085

91-
> Note that after you build the Asset, you can use it on a machine that has no ros2 installation (if built with `-standalone`).
92-
93-
> You can simply copy over the `Ros2ForUnity` subdirectory to update your Asset.
86+
> Note that after you build the package, you can use it on a machine that has no ros2 installation (if built with `-standalone`).

README.md

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Advantages of this module include:
1313
- The module supplies abstractions and tools to use in your Unity project, including transformations, sensor interface, a clock, spinning loop wrapped in a MonoBehavior, handling initialization and shutdown.
1414
- Supports all standard ROS2 messages.
1515
- Custom messages are generated automatically with build, using standard ROS2 way. It is straightforward to generate and use them without having to define `.cs` equivalents by hand.
16-
- The module is wrapped as a Unity asset.
16+
- The module is wrapped as a Unity package.
1717

1818
## Platforms
1919

@@ -49,7 +49,7 @@ You can download pre-built [releases](https://github.com/RobotecAI/ros2-for-unit
4949
## Building
5050

5151
> **Note:** The project will pull `ros2cs` into the workspace, which also functions independently as it is a more general project aimed at any `C# / .Net` environment.
52-
It has its own README and scripting, but for building the Unity Asset, please use instructions and scripting in this document instead, unless you also wish to run tests or examples for `ros2cs`.
52+
It has its own README and scripting, but for building the Unity package, please use instructions and scripting in this document instead, unless you also wish to run tests or examples for `ros2cs`.
5353

5454
Please see OS-specific instructions:
5555
- [Instructions for Ubuntu](README-UBUNTU.md)
@@ -64,16 +64,18 @@ Custom messages can be included in the build by either:
6464
## Installation
6565

6666
1. Perform building steps described in the OS-specific readme or download pre-built Unity package. Do not source `ros2-for-unity` nor `ros2cs` project into ROS2 workspace.
67-
1. Open or create Unity project.
68-
1. Import asset into project:
69-
1. copy `install/asset/Ros2ForUnity` into your project `Assets` folder, or
70-
1. if you have deployed an `.unitypackage` - import it in Unity Editor by selecting `Import Package``Custom Package`
67+
2. Open or create Unity project
68+
3. Import `install/package/Ros2ForUnity` into your project with the package manager
69+
70+
**Before uploading the package into a registry you have to import it once from disk to generate .meta files for the native libraries!**
7171

7272
## Usage
7373

7474
**Prerequisites**
7575

76-
* If your build was prepared with `--standalone` flag then you are fine, and all you have to do is run the editor
76+
* When running in edit mode call `Setup.SetupPath()` to prevent the native libraries from failing to load.
77+
78+
* If your build was prepared with `--standalone` flag then you are fine, and all you have to do is calling `Setup.SetupPath()` when necessary
7779

7880
otherwise
7981

@@ -82,20 +84,20 @@ otherwise
8284
**Initializing Ros2ForUnity**
8385

8486
1. Initialize `Ros2ForUnity` by creating a "hook" object which will be your wrapper around ROS2. You have two options:
85-
1. `ROS2UnityComponent` based on `MonoBehaviour` which must be attached to a `GameObject` somewhere in the scene, then:
87+
- `ROS2UnityComponent` based on `MonoBehaviour` which must be attached to a `GameObject` somewhere in the scene, then:
8688
```c#
8789
using ROS2;
8890
...
8991
// Example method of getting component, if ROS2UnityComponent lives in different GameObject, just use different get component methods.
9092
ROS2UnityComponent ros2Unity = GetComponent<ROS2UnityComponent>();
9193
```
92-
1. or `ROS2UnityCore` which is a standard class that can be created anywhere
94+
- `ROS2UnityCore` which is a standard class that can be created anywhere
9395
```c#
9496
using ROS2;
9597
...
9698
ROS2UnityCore ros2Unity = new ROS2UnityCore();
9799
```
98-
1. Create a node. You must first check if `Ros2ForUnity` is initialized correctly:
100+
2. Create a node. You must first check if `Ros2ForUnity` is initialized correctly:
99101
```c#
100102
private ROS2Node ros2Node;
101103
...
@@ -178,20 +180,7 @@ otherwise
178180
```
179181
### Examples
180182

181-
1. Create a top-level object containing `ROS2UnityComponent.cs`. This is the central `Monobehavior` for `Ros2ForUnity` that manages all the nodes. Refer to class documentation for details.
182-
> **Note:** Each example script looks for `ROS2UnityComponent` in its own game object. However, this is not a requirement, just example implementation.
183-
184-
**Topics**
185-
1. Add `ROS2TalkerExample.cs` script to the very same game object.
186-
1. Add `ROS2ListenerExample.cs` script to the very same game object.
187-
188-
Once you start the project in Unity, you should be able to see two nodes talking with each other in Unity Editor's console or use `ros2 node list` and `ros2 topic echo /chatter` to verify ros2 communication.
189-
190-
**Services**
191-
1. Add `ROS2ServiceExample.cs` script to the very same game object.
192-
1. Add `ROS2ClientExample.cs` script to the very same game object.
193-
194-
Once you start the project in Unity, you should be able to see client node calling an example service.
183+
More complete examples are included in the Unity package.
195184

196185
## Acknowledgements
197186

build.ps1

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
Makes a clean installation. Removes install dir before deploying
1313
#>
1414
Param (
15-
[Parameter(Mandatory=$false)][switch]$with_tests=$false,
16-
[Parameter(Mandatory=$false)][switch]$standalone=$false,
17-
[Parameter(Mandatory=$false)][switch]$clean_install=$false
15+
[Parameter(Mandatory = $false)][switch]$with_tests = $false,
16+
[Parameter(Mandatory = $false)][switch]$standalone = $false,
17+
[Parameter(Mandatory = $false)][switch]$clean_install = $false
1818
)
1919

2020
$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition
2121

22-
if(-Not (Test-Path -Path "$scriptPath\src\ros2cs")) {
22+
if (-Not (Test-Path -Path "$scriptPath\src\ros2cs")) {
2323
Write-Host "Pull repositories with 'pull_repositories.ps1' first." -ForegroundColor Red
2424
exit 1
2525
}
@@ -30,31 +30,32 @@ $options = @{
3030
standalone = $standalone
3131
}
3232

33-
if($clean_install) {
33+
if ($clean_install) {
3434
Write-Host "Cleaning install directory..." -ForegroundColor White
3535
Remove-Item -Path "$scriptPath\install" -Force -Recurse -ErrorAction Ignore
3636
}
3737

38-
if($standalone) {
39-
& "python" $SCRIPTPATH\src\scripts\metadata_generator.py --standalone
40-
} else {
41-
& "python" $SCRIPTPATH\src\scripts\metadata_generator.py
38+
if ($standalone) {
39+
& "python" $SCRIPTPATH\src\scripts\metadata_generator.py --standalone
40+
}
41+
else {
42+
& "python" $SCRIPTPATH\src\scripts\metadata_generator.py
43+
}
44+
if ($LASTEXITCODE -ne 0) {
45+
Write-Host "Generating the Metadata failed!" -ForegroundColor Red
46+
exit 1
4247
}
4348

4449
& "$scriptPath\src\ros2cs\build.ps1" @options
45-
if($?) {
46-
md -Force $scriptPath\install\asset | Out-Null
47-
Copy-Item -Path $scriptPath\src\Ros2ForUnity -Destination $scriptPath\install\asset\ -Recurse -Force
50+
if ($?) {
51+
mkdir -Force $scriptPath\install\package | Out-Null
52+
Copy-Item -Path $scriptPath\src\Ros2ForUnity -Destination $scriptPath\install\package\ -Recurse -Force
4853

49-
$plugin_path=Join-Path -Path $scriptPath -ChildPath "\install\asset\Ros2ForUnity\Plugins\"
54+
$plugin_path = Join-Path -Path $scriptPath -ChildPath "\install\package\Ros2ForUnity\Plugins\"
5055
Write-Host "Deploying build to $plugin_path" -ForegroundColor Green
5156
& "$scriptPath\deploy_unity_plugins.ps1" $plugin_path
52-
53-
Copy-Item -Path $scriptPath\src\Ros2ForUnity\metadata_ros2cs.xml -Destination $scriptPath\install\asset\Ros2ForUnity\Plugins\Windows\x86_64\
54-
Copy-Item -Path $scriptPath\src\Ros2ForUnity\metadata_ros2cs.xml -Destination $scriptPath\install\asset\Ros2ForUnity\Plugins\
55-
} else {
57+
}
58+
else {
5659
Write-Host "Ros2cs build failed!" -ForegroundColor Red
5760
exit 1
5861
}
59-
60-

build.sh

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#!/bin/bash
2-
SCRIPT=$(readlink -f $0)
3-
SCRIPTPATH=`dirname $SCRIPT`
1+
#!/bin/sh -e
2+
SCRIPT=$(readlink -f "$0")
3+
SCRIPTPATH=$(dirname "$SCRIPT")
44

55
display_usage() {
66
echo "Usage: "
@@ -23,7 +23,7 @@ STANDALONE=0
2323
TESTS=0
2424
CLEAN_INSTALL=0
2525

26-
while [[ $# -gt 0 ]]; do
26+
while [ $# -gt 0 ]; do
2727
key="$1"
2828
case $key in
2929
-t|--with-tests)
@@ -47,30 +47,27 @@ while [[ $# -gt 0 ]]; do
4747
-h|--help)
4848
display_usage
4949
exit 0
50-
shift # past argument
5150
;;
5251
*) # unknown option
5352
shift # past argument
5453
;;
5554
esac
5655
done
5756

58-
if [ $CLEAN_INSTALL == 1 ]; then
57+
if [ $CLEAN_INSTALL = 1 ]; then
5958
echo "Cleaning install directory..."
60-
rm -rf $SCRIPTPATH/install/*
59+
rm -rf "${SCRIPTPATH}/install/"*
6160
fi
6261

63-
if [ $STANDALONE == 1 ]; then
64-
python3 $SCRIPTPATH/src/scripts/metadata_generator.py --standalone
62+
if [ $STANDALONE = 1 ]; then
63+
python3 "${SCRIPTPATH}/src/scripts/metadata_generator.py" --standalone
6564
else
66-
python3 $SCRIPTPATH/src/scripts/metadata_generator.py
65+
python3 "${SCRIPTPATH}/src/scripts/metadata_generator.py"
6766
fi
6867

69-
if $SCRIPTPATH/src/ros2cs/build.sh $OPTIONS; then
70-
mkdir -p $SCRIPTPATH/install/asset && cp -R $SCRIPTPATH/src/Ros2ForUnity $SCRIPTPATH/install/asset/
71-
$SCRIPTPATH/deploy_unity_plugins.sh $SCRIPTPATH/install/asset/Ros2ForUnity/Plugins/
72-
cp $SCRIPTPATH/src/Ros2ForUnity/metadata_ros2cs.xml $SCRIPTPATH/install/asset/Ros2ForUnity/Plugins/Linux/x86_64/metadata_ros2cs.xml
73-
cp $SCRIPTPATH/src/Ros2ForUnity/metadata_ros2cs.xml $SCRIPTPATH/install/asset/Ros2ForUnity/Plugins/metadata_ros2cs.xml
68+
if "${SCRIPTPATH}/src/ros2cs/build.sh" $OPTIONS; then
69+
mkdir -p "${SCRIPTPATH}/install/package" && cp -R "${SCRIPTPATH}/src/Ros2ForUnity" "${SCRIPTPATH}/install/package/"
70+
"${SCRIPTPATH}/deploy_unity_plugins.sh" "${SCRIPTPATH}/install/package/Ros2ForUnity/Plugins/"
7471
else
7572
echo "Ros2cs build failed!"
7673
exit 1

create_unity_package.ps1

Lines changed: 0 additions & 85 deletions
This file was deleted.

0 commit comments

Comments
 (0)