Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
b6dcedd
Adding Ros2 instructions, restructuring a little
LaurieCheers-unity May 27, 2021
3eac860
Updating tutorials, work in progress
LaurieCheers-unity May 28, 2021
bb2eb7d
Tutorials updated
LaurieCheers-unity May 31, 2021
2f8d083
Package setup
LaurieCheers-unity May 31, 2021
6cba99e
All working. In ROS2 at least. I hope.
LaurieCheers-unity Jun 1, 2021
a4bca1f
Updated to make ros1 work
LaurieCheers-unity Jun 1, 2021
d8a4bc3
Remove RegisterSubscriber call
LaurieCheers-unity Jun 3, 2021
7d90f33
Fixed setup
LaurieCheers-unity Jun 3, 2021
5b526f6
Fix text
LaurieCheers-unity Jun 3, 2021
449ca3a
Remove C build references from CMakeLists.txt
LaurieCheers-unity Jun 3, 2021
af17567
Source before build
LaurieCheers-unity Jun 4, 2021
33436e0
Merge branch 'dev' into laurie/Ros2Update
LaurieCheers-unity Jun 4, 2021
11cbd4a
Submodule?
LaurieCheers-unity Jun 4, 2021
3b25e13
Updated to use new message names
LaurieCheers-unity Jun 4, 2021
3ecaad5
Added an extra source instruction
LaurieCheers-unity Jun 4, 2021
f82d7d0
Remove old register line
LaurieCheers-unity Jun 4, 2021
f244652
Reordered the ros-unity tutorial to do Unity Service before Service, …
LaurieCheers-unity Jun 4, 2021
331f425
Remove references to ros2_tcp_endpoint
LaurieCheers-unity Jun 9, 2021
28af8b2
Add ROS2 docker with a ROS-TCP-Endpoint submodule
LaurieCheers-unity Jun 9, 2021
43946b9
Added ros2 dockerfile to tutorial
LaurieCheers-unity Jun 9, 2021
eeb7eb5
"git submodule update"
LaurieCheers-unity Jun 9, 2021
b79a295
Remove reference to deleted section
LaurieCheers-unity Jun 9, 2021
6d042d1
White background for ros2 icon
LaurieCheers-unity Jun 9, 2021
37ad14b
"git submodule init"
LaurieCheers-unity Jun 9, 2021
4ff8dbb
"Note" instead of NB
LaurieCheers-unity Jun 9, 2021
08e5bba
Feedback
LaurieCheers-unity Jun 9, 2021
aff6e31
Misc feedback
LaurieCheers-unity Jun 9, 2021
c14d890
Added ROS1 icon
LaurieCheers-unity Jun 9, 2021
0ddf54e
More Ros1 icons, RosServiceExample -> RosServiceCallExample
LaurieCheers-unity Jun 9, 2021
d4e22f8
Testing formatting
LaurieCheers-unity Jun 9, 2021
d88afb7
ROS1 Dockerfile work in progress
LaurieCheers-unity Jun 10, 2021
726eabf
Bug bash feedback
LaurieCheers-unity Jun 10, 2021
c6a553c
Working dockerfile for ROS1
LaurieCheers-unity Jun 15, 2021
20c04b8
ROS2 dockerfile does git clone
LaurieCheers-unity Jun 15, 2021
2acca9c
Added notes about config file
LaurieCheers-unity Jun 15, 2021
616f429
Minor fixes
LaurieCheers-unity Jun 15, 2021
5fb326a
Run pre-commit hook
LaurieCheers-unity Jun 15, 2021
d166e77
Point the package string to the correct branch for now
LaurieCheers-unity Jun 16, 2021
b70b455
Tutorial references dev branch
LaurieCheers-unity Jun 21, 2021
c071354
Update publisher.md
LaurieCheers-unity Jun 21, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ public class Demo : MonoBehaviour
string rosConnectName = "ROSConnect";
string publisherName = "Publisher";
int hostPort = 10000;
int unityPort = 5005;
int awaitDataMaxRetries = 10;
int awaitDataSleepSeconds = 1;

string trajectoryPlannerType = "TrajectoryPlanner";
string rosServiceName = "niryo_moveit";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void Start()

