-
Notifications
You must be signed in to change notification settings - Fork 0
2a. URDF Import with ROS#
ROS# is a set of libraries that enables the communication between ROS and Unity.
A more elaborate tutorial on this part can be found at the ROS# github wiki.
- Install the latest version of Unity.
- Create a new 3D project.
- In the new project, go to
File > Build Settings ... > Player Settings... > Other Settings > Configuration
and change theApi compatibility level
to.NET 4.x
- Copy the RosSharp folder from the latest commit of the ROS# repository into the Assets folder of your Unity project.
- 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.
- 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. - Copy the panda_arm.urdf file from the home directory of the Ubuntu VM to Windows.
- In the Windows environment, download the franka_ros repository.
- Open the Unity 3D project.
- In the Assets folder of the Unity 3D project, create a new folder called "URDF".
- Move the franka_description folder located in
franka_ros
to the newly created URDF folder. - Move the panda_arm.urdf file from the wherever it is located to the URDF folder.
- 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.
- Right click the panda_arm.urdf file and select
Import Robot from URDF
. - You should now see the "panda" game object in the Hierarchy pane.
- 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. - Again in the Hierarchy pane, right click and select
3D 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.
- 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 typinghostname -I
in the terminal of the Ubuntu VM.
- 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
- 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)
- 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.