Skip to content

Commit 0fa3ee3

Browse files
Laurie/release tutorial fixes (#94)
1 parent 9a482f8 commit 0fa3ee3

9 files changed

Lines changed: 65 additions & 45 deletions

File tree

66.2 KB
Loading
66 KB
Loading

tutorials/ros_unity_integration/publisher.md

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,29 @@ Create a simple Unity scene which publishes a GameObject's position and rotation
1212

1313
```bash
1414
source devel/setup.bash
15-
rosrun robotics_demo server_endpoint.py
15+
rosrun robotics_demo server_endpoint.py
1616
```
1717

1818
Once the server_endpoint has started, it will print something similar to `[INFO] [1603488341.950794]: Starting server on 192.168.50.149:10000`.
1919

2020
- Open another new terminal window, navigate to your ROS workspace, and run the following commands:
2121
```bash
2222
source devel/setup.bash
23-
rostopic echo pos_rot
23+
rostopic echo pos_rot
2424
```
2525

2626
## Setting Up Unity Scene
27-
- In the menu bar, find and select `RosMessageGeneration` -> `Auto Generate Messages` -> `Single Message ...`
28-
- Set the input file path to `PATH/TO/Unity-Robotics-Hub/tutorials/ros_packages/robotics_demo/msg/PosRot.msg ` and click `GENERATE!`
29-
- The generated file will be saved in the default directory `Assets/RosMessages/msg`
27+
- In the menu bar, find and select `Robotics` -> `Generate ROS Messages...`
28+
- Set the ROS message path to `PATH/TO/Unity-Robotics-Hub/tutorials/ros_packages/robotics_demo`.
29+
- Expand the robotics_demo subfolder and click "Build 2 msgs" to generate new C# scripts from the ROS .msg files.
30+
31+
![](images/generate_messages_1.png)
32+
33+
- The generated files will be saved in the default directory `Assets/RosMessages/RoboticsDemo/msg`.
3034
- Create a new directory in `Assets` and name it `Scripts`
3135
- Create a new script in the `Scripts` directory and name it `RosPublisherExample.cs`
3236
- Open `RosPublisherExample.cs` and paste the following code:
33-
- **Note** Script can be found at `tutorials/ros_unity_integration/unity_scripts`
37+
- **Note** Script can be found at `tutorials/ros_unity_integration/unity_scripts`
3438

3539
```csharp
3640
using RosMessageTypes.RoboticsDemo;
@@ -42,7 +46,7 @@ using Random = UnityEngine.Random;
4246
/// </summary>
4347
public class RosPublisherExample : MonoBehaviour
4448
{
45-
public ROSConnection ros;
49+
ROSConnection ros;
4650
public string topicName = "pos_rot";
4751

4852
// The GameObject
@@ -53,6 +57,12 @@ public class RosPublisherExample : MonoBehaviour
5357
// Used to determine how much time has elapsed since the last message was published
5458
private float timeElapsed;
5559

60+
void Start()
61+
{
62+
// start the ROS connection
63+
ros = ROSConnection.instance;
64+
}
65+
5666
private void Update()
5767
{
5868
timeElapsed += Time.deltaTime;
@@ -82,11 +92,10 @@ public class RosPublisherExample : MonoBehaviour
8292

8393
- Add a plane and a cube to the empty Unity scene
8494
- Move the cube a little ways up so it is hovering above the plane
85-
- Create an empty GameObject, name it `RosConnection` and attach the `ROS TCP Connection/Runtime/TcpConnector/ROSConnection` script.
86-
- Change the host name and port to match the ROS IP and port variables defined when you set up ROS
95+
- In the main menu bar, open `Robotics/ROS Settings`.
96+
- Set the ROS IP address and port to match the ROS IP and port variables defined when you set up ROS.
8797
- Create another empty GameObject, name it `RosPublisher` and attach the `RosPublisherExample` script.
88-
- Drag the cube GameObject onto the `Cube` parameter
89-
- Drag the RosConnection object onto its `Ros` parameter.
98+
- Drag the cube GameObject onto the `Cube` parameter.
9099

91100
- Pressing play in the Editor should publish a message to the terminal running the `rostopic echo pos_rot` command every 0.5 seconds
92101

tutorials/ros_unity_integration/service.md

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Create a simple Unity scene which calls a [ROS service](http://wiki.ros.org/Serv
44

55
## Setting Up ROS
66

7-
(You can skip this if you already did the [ROS–Unity Integration Publisher](publisher.md) or [Subscriber](subscriber.md) tutorials.)
7+
(Skip to [Start the Position service](service.md#start-the-position-service) if you already did the [ROS–Unity Integration Publisher](publisher.md) or [Subscriber](subscriber.md) tutorials.)
88

99
- Copy the `tutorials/ros_packages/robotics_demo` folder of this repo into the `src` folder in your Catkin workspace.
1010

@@ -14,7 +14,7 @@ Create a simple Unity scene which calls a [ROS service](http://wiki.ros.org/Serv
1414

1515
```bash
1616
source devel/setup.bash
17-
rosrun robotics_demo server_endpoint.py
17+
rosrun robotics_demo server_endpoint.py
1818
```
1919

2020
Once the server_endpoint has started, it will print something similar to `[INFO] [1603488341.950794]: Starting server on 192.168.50.149:10000`.
@@ -24,16 +24,19 @@ Once the server_endpoint has started, it will print something similar to `[INFO]
2424

2525
```bash
2626
source devel/setup.bash
27-
rosrun robotics_demo position_service.py
27+
rosrun robotics_demo position_service.py
2828
```
2929

3030
## Setting Up Unity Scene
31-
- Generate the C# code for `PositionService`'s messages by going to `RosMessageGeneration` -> `AutoGenerateServices` -> `Single Service...`
32-
- Set the input file path to `PATH/TO/Unity-Robotics-Hub/tutorials/ros_packages/robotics_demo/srv/PositionService.srv` and click `GENERATE!`
33-
- The generated files will be saved in the default directory `Assets/RosMessages/srv`
31+
- Generate the C# code for `PositionService`'s messages by going to `Robotics` -> `Generate ROS Messages...`
32+
- Set the input file path to `PATH/TO/Unity-Robotics-Hub/tutorials/ros_packages/robotics_demo`, expand the robotics_demo folder and click `Build 1 srv`.
33+
34+
![](images/generate_messages_2.png)
35+
36+
- The generated files will be saved in the default directory `Assets/RosMessages/RoboticsDemo/srv`.
3437
- Create a script and name it `RosServiceExample.cs`
3538
- Paste the following code into `RosServiceExample.cs`
36-
- **Note** Script can be found at `tutorials/ros_unity_integration/unity_scripts`
39+
- **Note:** This script can be found at `tutorials/ros_unity_integration/unity_scripts`.
3740

3841
```csharp
3942
using System;
@@ -43,7 +46,7 @@ using Debug = UnityEngine.Debug;
4346

4447
public class RosServiceExample : MonoBehaviour
4548
{
46-
public ROSConnection ros;
49+
ROSConnection ros;
4750

4851
public string serviceName = "pos_srv";
4952

@@ -58,6 +61,7 @@ public class RosServiceExample : MonoBehaviour
5861

5962
void Start()
6063
{
64+
ros = ROSConnection.instance;
6165
destination = cube.transform.position;
6266
}
6367

@@ -98,10 +102,9 @@ public class RosServiceExample : MonoBehaviour
98102
}
99103
```
100104

101-
- Create an empty GameObject, name it `RosConnection`, and attach the `Plugins/TCPConnection/ROSConnection` script to it. (Or, if you're reusing the same scene from the previous tutorials, you can just keep the existing RosConnection object.)
102-
- In the Inspector window of the Editor change the `Host Name` variable on the `RosConnection` GameObject to the ROS IP.
103-
- Create another empty GameObject and name it `RosService`.
104-
- Attach the `RosServiceExample` script to the `RosService` GameObject. Drag the cube GameObject onto its `cube` parameter and the RosConnection GameObject onto its `Ros` parameter.
105+
- From the main menu bar, open `Robotics/ROS Settings`, and change the `ROS IP Address` variable to the ROS IP.
106+
- Create an empty GameObject and name it `RosService`.
107+
- Attach the `RosServiceExample` script to the `RosService` GameObject. Drag the cube GameObject onto its `cube` parameter.
105108
- Pressing play in the Editor should start communication with the `position_service` script, running as a ROS node, causing the cube to move to random positions in the scene.
106109

107110
![](images/tcp_3.gif)

tutorials/ros_unity_integration/setup.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,4 @@ Once ROS Core has started, it will print `started core service [/rosout]` to the
6262

6363
![](images/add_package_2.png)
6464

65-
Messages being passed between Unity and ROS need to be serialized exactly as ROS serializes them internally. This is achieved with the RosMessageGeneration utility, which generates C# classes, including serialization and deserialization functions, based on ROS message files. Adding the ROS TCP Connector package should have created a new Unity menu option, “RosMessageGeneration”, which we will use to generate these messages later.
65+
Messages being passed between Unity and ROS need to be serialized exactly as ROS serializes them internally. This is achieved with the RosMessageGeneration utility, which generates C# classes, including serialization and deserialization functions, based on ROS message files. Adding the ROS TCP Connector package should have created a new Unity menu option, “Robotics/Generate ROS Messages”, which we will use to generate these messages later.

tutorials/ros_unity_integration/subscriber.md

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22

33
Create a simple Unity scene which subscribes to a [ROS topic](http://wiki.ros.org/ROS/Tutorials/UnderstandingTopics#ROS_Topics) to change the colour of a GameObject.
44

5-
**NOTE:** If following from [Publisher](publisher.md) tutorial proceed to [Setting Up Unity Scene](subscriber.md#setting-up-unity-scene) step.
6-
75
## Setting Up ROS
86

9-
(You can skip this if you already did the [ROS–Unity Integration Publisher](publisher.md) tutorial.)
7+
(Skip to [Setting Up Unity Scene](subscriber.md#setting-up-unity-scene) if you already did the [Publisher](publisher.md) tutorial.)
108

119
- Copy the `tutorials/ros_packages/robotics_demo` folder of this repo into the `src` folder in your Catkin workspace.
1210

@@ -16,31 +14,34 @@ Create a simple Unity scene which subscribes to a [ROS topic](http://wiki.ros.or
1614

1715
```bash
1816
source devel/setup.bash
19-
rosrun robotics_demo server_endpoint.py
17+
rosrun robotics_demo server_endpoint.py
2018
```
2119

2220
Once the server_endpoint has started, it will print something similar to `[INFO] [1603488341.950794]: Starting server on 192.168.50.149:10000`.
2321

22+
- In Unity, we need to generate the C# code for the `UnityColor` message. Open `Robotics` -> `Generate ROS Messages...`.
23+
- Set the ROS message path to `PATH/TO/Unity-Robotics-Hub/tutorials/ros_packages/robotics_demo/`, expand the robotics_demo subfolder and click `Build 2 msgs`.
24+
25+
![](images/generate_messages_1.png)
26+
27+
- The generated files will be saved in the default directory `Assets/RosMessages/RoboticsDemo/msg`.
28+
2429
## Setting Up Unity Scene
25-
- Generate the C# code for `UnityColor` message by going to `RosMessageGeneration` -> `AutoGenerateMessages` -> `Single Message...`
26-
- Set the input file path to `PATH/TO/Unity-Robotics-Hub/tutorials/ros_packages/robotics_demo/msg/UnityColor.msg` and click `GENERATE!`
27-
- The generated file will be saved in the default directory `Assets/RosMessages/msg`
2830
- Create a script and name it `RosSubscriberExample.cs`
2931
- Paste the following code into `RosSubscriberExample.cs`
30-
- **Note** Script can be found at `tutorials/ros_unity_integration/unity_scripts`
32+
- **Note** Script can be found at `tutorials/ros_unity_integration/unity_scripts`
3133

3234
```csharp
3335
using UnityEngine;
3436
using RosColor = RosMessageTypes.RoboticsDemo.UnityColor;
3537

3638
public class RosSubscriberExample : MonoBehaviour
3739
{
38-
public ROSConnection ros;
3940
public GameObject cube;
4041

4142
void Start()
4243
{
43-
ros.Subscribe<RosColor>("color", ColorChange);
44+
ROSConnection.instance.Subscribe<RosColor>("color", ColorChange);
4445
}
4546

4647
void ColorChange(RosColor colorMessage)
@@ -50,14 +51,15 @@ public class RosSubscriberExample : MonoBehaviour
5051
}
5152
```
5253

53-
- Create an empty GameObject, name it `RosConnection` and attach the `Packages/ROS TCP Connection/Runtime/TcpConnector/ROSConnection` script. (Or, if you're reusing the same scene from the Publisher tutorial, you can just keep the existing RosConnection object.)
54-
- Change the host name and port to match the ROS IP and port variables defined when you set up ROS.
55-
- The IP for Unity to listen on should be determined automatically, but if you're having trouble, you can set it manually in the `Override Unity IP` field. Finding the IP address of your local machine (the one running Unity) depends on your operating system.
56-
- On a Mac, open `System Preferences > Network`. Your IP address should be listed on the active connection.
57-
- On Windows, click the Wi-Fi icon on the taskbar, and open `Properties`. Your IP address should be listed near the bottom, next to "IPv4 address."
58-
5954
- Create an empty GameObject and name it `RosSubscriber`
60-
- Attach the `RosSubscriberExample` script to the `RosSubscriber` GameObject, drag the cube GameObject onto the `cube` parameter in the Inspector window and the `RosConnection` object onto the `ros` parameter.
55+
- Attach the `RosSubscriberExample` script to the `RosSubscriber` GameObject and drag the cube GameObject onto the `cube` parameter in the Inspector window.
56+
57+
- From the Unity menu bar, open `Robotics/ROS Settings`, and set the `ROS IP Address` variable to your ROS IP.
58+
- Unlike the previous tutorial, using a subscriber requires an incoming connection from ROS to Unity. You may need to adjust your firewall settings for this to work.
59+
- The IP for Unity to listen on should be determined automatically, but if you're having trouble, you can set it manually in the `Override Unity IP` field. Finding the IP address of your local machine (the one running Unity) depends on your operating system.
60+
- On a Mac, open `System Preferences > Network`. Your IP address should be listed on the active connection.
61+
- On Windows, click the Wi-Fi icon on the taskbar, and open `Properties`. Your IP address should be listed near the bottom, next to "IPv4 address."
62+
6163
- Press play in the editor
6264

6365
### In ROS Terminal Window

tutorials/ros_unity_integration/unity_scripts/RosPublisherExample.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
/// </summary>
88
public class RosPublisherExample : MonoBehaviour
99
{
10-
public ROSConnection ros;
10+
ROSConnection ros;
1111
public string topicName = "pos_rot";
1212

1313
// The game object
@@ -17,6 +17,12 @@ public class RosPublisherExample : MonoBehaviour
1717

1818
// Used to determine how much time has elapsed since the last message was published
1919
private float timeElapsed;
20+
21+
void Start()
22+
{
23+
// start the ROS connection
24+
ros = ROSConnection.instance;
25+
}
2026

2127
private void Update()
2228
{

tutorials/ros_unity_integration/unity_scripts/RosServiceExample.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
public class RosServiceExample : MonoBehaviour
77
{
8-
public ROSConnection ros;
8+
ROSConnection ros;
99

1010
public string serviceName = "pos_srv";
1111

@@ -20,6 +20,7 @@ public class RosServiceExample : MonoBehaviour
2020

2121
void Start()
2222
{
23+
ros = ROSConnection.instance;
2324
destination = cube.transform.position;
2425
}
2526

tutorials/ros_unity_integration/unity_scripts/RosSubscriberExample.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33

44
public class RosSubscriberExample : MonoBehaviour
55
{
6-
public ROSConnection ros;
76
public GameObject cube;
87

98
void Start()
109
{
11-
ros.Subscribe<RosColor>("color", ColorChange);
10+
ROSConnection.instance.Subscribe<RosColor>("color", ColorChange);
1211
}
1312

1413
void ColorChange(RosColor colorMessage)

0 commit comments

Comments
 (0)