public void Publish()
{
MNiryoMoveitJoints sourceDestinationMessage = new MNiryoMoveitJoints();
NiryoMoveitJointsMsg sourceDestinationMessage = new NiryoMoveitJointsMsg();

sourceDestinationMessage.joint_00 = jointArticulationBodies[0].xDrive.target;
sourceDestinationMessage.joint_01 = jointArticulationBodies[1].xDrive.target;
Expand All @@ -62,14 +62,14 @@ public void Publish()
sourceDestinationMessage.joint_05 = jointArticulationBodies[5].xDrive.target;

// Pick Pose
sourceDestinationMessage.pick_pose = new MPose
sourceDestinationMessage.pick_pose = new PoseMsg
{
position = target.transform.position.To<FLU>(),
orientation = Quaternion.Euler(90, target.transform.eulerAngles.y, 0).To<FLU>()
};

// Place Pose
sourceDestinationMessage.place_pose = new MPose
sourceDestinationMessage.place_pose = new PoseMsg
{
position = targetPlacement.transform.position.To<FLU>(),
orientation = pickOrientation.To<FLU>()
Expand Down
16 changes: 8 additions & 8 deletions tutorials/pick_and_place/Scripts/TrajectoryPlanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ private void OpenGripper()
/// Get the current values of the robot's joint angles.
/// </summary>
/// <returns>NiryoMoveitJoints</returns>
MNiryoMoveitJoints CurrentJointConfig()
NiryoMoveitJointsMsg CurrentJointConfig()
{
MNiryoMoveitJoints joints = new MNiryoMoveitJoints();
NiryoMoveitJointsMsg joints = new NiryoMoveitJointsMsg();

joints.joint_00 = jointArticulationBodies[0].xDrive.target;
joints.joint_01 = jointArticulationBodies[1].xDrive.target;
Expand All @@ -101,28 +101,28 @@ MNiryoMoveitJoints CurrentJointConfig()
/// </summary>
public void PublishJoints()
{
MMoverServiceRequest request = new MMoverServiceRequest();
MoverServiceRequest request = new MoverServiceRequest();
request.joints_input = CurrentJointConfig();

// Pick Pose
request.pick_pose = new MPose
request.pick_pose = new PoseMsg
{
position = (target.transform.position + pickPoseOffset).To<FLU>(),
// The hardcoded x/z angles assure that the gripper is always positioned above the target cube before grasping.
orientation = Quaternion.Euler(90, target.transform.eulerAngles.y, 0).To<FLU>()
};

// Place Pose
request.place_pose = new MPose
request.place_pose = new PoseMsg
{
position = (targetPlacement.transform.position + pickPoseOffset).To<FLU>(),
orientation = pickOrientation.To<FLU>()
};

ros.SendServiceMessage<MMoverServiceResponse>(rosServiceName, request, TrajectoryResponse);
ros.SendServiceMessage<MoverServiceResponse>(rosServiceName, request, TrajectoryResponse);
}

void TrajectoryResponse(MMoverServiceResponse response)
void TrajectoryResponse(MoverServiceResponse response)
{
if (response.trajectories.Length > 0)
{
Expand All @@ -149,7 +149,7 @@ void TrajectoryResponse(MMoverServiceResponse response)
/// </summary>
/// <param name="response"> MoverServiceResponse received from niryo_moveit mover service running in ROS</param>
/// <returns></returns>
private IEnumerator ExecuteTrajectories(MMoverServiceResponse response)
private IEnumerator ExecuteTrajectories(MoverServiceResponse response)
{
if (response.trajectories != null)
{
Expand Down
4 changes: 2 additions & 2 deletions tutorials/pick_and_place/docker/set-up-workspace
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

source /opt/ros/melodic/setup.bash
echo "ROS_IP: $(hostname -i)" > $ROS_WORKSPACE/src/niryo_moveit/config/params.yaml
echo "ROS_IP: $(hostname -i)" > $ROS_WORKSPACE/src/ros-tcp-endpoint/config/params.yaml
cd $ROS_WORKSPACE
catkin_make
catkin_make
32 changes: 0 additions & 32 deletions tutorials/ros_packages/robotics_demo/scripts/color_publisher.py

This file was deleted.

32 changes: 0 additions & 32 deletions tutorials/ros_packages/robotics_demo/scripts/object_pose_client.py

This file was deleted.

27 changes: 0 additions & 27 deletions tutorials/ros_packages/robotics_demo/scripts/server_endpoint.py

This file was deleted.

17 changes: 8 additions & 9 deletions tutorials/ros_unity_integration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@ The `ROSConnection` plugin (also from [ROS TCP Connector](https://github.com/Uni


## Tutorials
- [ROS–Unity Integration: Initial Setup](setup.md) - ROS-Unity Initial Setup
- [ROS–Unity Integration: Initial Setup](setup.md) - ROSUnity Initial Setup
- [ROS–Unity Integration: Network Description](network.md) - Description of network settings and troubleshooting
- [ROS–Unity Integration: Publisher](publisher.md) - Adding a Publisher to a Unity Scene
- [ROS–Unity Integration: Subscriber](subscriber.md) - Adding a Subscriber to a Unity Scene
- [ROS–Unity Integration: Service](service.md) - Adding a Service call to a Unity Scene
- [ROS–Unity Integration: UnityService](unity_service.md) - Adding a Service that runs in a Unity Scene
- [ROS–Unity Integration: Server Endpoint](server_endpoint.md) - How to write a Server Endpoint
- [ROS–Unity Integration: Publisher](publisher.md) - Publish messages from a Unity Scene
- [ROS–Unity Integration: Subscriber](subscriber.md) - Subscribe to receive messages in a Unity Scene
- [ROS–Unity Integration: Unity Service](unity_service.md) - Implement a service inside a Unity Scene
- [ROS–Unity Integration: Service Call](service_call.md) - Call an external service from a Unity Scene

## Example Unity Scripts

Expand All @@ -32,9 +31,9 @@ Example scripts implemented in tutorials:
- `unity_scripts/RosSubscriberExample.cs`
- Subscribes to a topic that accepts color messages and uses them to change the color of a GameObject in the Unity scene.

- `unity_scripts/RosServiceExample.cs`
- Returns a destination position for a GameObject to move towards each time the service is called.

- `unity_scripts/RosUnityServiceExample.cs`
- Runs a service in the Unity scene that takes a GameObject's name and responds with the Pose of that object.

- `unity_scripts/RosServiceExample.cs`
- Returns a destination position for a GameObject to move towards each time the service is called.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 1 addition & 12 deletions tutorials/ros_unity_integration/network.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

`ROS_IP` : The IP address of the machine, VM, or container running ROS.

`UNITY_IP` : The IP address of the machine running Unity.

> It is possible to set both of these variables on the machines running Unity and ROS. The specifics of where and why each of these settings will be described below.

On the ROS machine these settings are set as a rosparam and will typically be set in a launch file like [this](https://github.com/Unity-Technologies/Unity-Robotics-Hub/blob/main/tutorials/ros_packages/robotics_demo/launch/robo_demo.launch) or in a [param file](https://github.com/Unity-Technologies/Unity-Robotics-Hub/blob/main/tutorials/pick_and_place/ROS/src/niryo_moveit/config/params.yaml) loaded by a launch file like [this](https://github.com/Unity-Technologies/Unity-Robotics-Hub/blob/main/tutorials/pick_and_place/ROS/src/niryo_moveit/launch/part_3.launch#L2). The param file can also be loaded manually by running the `rosparam load params.yaml` command.
Expand All @@ -37,19 +35,10 @@ The container will need to be started with the following arguments to forward th

- On the ROS side, set `ROS_IP` to `0.0.0.0`.

- On the Unity side, set `ROS_IP` to `127.0.0.1` and the `Override Unity IP Address` to your local machine's IP address.
- On the Unity side, set `ROS_IP` to `127.0.0.1`.

![](images/troubleshoot-docker-unity.png)

## Explicitly setting `UNITY_IP`

The `UNITY_IP` can be set in two different places.

1. If set on the ROS side as a rosparam, the `server_endpoint` will only use this IP to send messages to Unity.
1. If set on the Unity side as the `Override Unity IP Address`, the `UNITY_IP` on the ROS side will be set to this value during the initial handshake between ROS and Unity once play is pressed in the Editor.

> If the `UNITY_IP` is not set in either of these places, then the IP that makes the first connection to ROS during the initial handshake will be used.

# Troubleshooting

## Where Does Communication Break Down
Expand Down
85 changes: 48 additions & 37 deletions tutorials/ros_unity_integration/publisher.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,20 @@

Create a simple Unity scene which publishes a GameObject's position and rotation to a [ROS topic](http://wiki.ros.org/ROS/Tutorials/UnderstandingTopics#ROS_Topics).

## Setting Up ROS
These instructions cover the setup for both ROS1 and ROS2. Instructions for ROS2 users are marked with this icon: <img src="images/ros2_icon.png" alt="ros2" width="23" height="14"/>.

- Copy the `tutorials/ros_packages/robotics_demo` folder of this repo into the `src` folder in your Catkin workspace.
## Setting Up

- Follow the [ROS–Unity Initial Setup](setup.md) guide.
- Follow the [ROS–Unity Demo Setup](setup.md#ros2-environment) guide.

- Open a new terminal window and run the following commands:

```bash
source devel/setup.bash
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`.

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

## Setting Up Unity Scene
- 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`.
- Create a new directory in `Assets` and name it `Scripts`
- Create a new script in the `Scripts` directory and name it `RosPublisherExample.cs`
- Open `RosPublisherExample.cs` and paste the following code:
- **Note** Script can be found at `tutorials/ros_unity_integration/unity_scripts`
## Create Unity Publisher
- In your Project tab in Unity, create a new C# script and name it `RosPublisherExample`. Paste the following code into the new script file.
- (Alternatively, you can drag the script file into Unity from `tutorials/ros_unity_integration/unity_scripts/RosPublisherExample.cs` in this repo.)

```csharp
using RosMessageTypes.RoboticsDemo;
using UnityEngine;
using Unity.Robotics.ROSTCPConnector;
using RosMessageTypes.UnityRoboticsDemo;

/// <summary>
///
Expand All @@ -61,6 +37,7 @@ public class RosPublisherExample : MonoBehaviour
{
// start the ROS connection
ros = ROSConnection.instance;
ros.RegisterPublisher<PosRotMsg>(topicName);
}

private void Update()
Expand All @@ -71,7 +48,7 @@ public class RosPublisherExample : MonoBehaviour
{
cube.transform.rotation = Random.rotation;

MPosRot cubePos = new MPosRot(
PosRotMsg cubePos = new PosRotMsg(
cube.transform.position.x,
cube.transform.position.y,
cube.transform.position.z,
Expand All @@ -90,14 +67,48 @@ public class RosPublisherExample : MonoBehaviour
}
```

- 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
- 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.
- Add a plane and a cube to your Unity scene. You can create simple geometric shapes in Unity by going to the Hierarchy window, clicking the + button, and navigating to the shape you want to create.

![](images/create_cube.png)

- Move the cube a little ways up so it is hovering above the plane. To do this, select the cube in the hierarchy window, and click on the move tool in the toolbar at the top left of the Unity window.

![](images/move_tool.png)

- Draggable arrows will appear around the cube in the Scene view; to move the cube up, drag the vertical (green) arrow upwards.

- Create another empty GameObject, name it `RosPublisher` and attach the `RosPublisherExample` script.
- 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
- Press play in the Editor. You should see the connection lights at the top left corner of the Game window turn blue, and something like `[INFO] [1622242057.562860400] [TCPServer]: Connection from 172.17.0.1` appear in the terminal running your server_endpoint.

## Common Errors

If you see the error `Failed to resolve message name: No module named unity_robotics_demo_msgs.msg` followed by `Topic 'pos_rot' is not registered` in the ROS-TCP-Endpoint log, you may have missed the step about installing the unity_robotics_demo_msgs package, or perhaps you forgot to build and/or source it afterwards. Try following the "Install Unity Robotics Demo" instructions [here](setup.md#install-unity-robotics-demo).

## Start the Echo monitor

- To prove that messages are actually being received by ROS, let's run the rostopic echo command.

a) <img src="images/ros1_icon.png" alt="ros1" width="14" height="14"/> In ROS1, open a new terminal window, navigate to your ROS workspace, and run the following commands:

```bash
source devel/setup.bash
rostopic echo pos_rot
```

b) <img src="images/ros2_icon.png" alt="ros2" width="23" height="14"/> In ROS2, the commands to run are

```bash
source install/setup.bash
ros2 topic echo pos_rot
```

- If you're using Docker, you can use the command `docker ps` to get a list of all running containers; `docker exec -ti bash <container name> bash` starts a new terminal for the specified container. Alternatively, click the "CLI" button in the Docker UI to open a new terminal ("command line interface").

![](images/docker_cli.png)

- If it's working correctly, you should see the contents of the message Unity is sending appearing every 0.5 seconds.

> Please reference [networking troubleshooting](network.md) doc if any errors are thrown.

Expand Down
Loading