You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: tutorials/ros_unity_integration/service.md
+15-12Lines changed: 15 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ Create a simple Unity scene which calls a [ROS service](http://wiki.ros.org/Serv
4
4
5
5
## Setting Up ROS
6
6
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.)
8
8
9
9
- Copy the `tutorials/ros_packages/robotics_demo` folder of this repo into the `src` folder in your Catkin workspace.
10
10
@@ -14,7 +14,7 @@ Create a simple Unity scene which calls a [ROS service](http://wiki.ros.org/Serv
14
14
15
15
```bash
16
16
source devel/setup.bash
17
-
rosrun robotics_demo server_endpoint.py
17
+
rosrun robotics_demo server_endpoint.py
18
18
```
19
19
20
20
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]
24
24
25
25
```bash
26
26
source devel/setup.bash
27
-
rosrun robotics_demo position_service.py
27
+
rosrun robotics_demo position_service.py
28
28
```
29
29
30
30
## 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
+

35
+
36
+
- The generated files will be saved in the default directory `Assets/RosMessages/RoboticsDemo/srv`.
34
37
- Create a script and name it `RosServiceExample.cs`
35
38
- 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`.
37
40
38
41
```csharp
39
42
usingSystem;
@@ -43,7 +46,7 @@ using Debug = UnityEngine.Debug;
43
46
44
47
publicclassRosServiceExample : MonoBehaviour
45
48
{
46
-
publicROSConnectionros;
49
+
ROSConnectionros;
47
50
48
51
publicstringserviceName="pos_srv";
49
52
@@ -58,6 +61,7 @@ public class RosServiceExample : MonoBehaviour
58
61
59
62
voidStart()
60
63
{
64
+
ros=ROSConnection.instance;
61
65
destination=cube.transform.position;
62
66
}
63
67
@@ -98,10 +102,9 @@ public class RosServiceExample : MonoBehaviour
98
102
}
99
103
```
100
104
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.
105
108
- 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.
Copy file name to clipboardExpand all lines: tutorials/ros_unity_integration/setup.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -62,4 +62,4 @@ Once ROS Core has started, it will print `started core service [/rosout]` to the
62
62
63
63

64
64
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.
Copy file name to clipboardExpand all lines: tutorials/ros_unity_integration/subscriber.md
+19-17Lines changed: 19 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,11 +2,9 @@
2
2
3
3
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.
4
4
5
-
**NOTE:** If following from [Publisher](publisher.md) tutorial proceed to [Setting Up Unity Scene](subscriber.md#setting-up-unity-scene) step.
6
-
7
5
## Setting Up ROS
8
6
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.)
10
8
11
9
- Copy the `tutorials/ros_packages/robotics_demo` folder of this repo into the `src` folder in your Catkin workspace.
12
10
@@ -16,31 +14,34 @@ Create a simple Unity scene which subscribes to a [ROS topic](http://wiki.ros.or
16
14
17
15
```bash
18
16
source devel/setup.bash
19
-
rosrun robotics_demo server_endpoint.py
17
+
rosrun robotics_demo server_endpoint.py
20
18
```
21
19
22
20
Once the server_endpoint has started, it will print something similar to `[INFO] [1603488341.950794]: Starting server on 192.168.50.149:10000`.
23
21
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
+

26
+
27
+
- The generated files will be saved in the default directory `Assets/RosMessages/RoboticsDemo/msg`.
28
+
24
29
## 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`
28
30
- Create a script and name it `RosSubscriberExample.cs`
29
31
- 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`
@@ -50,14 +51,15 @@ public class RosSubscriberExample : MonoBehaviour
50
51
}
51
52
```
52
53
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
-
59
54
- 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."
0 commit comments