Skip to content

2a. URDF Import with ROS#

Erencan edited this page Apr 15, 2022 · 1 revision

ROS# is a set of libraries that enables the communication between ROS and Unity.

Setting up Unity

A more elaborate tutorial on this part can be found at the ROS# github wiki.

  1. Install the latest version of Unity.
  2. Create a new 3D project.
  3. In the new project, go to File > Build Settings ... > Player Settings... > Other Settings > Configuration and change the Api compatibility level to .NET 4.x
  4. Copy the RosSharp folder from the latest commit of the ROS# repository into the Assets folder of your Unity project.

Importing the URDF File

  1. In Ubuntu, open up a terminal window and install the necessary packages by running the code sudo apt install ros-noetic-libfranka ros-noetic-franka-ros.

The files in the repository are in the .urdf.xacro format and need to be converted into the .urdf format in order for the URDF importer in Unity to work.

  1. In a terminal window, execute rosrun xacro xacro $(rospack find franka_description)/robots/panda_arm.urdf.xacro gazebo:=true hand:=true> panda_arm.urdf which should create the aforementioned .urdf file in the home directory of the Ubuntu VM.
  2. Copy the panda_arm.urdf file from the home directory of the Ubuntu VM to Windows.
  3. In the Windows environment, download the franka_ros repository.
  4. Open the Unity 3D project.
  5. In the Assets folder of the Unity 3D project, create a new folder called "URDF".
  6. Move the franka_description folder located in franka_ros to the newly created URDF folder.
  7. Move the panda_arm.urdf file from the wherever it is located to the URDF folder.
  8. In the project window of Unity open the URDF folder which should now contain the panda_arm.urdf file and the franka_description folder from the franka_ros repository.
  9. Right click the panda_arm.urdf file and select Import Robot from URDF.
  10. You should now see the "panda" game object in the Hierarchy pane.

Setting up the ROS Connection

  1. In the Unity environment, right click on the Hierarchy pane and select Create Empty to create an empty game object. This game object will be the ROS Connector that will handle the all the communication between ROS and Unity. Rename it to ROS Connector.
  2. Again in the Hierarchy pane, right click and select3D Object > Cube. This game object will be the target pose that will be subscribed by the gazebo script in the next section. Rename the object to Target Cube

The ROS Connector will serve three purposes in this project:

  • Establish the connection
  • Subscribe to the joint states of the robot simulation running on Ubuntu with ROS. This way, the robot's movements are seen without having to configure inverse kinematics in Unity.
  • Publish the pose data of the target that will be subscribed to by the gazebo script in the next section.
  1. Click on the ROS Connector game object. In the Inspector pane, click Add Component, type and add "Ros Connector". The settings of the connector are listed below:

i. Serializer > Microsoft

ii. Protocol > Web Socket NET

iii. Ros Bridge Server Url > ws://vm_ip_address:9090

You can find the vm_ip_address by typing hostname -I in the terminal of the Ubuntu VM.

  1. Click on the ROS Connector game object. In the Inspector pane, click Add Component, type and add "Joint State Subscriber". The settings of the state subscriber are listed below:

Topic > /joint_states

  1. Click on the ROS Connector game object. In the Inspector pane, click Add Component, type and add "Joint State Patcher". The settings of the state patcher are listed below:

Urdf Robot > panda (you can drag and drop the panda object into the field or select the panda object by clicking the field)

  1. Click on the Target Cube game object. In the inspector pane, click Add Component, type and add "Pose Stamped Publisher". The settings of the pose publisher are listed below:

i. Topic > /cartesian_impedance_example_controller/equilibrium_pose

ii. Published Transform > Target Cube (you can drag and drop the cube object into the field or select the cube object by clicking the field)

iii. Frame Id > panda_link0

Now that the ROS Connector is established, whenever the ROS Bridge Websocket in Ubuntu is run and Play in the Unity toolbar is clicked, the Unity project will try to subscribe to the robot's states published with the topic /joint_states and the target cube's pose data will be subscribed to by the topic /cartesian_impedance_example_controller/equilibrium_pose, which is a topic that's created in the gazebo script explained in the following section.

Target Tracking