浏览代码

Laurie/release tutorial fixes (#94)

/devin-main-fix
GitHub 4 年前
当前提交
a78d843a
共有 9 个文件被更改,包括 609 次插入45 次删除
  1. 31
      tutorials/ros_unity_integration/publisher.md
  2. 27
      tutorials/ros_unity_integration/service.md
  3. 2
      tutorials/ros_unity_integration/setup.md
  4. 36
      tutorials/ros_unity_integration/subscriber.md
  5. 8
      tutorials/ros_unity_integration/unity_scripts/RosPublisherExample.cs
  6. 3
      tutorials/ros_unity_integration/unity_scripts/RosServiceExample.cs
  7. 3
      tutorials/ros_unity_integration/unity_scripts/RosSubscriberExample.cs
  8. 265
      tutorials/ros_unity_integration/images/generate_messages_1.png
  9. 279
      tutorials/ros_unity_integration/images/generate_messages_2.png

31
tutorials/ros_unity_integration/publisher.md


```bash
source devel/setup.bash
rosrun robotics_demo server_endpoint.py
rosrun robotics_demo server_endpoint.py
```
Once the server_endpoint has started, it will print something similar to `[INFO] [1603488341.950794]: Starting server on 192.168.50.149:10000`.

source devel/setup.bash
rostopic echo pos_rot
rostopic echo pos_rot
- In the menu bar, find and select `RosMessageGeneration` -> `Auto Generate Messages` -> `Single Message ...`
- Set the input file path to `PATH/TO/Unity-Robotics-Hub/tutorials/ros_packages/robotics_demo/msg/PosRot.msg ` and click `GENERATE!`
- The generated file will be saved in the default directory `Assets/RosMessages/msg`
- In the menu bar, find and select `Robotics` -> `Generate ROS Messages...`
- 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" to generate new C# scripts from the ROS .msg files.
![](images/generate_messages_1.png)
- The generated files will be saved in the default directory `Assets/RosMessages/RoboticsDemo/msg`.
- **Note** Script can be found at `tutorials/ros_unity_integration/unity_scripts`
- **Note** Script can be found at `tutorials/ros_unity_integration/unity_scripts`
```csharp
using RosMessageTypes.RoboticsDemo;

/// </summary>
public class RosPublisherExample : MonoBehaviour
{
public ROSConnection ros;
ROSConnection ros;
public string topicName = "pos_rot";
// The GameObject

// Used to determine how much time has elapsed since the last message was published
private float timeElapsed;
void Start()
{
// start the ROS connection
ros = ROSConnection.instance;
}
private void Update()
{

- Add a plane and a cube to the empty Unity scene
- Move the cube a little ways up so it is hovering above the plane
- Create an empty GameObject, name it `RosConnection` and attach the `ROS TCP Connection/Runtime/TcpConnector/ROSConnection` script.
- Change the host name and port to match the ROS IP and port variables defined when you set up ROS
- In the main menu bar, open `Robotics/ROS Settings`.
- Set the ROS IP address and port to match the ROS IP and port variables defined when you set up ROS.
- Drag the cube GameObject onto the `Cube` parameter
- Drag the RosConnection object onto its `Ros` parameter.
- Drag the cube GameObject onto the `Cube` parameter.
- Pressing play in the Editor should publish a message to the terminal running the `rostopic echo pos_rot` command every 0.5 seconds

27
tutorials/ros_unity_integration/service.md


## Setting Up ROS
(You can skip this if you already did the [ROS–Unity Integration Publisher](publisher.md) or [Subscriber](subscriber.md) tutorials.)
(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.)
- Copy the `tutorials/ros_packages/robotics_demo` folder of this repo into the `src` folder in your Catkin workspace.

```bash
source devel/setup.bash
rosrun robotics_demo server_endpoint.py
rosrun robotics_demo server_endpoint.py
```
Once the server_endpoint has started, it will print something similar to `[INFO] [1603488341.950794]: Starting server on 192.168.50.149:10000`.

```bash
source devel/setup.bash
rosrun robotics_demo position_service.py
rosrun robotics_demo position_service.py
- Generate the C# code for `PositionService`'s messages by going to `RosMessageGeneration` -> `AutoGenerateServices` -> `Single Service...`
- Set the input file path to `PATH/TO/Unity-Robotics-Hub/tutorials/ros_packages/robotics_demo/srv/PositionService.srv` and click `GENERATE!`
- The generated files will be saved in the default directory `Assets/RosMessages/srv`
- Generate the C# code for `PositionService`'s messages by going to `Robotics` -> `Generate ROS Messages...`
- 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`.
![](images/generate_messages_2.png)
- The generated files will be saved in the default directory `Assets/RosMessages/RoboticsDemo/srv`.
- **Note** Script can be found at `tutorials/ros_unity_integration/unity_scripts`
- **Note:** This script can be found at `tutorials/ros_unity_integration/unity_scripts`.
```csharp
using System;

public class RosServiceExample : MonoBehaviour
{
public ROSConnection ros;
ROSConnection ros;
public string serviceName = "pos_srv";

void Start()
{
ros = ROSConnection.instance;
destination = cube.transform.position;
}

}
```
- 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.)
- In the Inspector window of the Editor change the `Host Name` variable on the `RosConnection` GameObject to the ROS IP.
- Create another empty GameObject and name it `RosService`.
- Attach the `RosServiceExample` script to the `RosService` GameObject. Drag the cube GameObject onto its `cube` parameter and the RosConnection GameObject onto its `Ros` parameter.
- From the main menu bar, open `Robotics/ROS Settings`, and change the `ROS IP Address` variable to the ROS IP.
- Create an empty GameObject and name it `RosService`.
- Attach the `RosServiceExample` script to the `RosService` GameObject. Drag the cube GameObject onto its `cube` parameter.
- 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.
![](images/tcp_3.gif)

2
tutorials/ros_unity_integration/setup.md


![](images/add_package_2.png)
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.
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.

36
tutorials/ros_unity_integration/subscriber.md


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.
**NOTE:** If following from [Publisher](publisher.md) tutorial proceed to [Setting Up Unity Scene](subscriber.md#setting-up-unity-scene) step.
(You can skip this if you already did the [ROS–Unity Integration Publisher](publisher.md) tutorial.)
(Skip to [Setting Up Unity Scene](subscriber.md#setting-up-unity-scene) if you already did the [Publisher](publisher.md) tutorial.)
- Copy the `tutorials/ros_packages/robotics_demo` folder of this repo into the `src` folder in your Catkin workspace.

```bash
source devel/setup.bash
rosrun robotics_demo server_endpoint.py
rosrun robotics_demo server_endpoint.py
- In Unity, we need to generate the C# code for the `UnityColor` message. Open `Robotics` -> `Generate ROS Messages...`.
- 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`.
![](images/generate_messages_1.png)
- The generated files will be saved in the default directory `Assets/RosMessages/RoboticsDemo/msg`.
- Generate the C# code for `UnityColor` message by going to `RosMessageGeneration` -> `AutoGenerateMessages` -> `Single Message...`
- Set the input file path to `PATH/TO/Unity-Robotics-Hub/tutorials/ros_packages/robotics_demo/msg/UnityColor.msg` and click `GENERATE!`
- The generated file will be saved in the default directory `Assets/RosMessages/msg`
- **Note** Script can be found at `tutorials/ros_unity_integration/unity_scripts`
- **Note** Script can be found at `tutorials/ros_unity_integration/unity_scripts`
```csharp
using UnityEngine;

{
public ROSConnection ros;
ros.Subscribe<RosColor>("color", ColorChange);
ROSConnection.instance.Subscribe<RosColor>("color", ColorChange);
}
void ColorChange(RosColor colorMessage)

}
```
- 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.)
- Change the host name and port to match the ROS IP and port variables defined when you set up ROS.
- 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.
- On a Mac, open `System Preferences > Network`. Your IP address should be listed on the active connection.
- 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."
- 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.
- Attach the `RosSubscriberExample` script to the `RosSubscriber` GameObject and drag the cube GameObject onto the `cube` parameter in the Inspector window.
- From the Unity menu bar, open `Robotics/ROS Settings`, and set the `ROS IP Address` variable to your ROS IP.
- 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.
- 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.
- On a Mac, open `System Preferences > Network`. Your IP address should be listed on the active connection.
- 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."
- Press play in the editor
### In ROS Terminal Window

8
tutorials/ros_unity_integration/unity_scripts/RosPublisherExample.cs


/// </summary>
public class RosPublisherExample : MonoBehaviour
{
public ROSConnection ros;
ROSConnection ros;
public string topicName = "pos_rot";
// The game object

// Used to determine how much time has elapsed since the last message was published
private float timeElapsed;
void Start()
{
// start the ROS connection
ros = ROSConnection.instance;
}
private void Update()
{

3
tutorials/ros_unity_integration/unity_scripts/RosServiceExample.cs


public class RosServiceExample : MonoBehaviour
{
public ROSConnection ros;
ROSConnection ros;
public string serviceName = "pos_srv";

void Start()
{
ros = ROSConnection.instance;
destination = cube.transform.position;
}

3
tutorials/ros_unity_integration/unity_scripts/RosSubscriberExample.cs


public class RosSubscriberExample : MonoBehaviour
{
public ROSConnection ros;
ros.Subscribe<RosColor>("color", ColorChange);
ROSConnection.instance.Subscribe<RosColor>("color", ColorChange);
}
void ColorChange(RosColor colorMessage)

265
tutorials/ros_unity_integration/images/generate_messages_1.png

之前 之后
宽度: 629  |  高度: 374  |  大小: 66 KiB

279
tutorials/ros_unity_integration/images/generate_messages_2.png

之前 之后
宽度: 629  |  高度: 374  |  大小: 66 KiB
正在加载...
取消
保存