Skip to content

Commit 776f74f

Browse files
committed
Version 1.2 (#45)
Humble, custom messages with custom messages, ubuntu standalone
1 parent 22d59ff commit 776f74f

File tree

11 files changed

+208
-62
lines changed

11 files changed

+208
-62
lines changed

README-UBUNTU.md

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,48 @@ This readme contains information specific to Ubuntu 20.04. For general informati
44

55
## Building
66

7+
We assume that working directory is `~/ros2-for-unity` and we are using `ROS2 galactic` (replace with `foxy` or `humble` where applicable).
8+
79
### Prerequisites
810

911
Start with installation of dependencies. Make sure to complete each step of `ros2cs` [Prerequisites section](https://github.com/RobotecAI/ros2cs/blob/master/README-UBUNTU.md#prerequisites).
1012

1113
### Steps
1214

13-
* Clone this project.
14-
* You need to source your ROS2 installation (`source /opt/ros/foxy/setup.bash`) before you proceed, for each new open terminal. It is convenient to include this command in your `~/.profile` file.
15-
* 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`).
16-
* Run `build.sh` script.
17-
* You can build tests by adding `--with-tests` argument to `build` command.
18-
* You can build with `--clean-install` to make sure your installation directory is cleaned before deploying.
19-
* It invokes `colcon_build` with `--merge-install` argument to simplify libraries installation.
20-
* 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).
21-
* It prepares Unity Asset that is ready to import into your Unity project (`install/asset/` directory).
22-
* Run `create_unity_package.sh -u <your-path-to-unity-editor-executable>` to generate .unitypackage file in `install/unity_package`
15+
* Clone this project.
16+
```bash
17+
git clone [email protected]:RobotecAI/ros2-for-unity.git ~/ros2-for-unity
18+
```
19+
* You need to source your ROS2 installation before you proceed, for each new open terminal. It is convenient to include this command in your `~/.profile` file.
20+
```bash
21+
# galactic
22+
. /opt/ros/galactic/setup.bash
23+
```
24+
* Enter `Ros2ForUnity` working directory.
25+
```bash
26+
cd ~/ros2-for-unity
27+
```
28+
* Set up you custom messages in `ros2_for_unity_custom_messages.repos`
29+
* Import necessary and custom messages repositories.
30+
```bash
31+
./pull_repositories.sh
32+
```
33+
> *NOTE* `pull_repositories.sh` script doesn't update already existing repositories, you have to remove `src/ros2cs` folder to re-import new versions.
34+
* Build `Ros2ForUnty`. You can build it in standalone or overlay mode.
35+
```bash
36+
# standalone mode
37+
./build.sh --standalone
38+
39+
# overlay mode
40+
./build.sh
41+
```
42+
* 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.
2349
2450
## OS-Specific usage remarks
2551
@@ -30,5 +56,13 @@ Running Unity Editor through Unity Hub is also supported.
3056
3157
## Usage troubleshooting
3258
59+
**No ROS environment sourced. You need to source your ROS2 (..)**
60+
3361
* If you see `"No ROS environment sourced. You need to source your ROS2 (..)"` message in Unity3D Editor, it means your environment was not sourced properly. This could happen if you run Unity but it redirects to Hub and ignores your console environment variables (this behavior can depend on Unity3D version). In such case, run project directly with `-projectPath` or add ros2 sourcing to your `~/.profile` file (you need to re-log for it to take effect).
62+
3463
* Keep in mind that `UnityHub` stays in the background after its first launch and Unity Editor launch without `-projectPath` will redirect to it and the Hub will start Unity Editor. Since environment variables for the process are set on launch and inherited by child processes, your sourced ros2 environment in the console launching the Editor this way won't be applied. To make sure it applies (and to change between different ros2 distributions), make sure to terminate existing UnityHub process and run it with the correct ros2 distribution sourced.
64+
65+
**There are no errors but I can't see topics published by Ros2ForUnity**
66+
67+
* Make sure your dds config is correct.
68+
* Sometimes ROS2 daemon brakes up when changing network interfaces or ROS2 version. Try to stop it forcefully (`pkill -9 _ros2_daemon`) and restart (`ros2 daemon start`).

README-WINDOWS.md

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# ROS2 For Unity - Windows 10
22

3-
This readme contains information specific to Window 10. For general information, please see README.md
3+
This readme contains information specific to Window 10. For general information, please see [README.md](README.md).
44

55
## Building
66

7-
We assume working directory is `C:\dev` and we are using `ROS2 foxy` (replace with `Galactic` where applicable).
7+
We assume that working directory is `C:\dev` and we are using `ROS2 galactic` (replace with `foxy` or `humble` where applicable).
88

99
### Prerequisites
1010

@@ -15,22 +15,39 @@ It is necessary to complete all the steps for `ros2cs` [Prerequisites](https://g
1515
* Make sure [long paths on Windows are enabled](https://github.com/RobotecAI/ros2cs/blob/master/README-WINDOWS.md#important-notices)
1616
* Make sure you open [`Developer PowerShell for VS` with administrator privileges](https://github.com/RobotecAI/ros2cs/blob/master/README-WINDOWS.md#important-notices)
1717
* For `ros2 galactic` distribution, it is best to [create a `C:\ci\ws\install\include` directory](https://github.com/RobotecAI/ros2cs/blob/master/README-WINDOWS.md#important-notices)
18-
* Clone this repository.
18+
* Clone this project.
19+
```powershell
20+
git clone [email protected]:RobotecAI/ros2-for-unity.git C:\dev\ros2-for-unity
21+
```
1922
* Source your ROS2 installation (`C:\dev\ros2_foxy\local_setup.ps1`) in the terminal before you proceed.
20-
* Run `pull_repositories.ps1`. This will pull `ros2cs` as well as your custom messages. You might be asked for github credentials.
21-
* Run `build.ps1` script.
22-
* Optionally, you can build tests by adding `-with_tests` argument to `build` command.
23+
```
24+
C:\dev\ros2_foxy\local_setup.ps1
25+
```
26+
* Enter `Ros2ForUnity` working directory.
27+
```powershell
28+
cd C:\dev\ros2-for-unity
29+
```
30+
* Set up you custom messages in `ros2_for_unity_custom_messages.repos`
31+
* Import necessary and custom messages repositories.
32+
```powershell
33+
.\pull_repositories.ps1
34+
```
35+
> *NOTE* `pull_repositories.ps1` script doesn't update already existing repositories, you have to remove `src\ros2cs` folder to re-import new versions.
36+
* Build `Ros2ForUnty`. You can build it in standalone or overlay mode.
37+
```powershell
38+
# standalone mode
39+
./build.ps1 -standalone
40+
41+
# overlay mode
42+
./build.ps1
43+
```
2344
* You can build with `-clean_install` to make sure your installation directory is cleaned before deploying.
24-
* This ivokes `colcon_build` with `--merge-install` argument to simplify libraries installation.
25-
* 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).
26-
* It prepares Unity Asset that is ready to import into your Unity project (`install/asset/` directory).
27-
* Currently Windows OS supports standalone build only.
28-
* In order to generate `Ros2ForUnity.unitypackage` please run `create_unity_package.ps1`. Please provide path to your Unity executable when prompted.
29-
* Asset can be found in `install\unity_package` directory
30-
* 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.
31-
* At this moment you have two valid forms of the Asset.
32-
* One is available as `src\Ros2ForUnity` folder which you can simply copy to Unity3D `Assets` directory.
33-
* Second one is `Ros2ForUnity.unitypackage` which you can import in Unity3D.
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.
3451
3552
## Build troubleshooting
3653

@@ -59,7 +76,7 @@ Please execute `Set-ExecutionPolicy Bypass -Scope Process` in PS shell session t
5976
> [4.469s] C:/dev/ros2_foxy/share/rosidl_cmake/cmake/rosidl_generate_interfaces.cmake:286 (ament_execute_extensions)
6077
> [4.484s] CMakeLists.txt:16 (rosidl_generate_interfaces)
6178
Please reinstall `numpy` package from python by typing:
62-
```bash
79+
```powershell
6380
pip uninstall numpy
6481
pip install numpy
6582
```

README.md

Lines changed: 91 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Advantages of this module include:
66
- High performance - higher throughput and considerably lower latencies comparing to bridging solutions.
77
- Your simulation entities are real ROS2 nodes / publishers / subscribers. They will behave correctly with e.g. command line tools such as `ros2 topic`. They will respect QoS settings and can use ROS2 native time.
88
- 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.
9-
- Supports all standard ROS2 messages
9+
- Supports all standard ROS2 messages.
1010
- 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.
1111
- The module is wrapped as a Unity asset.
1212

@@ -16,18 +16,22 @@ Supported OSes:
1616
- Ubuntu 20.04 (bash)
1717
- Windows 10 (powershell)
1818

19+
> **Notice:** Currently, ros2 humble is only supported on Ubuntu 20.04. You have to build it from sources since it is not available in `apt`.
20+
1921
Supported ROS2 distributions:
2022
- Foxy
2123
- Galactic
24+
- Humble
2225

2326
Supported Unity3d:
2427
- 2020+
2528

2629
Older versions of Unity3d may work, but the editor executable most probably won't be detected properly by deployment script. This would require user confirmation for using unsupported version.
2730

28-
For Windows, this asset can be prepared in standalone mode only (no ROS2 installation required on target machine, e.g. your Unity3D simulation server). All required dependencies are installed and can be used e.g. as a complete set of Unity3D plugins.
31+
This asset can be prepared in two flavours:
2932

30-
For Ubuntu, this asset can be prepared in overlay mode only (assuming existing (supported) ROS2 installation on target machine). Only asset libraries and generated messages are installed.
33+
- standalone mode, where no ROS2 installation required on target machine, e.g. your Unity3D simulation server. All required dependencies are installed and can be used e.g. as a complete set of Unity3D plugins.
34+
- overlay mode, where the ROS2 installation is required on target machine. Only asset libraries and generated messages are installed therefore ROS2 instance must be sourced.
3135

3236
## Releases
3337

@@ -37,25 +41,98 @@ You can download pre-built [releases](https://github.com/RobotecAI/ros2-for-unit
3741

3842
## Building
3943

40-
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.
44+
> **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.
4145
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`.
4246

4347
Please see OS-specific instructions:
4448
- [Instructions for Ubuntu 20.04](README-UBUNTU.md)
4549
- [Instructions for Windows 10](README-WINDOWS.md)
4650

47-
## Usage
51+
## Custom messages
52+
53+
Custom messages can be included in the build by either:
54+
* list them in `ros2_for_unity_custom_messages.repos` file, or
55+
* manually inserting them in `src/ros2cs` directory. If the folder doesn't exist, you must pull repositories first (see building steps for each OS).
4856

49-
1. Perform building steps described in the OS-specific readme or download pre-built Unity package. Do not source ros2-for-unity nor ros2cs.
50-
2. Open or create Unity project.
51-
3. Go to Assets in the menu bar (at the top of the Unity Window).
52-
4. Select `Import Package``Custom Package`. Make sure that the asset name is Ros2ForUnity and it is directly in the Assets folder.
53-
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.
54-
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.
55-
7. Add example script to any object in the hierarchy tab, e.g. by dragging `ROS2TalkerExample.cs` to the object in the inspector tab.
56-
8. Select another object in the hierarchy tab and add repeat the previous step using `ROS2ListenerExample.cs`.
57-
9. 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.
57+
## Installation
58+
59+
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.
60+
1. Open or create Unity project.
61+
1. Import asset into project:
62+
1. copy `install/asset/Ros2ForUnity` into your project `Assets` folder, or
63+
1. if you have deployed an `.unitypackage` - import it in Unity Editor by selecting `Import Package``Custom Package`
64+
65+
## Usage
5866

67+
**Prerequisites**
68+
69+
* If your build was prepared with `--standalone` flag then you are fine, and all you have to do is run the editor
70+
71+
otherwise
72+
73+
* source ROS2 which matches the `Ros2ForUnity` version, then run the editor from within the very same terminal/console.
74+
75+
**Initializing Ros2ForUnity**
76+
77+
1. Initialize `Ros2ForUnity` by creating a "hook" object which will be your wrapper around ROS2. You have two options:
78+
1. `ROS2UnityComponent` based on `MonoBehaviour` which must be attached to a `GameObject` somewhere in the scene, then:
79+
```c#
80+
using ROS2;
81+
...
82+
// Example method of getting component, if ROS2UnityComponent lives in different GameObject, just use different get component methods.
83+
ROS2UnityComponent ros2Unity = GetComponent<ROS2UnityComponent>();
84+
```
85+
1. or `ROS2UnityCore` which is a standard class that can be created anywhere
86+
```c#
87+
using ROS2;
88+
...
89+
ROS2UnityCore ros2Unity = new ROS2UnityCore();
90+
```
91+
1. Create a node. You must first check if `Ros2ForUnity` is initialized correctly:
92+
```c#
93+
private ROS2Node ros2Node;
94+
...
95+
if (ros2Unity.Ok()) {
96+
ros2Node = ros2Unity.CreateNode("ROS2UnityListenerNode");
97+
}
98+
```
99+
100+
**Publishing messages:**
101+
102+
1. Create publisher
103+
```c#
104+
private IPublisher<std_msgs.msg.String> chatter_pub;
105+
...
106+
if (ros2Unity.Ok()){
107+
chatter_pub = ros2Node.CreatePublisher<std_msgs.msg.String>("chatter");
108+
}
109+
```
110+
1. Send messages
111+
```c#
112+
std_msgs.msg.String msg = new std_msgs.msg.String();
113+
msg.Data = "Hello Ros2ForUnity!";
114+
chatter_pub.Publish(msg);
115+
```
116+
117+
**Subscribing to a topic**
118+
119+
1. Create subscriber:
120+
```c#
121+
private ISubscription<std_msgs.msg.String> chatter_sub;
122+
...
123+
if (ros2Unity.Ok()) {
124+
chatter_sub = ros2Node.CreateSubscription<std_msgs.msg.String>(
125+
"chatter", msg => Debug.Log("Unity listener heard: [" + msg.Data + "]"));
126+
}
127+
```
128+
129+
### Examples
130+
131+
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.
132+
1. Add `ROS2TalkerExample.cs` script to the very same game object.
133+
1. Add `ROS2ListenerExample.cs` script to the very same game object.
134+
> **Note:** Each example script looks for `ROS2UnityComponent` in its own game object. However, this is not a requirement, just example implementation.
135+
1. 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.
59136
## Acknowledgements
60137

61138
Open-source release of ROS2 For Unity was made possible through cooperation with [Tier IV](https://tier4.jp). Thanks to encouragement, support and requirements driven by Tier IV the project was significantly improved in terms of portability, stability, core structure and user-friendliness.

build.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#>
1414
Param (
1515
[Parameter(Mandatory=$false)][switch]$with_tests=$false,
16-
[Parameter(Mandatory=$false)][switch]$standalone=$true,
16+
[Parameter(Mandatory=$false)][switch]$standalone=$false,
1717
[Parameter(Mandatory=$false)][switch]$clean_install=$false
1818
)
1919

@@ -50,7 +50,7 @@ if($?) {
5050
Write-Host "Deploying build to $plugin_path" -ForegroundColor Green
5151
& "$scriptPath\deploy_unity_plugins.ps1" $plugin_path
5252

53-
Copy-Item -Path $scriptPath\src\Ros2ForUnity\metadata_ros2cs.xml -Destination $scriptPath\install\asset\Ros2ForUnity\Plugins\Linux\x86_64\
53+
Copy-Item -Path $scriptPath\src\Ros2ForUnity\metadata_ros2cs.xml -Destination $scriptPath\install\asset\Ros2ForUnity\Plugins\Windows\x86_64\
5454
Copy-Item -Path $scriptPath\src\Ros2ForUnity\metadata_ros2cs.xml -Destination $scriptPath\install\asset\Ros2ForUnity\Plugins\
5555
} else {
5656
Write-Host "Ros2cs build failed!" -ForegroundColor Red

deploy_unity_plugins.ps1

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,21 @@ if (([string]::IsNullOrEmpty($pluginDir)) -Or $args[0] -eq "--help" -Or $args[0]
1818

1919
if (Test-Path -Path $pluginDir) {
2020
Write-Host "Copying plugins to to: '$pluginDir' ..."
21-
(Copy-Item -verbose -Path $scriptPath\install\lib\dotnet\* -Destination ${pluginDir} 4>&1).Message
21+
Get-ChildItem $scriptPath\install\lib\dotnet\ -Recurse -Exclude @('*.pdb') | Copy-Item -Destination ${pluginDir}
2222
Write-Host "Plugins copied to: '$pluginDir'" -ForegroundColor Green
2323
if(-not (Test-Path -Path $pluginDir\Windows\x86_64\)) {
2424
mkdir ${pluginDir}\Windows\x86_64\
2525
}
2626
Write-Host "Copying libraries to: '$pluginDir\Windows\x86_64\' ..."
27-
(Copy-Item -verbose -Path $scriptPath\install\bin\*.dll -Destination ${pluginDir}\Windows\x86_64\ 4>&1).Message
28-
(Copy-Item -verbose -Path $scriptPath\install\standalone\*.dll -Destination ${pluginDir}\Windows\x86_64\ 4>&1).Message
29-
(Copy-Item -verbose -Path $scriptPath\install\resources\*.dll -Destination ${pluginDir}\Windows\x86_64\ 4>&1).Message
27+
Get-ChildItem $scriptPath\install\bin\ -Recurse -Exclude @('*_py.dll', '*_python.dll') | Copy-Item -Destination ${pluginDir}\Windows\x86_64\
28+
if(-not (Test-Path -Path $scriptPath\install\standalone\)) {
29+
mkdir $scriptPath\install\standalone
30+
}
31+
(Copy-Item -Path $scriptPath\install\standalone\*.dll -Destination ${pluginDir}\Windows\x86_64\ 4>&1).Message
32+
if(-not (Test-Path -Path $scriptPath\install\resources\)) {
33+
mkdir $scriptPath\install\resources
34+
}
35+
(Copy-Item -Path $scriptPath\install\resources\*.dll -Destination ${pluginDir}\Windows\x86_64\ 4>&1).Message
3036
Write-Host "Libraries copied to '${pluginDir}\Windows\x86_64\'" -ForegroundColor Green
3137
} else {
3238
Write-Host "Plugins directory: '$pluginDir' doesn't exist. Please create it first manually." -ForegroundColor Red

deploy_unity_plugins.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ fi
1414
pluginDir=$1
1515

1616
mkdir -p ${pluginDir}/Linux/x86_64/
17-
cp $SCRIPTPATH/install/lib/dotnet/* ${pluginDir}
17+
find install/lib/dotnet/ -maxdepth 1 -not -name "*.pdb" -type f -exec cp {} ${pluginDir} \;
1818
cp $SCRIPTPATH/install/standalone/* ${pluginDir}/Linux/x86_64/
19-
cp $SCRIPTPATH/install/lib/*.so ${pluginDir}/Linux/x86_64/
19+
find install/lib/ -maxdepth 1 -not -name "*_python.so" -type f -exec cp {} ${pluginDir}/Linux/x86_64/ \;
2020
cp $SCRIPTPATH/install/resources/*.so ${pluginDir}/Linux/x86_64/

0 commit comments

Comments
 (0)