Skip to content
Merged
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
5 changes: 3 additions & 2 deletions README-UBUNTU.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ Start with installation of dependencies. Make sure to complete each step of `ros
* Run `pull_repositories.sh`. This will pull `ros2cs` as well as your custom messages. You might be asked for gitlab credentials. Remember to **pull this repository with each update** (e.g. with `vcs pull`).
* Run `build.sh` script.
* You can build tests by adding `--with-tests` argument to `build` command.
* You can build with `--clean-install` to make sure your installation directory is cleaned before deploying.
* It invokes `colcon_build` with `--merge-install` argument to simplify libraries installation.
* It deploys built plugins into the Asset directory. Note that only plugins built for the current platform will be deployed (there is no cross-compilation).
* It prepares Unity Asset that is ready to import into your Unity project.
* Run `create_unity_asset.sh -u <your-path-to-unity-editor-executable>` to generate .unitypackage file in `install/unity_package`
* It prepares Unity Asset that is ready to import into your Unity project (`install/asset/` directory).
* Run `create_unity_package.sh -u <your-path-to-unity-editor-executable>` to generate .unitypackage file in `install/unity_package`

## OS-Specific usage remarks

Expand Down
7 changes: 4 additions & 3 deletions README-WINDOWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ It is necessary to complete all the steps for `ros2cs` [Prerequisites](https://g
* Run `pull_repositories.ps1`. This will pull `ros2cs` as well as your custom messages. You might be asked for github credentials.
* Run `build.ps1` script.
* Optionally, you can build tests by adding `--with-tests` argument to `build` command.
* You can build with `--clean-install` to make sure your installation directory is cleaned before deploying.
* This ivokes `colcon_build` with `--merge-install` argument to simplify libraries installation.
* It deploys built plugins into the Asset directory. Note that only plugins built for the current platform will be deployed (there is no cross-compilation).
* It prepares Unity Asset that is ready to import into your Unity project.
* It prepares Unity Asset that is ready to import into your Unity project (`install/asset/` directory).
* By default, build process generates standalone libraries on Windows.
You can disable this feature by setting CMake option `STANDALONE_BUILD` to `OFF` (e.g. through editing `build.ps1`).
* In order to generate `Ros2ForUnity.unitypackage` please run `create_unity_asset.ps1`. Please provide path to your Unity executable when prompted.
* In order to generate `Ros2ForUnity.unitypackage` please run `create_unity_package.ps1`. Please provide path to your Unity executable when prompted.
* Asset can be found in `install\unity_package` directory
* In case your Unity license has expired, the `create_unity_asset.ps1` won't throw any errors but `Ros2ForUnity.unitypackage` won't be generated too.
* 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.
* At this moment you have two valid forms of the Asset.
* One is available as `src\Ros2ForUnity` folder which you can simply copy to Unity3D `Assets` directory.
* Second one is `Ros2ForUnity.unitypackage` which you can import in Unity3D.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Please see OS-specific instructions:
2. Open or create Unity project.
3. Go to Assets in the menu bar (at the top of the Unity Window).
4. Select `Import Package` → `Custom Package`.
5. In the file browser, select the .unitypackage file built by `create_unity_asset` script (by default located in `install/unity_package`) and follow the instructions on the screen.
5. In the file browser, select the .unitypackage file built by `create_unity_package` script (by default located in `install/unity_package`) and follow the instructions on the screen.
6. Create a top-level object containing `ROS2UnityComponent.cs`. This is the central Monobehavior for `ROS2 For Unity` that manages all the nodes. Refer to class documentation for details.
7. Add example script to any object in the hierarchy tab, e.g. by dragging `ROS2TalkerExample.cs` to the object in the inspector tab.
8. Select another object in the hierarchy tab and add repeat the previous step using `ROS2ListenerExample.cs`.
Expand Down
64 changes: 42 additions & 22 deletions build.ps1
Original file line number Diff line number Diff line change
@@ -1,30 +1,50 @@
$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition

function Print-Help {
"
Usage:
build.ps1 [--with-tests]
<#
.SYNOPSIS
Builds Ros2ForUnity asset
.DESCRIPTION
This script builds Ros2DorUnity asset
.PARAMETER with_tests
Build tests
.PARAMETER standalone
Add ros2 binaries. Currently standalone flag is fixed to true, so there is no way to build without standalone libs. Parameter kept for future releases
.PARAMETER clean_install
Makes a clean installation. Removes install dir before deploying
#>
Param (
[Parameter(Mandatory=$false)][switch]$with_tests=$false,
[Parameter(Mandatory=$false)][switch]$standalone=$true,
[Parameter(Mandatory=$false)][switch]$clean_install=$false
)

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

Options:
--with-tests - build with tests.
"
if(-Not (Test-Path -Path "$scriptPath\src\ros2cs")) {
Write-Host "Pull repositories with 'pull_repositories.ps1' first." -ForegroundColor Red
exit 1
}

$tests=0
$msg="Build started."
if ($args[0] -eq "--with-tests") {
$tests=1
$msg+=" (with tests)"
} elseif ($args[0] -eq "--help" -Or $args[0] -eq "-h") {
Print-Help
exit
Write-Host $msg -ForegroundColor Green
$options = @{
with_tests = $with_tests
standalone = $standalone
}

$tests_info=0
$plugin_path=Join-Path -Path $scriptPath -ChildPath "\src\Ros2ForUnity\Plugins\"
if($clean_install) {
Write-Host "Cleaning install directory..." -ForegroundColor White
Remove-Item -Path "$scriptPath\install" -Force -Recurse -ErrorAction Ignore
}
& "$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

$plugin_path=Join-Path -Path $scriptPath -ChildPath "\install\asset\Ros2ForUnity\Plugins\"
Write-Host "Deploying build to $plugin_path" -ForegroundColor Green
& "$scriptPath\deploy_unity_plugins.ps1" $plugin_path
} else {
Write-Host "Ros2cs build failed!" -ForegroundColor Red
exit 1
}

Write-Host $msg -ForegroundColor Green
colcon build --merge-install --event-handlers console_direct+ --cmake-args -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=$tests

Write-Host "Deploying build to $plugin_path" -ForegroundColor Green
& "$scriptPath\deploy_unity_plugins.ps1" $plugin_path
70 changes: 54 additions & 16 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,63 @@
SCRIPT=$(readlink -f $0)
SCRIPTPATH=`dirname $SCRIPT`

if [ -z "${ROS_DISTRO}" ]; then
echo "Source your ros2 distro first (Foxy and Galactic are supported)"
exit 1
fi

TESTS=0
MSG="Build started."
if [ "$1" = "--with-tests" ]; then
TESTS=1
MSG="$MSG (with tests)"
elif [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
display_usage() {
echo "Usage: "
echo "build.sh [--with-tests]"
echo ""
echo "build.sh [--with-tests] [--standalone] [--clean-install]"
echo ""
echo "Options:"
echo "--with-tests - build with tests."
echo "--with-tests - build with tests"
echo "--standalone - standalone version"
echo "--clean-install - makes a clean installation, removes install directory before deploying"
}

if [ ! -d "$SCRIPTPATH/src/ros2cs" ]; then
echo "Pull repositories with 'pull_repositories.sh' first."
exit 1
fi

echo $MSG
#TODO - call ros2cs ./build.sh instead, but with this workspace directory (parametrize the script)
colcon build --merge-install --event-handlers console_direct+ --cmake-args -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=$TESTS -DCMAKE_SHARED_LINKER_FLAGS="-Wl,-rpath=." && $SCRIPTPATH/deploy_unity_plugins.sh $SCRIPTPATH/src/Ros2ForUnity/Plugins/
OPTIONS=""
STANDALONE=0
TESTS=0
CLEAN_INSTALL=0

while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-t|--with-tests)
OPTIONS="$OPTIONS --with-tests"
TESTS=1
shift # past argument
;;
-s|--standalone)
OPTIONS="$OPTIONS --standalone"
STANDALONE=1
shift # past argument
;;
-c|--clean-install)
CLEAN_INSTALL=1
shift # past argument
;;
-h|--help)
display_usage
exit 0
shift # past argument
;;
*) # unknown option
shift # past argument
;;
esac
done

if [ $CLEAN_INSTALL == 1 ]; then
echo "Cleaning install directory..."
rm -rf "$SCRIPTPATH/install"
fi
if $SCRIPTPATH/src/ros2cs/build.sh $OPTIONS; then
mkdir -p $SCRIPTPATH/install/asset && cp -R $SCRIPTPATH/src/Ros2ForUnity $SCRIPTPATH/install/asset/Ros2ForUnity
$SCRIPTPATH/deploy_unity_plugins.sh $SCRIPTPATH/install/asset/Ros2ForUnity/Plugins/
else
echo "Ros2cs build failed!"
exit 1
fi
7 changes: 6 additions & 1 deletion create_unity_asset.ps1 → create_unity_package.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,18 @@ $scriptPath = split-path -parent $MyInvocation.MyCommand.Definition
$temp_dir = $Env:TEMP

if(-Not $PSBoundParameters.ContainsKey('input_asset')) {
$input_asset= Join-Path -Path $scriptPath -ChildPath "\src\Ros2ForUnity"
$input_asset= Join-Path -Path $scriptPath -ChildPath "\install\asset\Ros2ForUnity"
}

if(-Not $PSBoundParameters.ContainsKey('output_dir')) {
$output_dir= Join-Path -Path $scriptPath -ChildPath "\install\unity_package"
}

if(-Not (Test-Path -Path "$input_asset")) {
Write-Host "Input asset '$input_asset' doesn't exist! Use 'build.ps1' to build project first." -ForegroundColor Red
exit 1
}

if(-Not (Test-Path -Path "$output_dir")) {
mkdir ${output_dir} | Out-Null
}
Expand Down
12 changes: 8 additions & 4 deletions create_unity_asset.sh → create_unity_package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ display_usage() {
echo "This script creates a temporary Unity project in '/tmp' directory, copy input asset and makes an unity package out of it. Valid Unity license is required."
echo ""
echo "Usage:"
echo "create_unity_asset.sh -u <UNITY_PATH> -i [INPUT_ASSET] -p [PACKAGE_NAME] -o [OUTPUT_DIR]"
echo "create_unity_package.sh -u <UNITY_PATH> -i [INPUT_ASSET] -p [PACKAGE_NAME] -o [OUTPUT_DIR]"
echo ""
echo "UNITY_PATH - Unity editor executable path"
echo "INPUT_ASSET - input asset to pack into unity package, default = 'src/Ros2ForUnity'"
echo "INPUT_ASSET - input asset to pack into unity package, default = 'install/asset/Ros2ForUnity'"
echo "PACKAGE_NAME - unity package name, default = 'Ros2ForUnity'"
echo "OUTPUT_DIR - output file directory, default = 'install/unity_package'"
}

UNITY_PATH=""
INPUT_ASSET="src/Ros2ForUnity"
INPUT_ASSET="install/asset/Ros2ForUnity"
PACKAGE_NAME="Ros2ForUnity"
OUTPUT_DIR="$SCRIPTPATH/install/unity_package"

Expand Down Expand Up @@ -48,7 +48,6 @@ while [[ $# -gt 0 ]]; do
display_usage
exit 0
shift # past argument
shift # past value
;;
*) # unknown option
shift # past argument
Expand All @@ -63,6 +62,11 @@ if [ -z "$UNITY_PATH" ] || [ -z "$PACKAGE_NAME" ] || [ -z "$INPUT_ASSET" ] || [
exit 1
fi

if [ ! -d "$INPUT_ASSET" ]; then
echo "Input asset '$INPUT_ASSET' doesn't exist! Use 'build.sh' to build project first."
exit 1
fi

UNITY_VERSION=`$UNITY_PATH -version`

# Test if unity editor is valid
Expand Down