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

Turning ROS2-For-Unity into a package #95

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ log
build
.idea
src/ros2cs
**/metadata*.xml
src/Ros2ForUnity/Plugins
!src/Ros2ForUnity/Plugins/.gitkeep
src/Ros2ForUnity/Resources/ros2-for-unity.xml
7 changes: 1 addition & 6 deletions README-UBUNTU.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,7 @@ Start with installation of dependencies. Make sure to complete each step of `ros
./build.sh
```
* You can add `--clean-install` flag to make sure your installation directory is cleaned before deploying.
* Unity Asset is ready to import into your Unity project. You can find it in `install/asset/` directory.
* (optionally) To create `.unitypackage` in `install/unity_package`
```bash
create_unity_package.sh -u <your-path-to-unity-editor-executable>
```
> *NOTE* Unity license is required.
* Unity package is ready to import into your Unity project. You can find it in `install/package/` directory.

## OS-Specific usage remarks

Expand Down
13 changes: 3 additions & 10 deletions README-WINDOWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,7 @@ It is necessary to complete all the steps for `ros2cs` [Prerequisites](https://g
./build.ps1
```
* You can build with `-clean_install` to make sure your installation directory is cleaned before deploying.
* Unity Asset is ready to import into your Unity project. You can find it in `install/asset/` directory.
* (optionally) To create `.unitypackage` in `install/unity_package`
```powershell
create_unity_package.ps1
```
> *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.
* Unity package is ready to import into your Unity project. You can find it in `install/package/` directory.

## Build troubleshooting

Expand Down Expand Up @@ -85,9 +80,7 @@ pip install numpy

## OS-Specific usage remarks

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

> Note that after you build the Asset, you can use it on a machine that has no ros2 installation (if built with `-standalone`).

> You can simply copy over the `Ros2ForUnity` subdirectory to update your Asset.
> Note that after you build the package, you can use it on a machine that has no ros2 installation (if built with `-standalone`).
37 changes: 13 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Advantages of this module include:
- 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.
- Supports all standard ROS2 messages.
- 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.
- The module is wrapped as a Unity asset.
- The module is wrapped as a Unity package.

## Platforms

Expand Down Expand Up @@ -44,7 +44,7 @@ You can download pre-built [releases](https://github.com/RobotecAI/ros2-for-unit
## Building

> **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.
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`.
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`.

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

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.
1. Open or create Unity project.
1. Import asset into project:
1. copy `install/asset/Ros2ForUnity` into your project `Assets` folder, or
1. if you have deployed an `.unitypackage` - import it in Unity Editor by selecting `Import Package` → `Custom Package`
2. Open or create Unity project
3. Import `install/package/Ros2ForUnity` into your project with the package manager

**Before uploading the package into a registry you have to import it once from disk to generate .meta files for the native libraries!**

## Usage

**Prerequisites**

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

* If your build was prepared with `--standalone` flag then you are fine, and all you have to do is calling `Setup.SetupPath()` when necessary

otherwise

Expand All @@ -77,20 +79,20 @@ otherwise
**Initializing Ros2ForUnity**

1. Initialize `Ros2ForUnity` by creating a "hook" object which will be your wrapper around ROS2. You have two options:
1. `ROS2UnityComponent` based on `MonoBehaviour` which must be attached to a `GameObject` somewhere in the scene, then:
- `ROS2UnityComponent` based on `MonoBehaviour` which must be attached to a `GameObject` somewhere in the scene, then:
```c#
using ROS2;
...
// Example method of getting component, if ROS2UnityComponent lives in different GameObject, just use different get component methods.
ROS2UnityComponent ros2Unity = GetComponent<ROS2UnityComponent>();
```
1. or `ROS2UnityCore` which is a standard class that can be created anywhere
- `ROS2UnityCore` which is a standard class that can be created anywhere
```c#
using ROS2;
...
ROS2UnityCore ros2Unity = new ROS2UnityCore();
```
1. Create a node. You must first check if `Ros2ForUnity` is initialized correctly:
2. Create a node. You must first check if `Ros2ForUnity` is initialized correctly:
```c#
private ROS2Node ros2Node;
...
Expand Down Expand Up @@ -173,20 +175,7 @@ otherwise
```
### Examples

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.
> **Note:** Each example script looks for `ROS2UnityComponent` in its own game object. However, this is not a requirement, just example implementation.

**Topics**
1. Add `ROS2TalkerExample.cs` script to the very same game object.
1. Add `ROS2ListenerExample.cs` script to the very same game object.

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.

**Services**
1. Add `ROS2ServiceExample.cs` script to the very same game object.
1. Add `ROS2ClientExample.cs` script to the very same game object.

Once you start the project in Unity, you should be able to see client node calling an example service.
More complete examples are included in the Unity package.

## Acknowledgements

Expand Down
39 changes: 20 additions & 19 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
Makes a clean installation. Removes install dir before deploying
#>
Param (
[Parameter(Mandatory=$false)][switch]$with_tests=$false,
[Parameter(Mandatory=$false)][switch]$standalone=$false,
[Parameter(Mandatory=$false)][switch]$clean_install=$false
[Parameter(Mandatory = $false)][switch]$with_tests = $false,
[Parameter(Mandatory = $false)][switch]$standalone = $false,
[Parameter(Mandatory = $false)][switch]$clean_install = $false
)

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

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

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

if($standalone) {
& "python" $SCRIPTPATH\src\scripts\metadata_generator.py --standalone
} else {
& "python" $SCRIPTPATH\src\scripts\metadata_generator.py
if ($standalone) {
& "python" $SCRIPTPATH\src\scripts\metadata_generator.py --standalone
}
else {
& "python" $SCRIPTPATH\src\scripts\metadata_generator.py
}
if ($LASTEXITCODE -ne 0) {
Write-Host "Generating the Metadata failed!" -ForegroundColor Red
exit 1
}

& "$scriptPath\src\ros2cs\build.ps1" @options
if($?) {
md -Force $scriptPath\install\asset | Out-Null
Copy-Item -Path $scriptPath\src\Ros2ForUnity -Destination $scriptPath\install\asset\ -Recurse -Force
if ($?) {
mkdir -Force $scriptPath\install\package | Out-Null
Copy-Item -Path $scriptPath\src\Ros2ForUnity -Destination $scriptPath\install\package\ -Recurse -Force

$plugin_path=Join-Path -Path $scriptPath -ChildPath "\install\asset\Ros2ForUnity\Plugins\"
$plugin_path = Join-Path -Path $scriptPath -ChildPath "\install\package\Ros2ForUnity\Plugins\"
Write-Host "Deploying build to $plugin_path" -ForegroundColor Green
& "$scriptPath\deploy_unity_plugins.ps1" $plugin_path

Copy-Item -Path $scriptPath\src\Ros2ForUnity\metadata_ros2cs.xml -Destination $scriptPath\install\asset\Ros2ForUnity\Plugins\Windows\x86_64\
Copy-Item -Path $scriptPath\src\Ros2ForUnity\metadata_ros2cs.xml -Destination $scriptPath\install\asset\Ros2ForUnity\Plugins\
} else {
}
else {
Write-Host "Ros2cs build failed!" -ForegroundColor Red
exit 1
}


27 changes: 12 additions & 15 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
SCRIPT=$(readlink -f $0)
SCRIPTPATH=`dirname $SCRIPT`
#!/bin/sh -e
SCRIPT=$(readlink -f "$0")
SCRIPTPATH=$(dirname "$SCRIPT")

display_usage() {
echo "Usage: "
Expand All @@ -23,7 +23,7 @@ STANDALONE=0
TESTS=0
CLEAN_INSTALL=0

while [[ $# -gt 0 ]]; do
while [ $# -gt 0 ]; do
key="$1"
case $key in
-t|--with-tests)
Expand All @@ -47,30 +47,27 @@ while [[ $# -gt 0 ]]; do
-h|--help)
display_usage
exit 0
shift # past argument
;;
*) # unknown option
shift # past argument
;;
esac
done

if [ $CLEAN_INSTALL == 1 ]; then
if [ $CLEAN_INSTALL = 1 ]; then
echo "Cleaning install directory..."
rm -rf $SCRIPTPATH/install/*
rm -rf "${SCRIPTPATH}/install/"*
fi

if [ $STANDALONE == 1 ]; then
python3 $SCRIPTPATH/src/scripts/metadata_generator.py --standalone
if [ $STANDALONE = 1 ]; then
python3 "${SCRIPTPATH}/src/scripts/metadata_generator.py" --standalone
else
python3 $SCRIPTPATH/src/scripts/metadata_generator.py
python3 "${SCRIPTPATH}/src/scripts/metadata_generator.py"
fi

if $SCRIPTPATH/src/ros2cs/build.sh $OPTIONS; then
mkdir -p $SCRIPTPATH/install/asset && cp -R $SCRIPTPATH/src/Ros2ForUnity $SCRIPTPATH/install/asset/
$SCRIPTPATH/deploy_unity_plugins.sh $SCRIPTPATH/install/asset/Ros2ForUnity/Plugins/
cp $SCRIPTPATH/src/Ros2ForUnity/metadata_ros2cs.xml $SCRIPTPATH/install/asset/Ros2ForUnity/Plugins/Linux/x86_64/metadata_ros2cs.xml
cp $SCRIPTPATH/src/Ros2ForUnity/metadata_ros2cs.xml $SCRIPTPATH/install/asset/Ros2ForUnity/Plugins/metadata_ros2cs.xml
if "${SCRIPTPATH}/src/ros2cs/build.sh" $OPTIONS; then
mkdir -p "${SCRIPTPATH}/install/package" && cp -R "${SCRIPTPATH}/src/Ros2ForUnity" "${SCRIPTPATH}/install/package/"
"${SCRIPTPATH}/deploy_unity_plugins.sh" "${SCRIPTPATH}/install/package/Ros2ForUnity/Plugins/"
else
echo "Ros2cs build failed!"
exit 1
Expand Down
85 changes: 0 additions & 85 deletions create_unity_package.ps1

This file was deleted.

Loading