Skip to content

Commit 0e34be9

Browse files
LaurieCheers-unitysdiao
authored andcommitted
Update tutorial text (#148)
1 parent 3c99f00 commit 0e34be9

File tree

2 files changed

+31
-19
lines changed

2 files changed

+31
-19
lines changed

tutorials/ros_unity_integration/publisher.md

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,46 +12,56 @@ 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;
3741
using UnityEngine;
38-
using Random = UnityEngine.Random;
42+
using Unity.Robotics.ROSTCPConnector;
3943

4044
/// <summary>
4145
///
4246
/// </summary>
4347
public class RosPublisherExample : MonoBehaviour
4448
{
45-
public ROSConnection ros;
49+
ROSConnection ros;
4650
public string topicName = "pos_rot";
4751

48-
// The GameObject
52+
// The game object
4953
public GameObject cube;
5054
// Publish the cube's position and rotation every N seconds
5155
public float publishMessageFrequency = 0.5f;
5256

5357
// Used to determine how much time has elapsed since the last message was published
5458
private float timeElapsed;
59+
60+
void Start()
61+
{
62+
// start the ROS connection
63+
ros = ROSConnection.instance;
64+
}
5565

5666
private void Update()
5767
{
@@ -82,14 +92,13 @@ 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

93102
![](images/tcp_1.gif)
94103

95-
Continue to the [ROS Subscriber](subscriber.md) tutorial.
104+
Continue to the [ROS Subscriber](subscriber.md) tutorial.

tutorials/ros_unity_integration/subscriber.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Create a simple Unity scene which subscribes to a [ROS topic](http://wiki.ros.or
1111
- Follow the [ROS–Unity Initial Setup](setup.md) guide.
1212

1313
- Open a new terminal window, navigate to your Catkin workspace, and run the following commands:
14-
14+
1515
```bash
1616
source devel/setup.bash
1717
rosrun robotics_demo server_endpoint.py
@@ -21,7 +21,7 @@ Once the server_endpoint has started, it will print something similar to `[INFO]
2121

2222
- In Unity, we need to generate the C# code for the `UnityColor` message. Open `Robotics` -> `Generate ROS Messages...`.
2323
- 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-
24+
2525
![](images/generate_messages_1.png)
2626

2727
- The generated files will be saved in the default directory `Assets/RosMessages/RoboticsDemo/msg`.
@@ -34,7 +34,7 @@ Once the server_endpoint has started, it will print something similar to `[INFO]
3434
```csharp
3535
using UnityEngine;
3636
using Unity.Robotics.ROSTCPConnector;
37-
using RosColor = RosMessageTypes.RoboticsDemo.MUnityColor;
37+
using RosColor = RosMessageTypes.RoboticsDemo.UnityColor;
3838

3939
public class RosSubscriberExample : MonoBehaviour
4040
{
@@ -56,13 +56,16 @@ public class RosSubscriberExample : MonoBehaviour
5656
- Attach the `RosSubscriberExample` script to the `RosSubscriber` GameObject and drag the cube GameObject onto the `cube` parameter in the Inspector window.
5757

5858
- From the Unity menu bar, open `Robotics/ROS Settings`, and set the `ROS IP Address` variable to your ROS IP.
59+
- 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.
60+
- 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.
61+
- On a Mac, open `System Preferences > Network`. Your IP address should be listed on the active connection.
62+
- 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."
63+
5964
- Press play in the editor
6065

6166
### In ROS Terminal Window
6267
- After the scene has entered Play mode, run the following command: `rosrun robotics_demo color_publisher.py` to change the color of the cube GameObject in Unity to a random color
6368

64-
> Please reference [networking troubleshooting](network.md) doc if any errors are thrown.
65-
6669
![](images/tcp_2.gif)
6770

6871
Continue to the [ROS–Unity Integration Service](service.md).

0 commit comments

Comments
 (0)