<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Simone Zandara</title>
    <description>The latest articles on DEV Community by Simone Zandara (@szandara).</description>
    <link>https://dev.to/szandara</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F596054%2F76d91621-31b0-429b-a300-58669eff9daa.jpeg</url>
      <title>DEV Community: Simone Zandara</title>
      <link>https://dev.to/szandara</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/szandara"/>
    <language>en</language>
    <item>
      <title>Robotics on WSL2 using ROS, Docker and Unity 3D (Part II)</title>
      <dc:creator>Simone Zandara</dc:creator>
      <pubDate>Tue, 16 Mar 2021 19:13:58 +0000</pubDate>
      <link>https://dev.to/szandara/robotics-on-wsl2-using-ros-docker-and-unity-3d-part-ii-4l45</link>
      <guid>https://dev.to/szandara/robotics-on-wsl2-using-ros-docker-and-unity-3d-part-ii-4l45</guid>
      <description>&lt;p&gt;&lt;em&gt;Not that this is the second part on how to setup ROS to work with WSL2 (&lt;a href="https://dev.to/szandara/robotics-on-wsl2-using-ros-docker-and-unity-3d-part-i-3752"&gt;Part I&lt;/a&gt;). However, the upcoming section would work in a full Linux setup as well.&lt;/em&gt; &lt;/p&gt;

&lt;h2&gt;
  
  
  Robotics for Unity
&lt;/h2&gt;

&lt;p&gt;There are several ways of using &lt;a href="https://unity.com/solutions/automotive-transportation-manufacturing/robotics" rel="noopener noreferrer"&gt;Unity for robotics&lt;/a&gt;. Robotics for Unity is a new field and support is still custom made. Most of the applications out there are proprietary software created by private companies and not easily accessible or configurable by others. &lt;a href="https://blogs.unity3d.com/2020/11/19/robotics-simulation-in-unity-is-as-easy-as-1-2-3/" rel="noopener noreferrer"&gt;ROS support&lt;/a&gt; has been recently introduced by Unity itself, and it is a fork from a previous library from Siemens' &lt;a href="https://github.com/siemens/ros-sharp" rel="noopener noreferrer"&gt;RosSharp&lt;/a&gt;. In my setup, I used the &lt;a href="https://github.com/Unity-Technologies/Unity-Robotics-Hub" rel="noopener noreferrer"&gt;Unity ROS library&lt;/a&gt; which works with the latest &lt;a href="https://docs.unity3d.com/2020.1/Documentation/ScriptReference/ArticulationBody.html" rel="noopener noreferrer"&gt;ArticulationBody&lt;/a&gt; types.&lt;/p&gt;

&lt;p&gt;For this demo project I have chosen a cute robotic manipulator which is open sourced: &lt;a href="https://www.pollen-robotics.com/" rel="noopener noreferrer"&gt;Reachy from Pollen Robotics&lt;/a&gt;. To use a robot with ROS in Unity you need an existing &lt;a href="http://wiki.ros.org/urdf/Tutorials" rel="noopener noreferrer"&gt;URDF&lt;/a&gt; (robot file descriptor) which is usually shipped by the robot manufacturer. In specific I have decided to work on a static robotic manipulator and operate it with &lt;a href="https://moveit.ros.org/" rel="noopener noreferrer"&gt;MoveIt!&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;There are already quite few tutorials on how to do that in Unity, however, I took the opportunity to create a MoveIt! connector for Unity which allows to control the robot using the &lt;a href="http://docs.ros.org/en/kinetic/api/moveit_tutorials/html/doc/moveit_commander_scripting/moveit_commander_scripting_tutorial.html" rel="noopener noreferrer"&gt;MoveIt! MoveGroup API&lt;/a&gt; rather than creating custom services as done by other tutorials. I find this solution easier to plug to other robots since it uses all standard ROS messages and does not require an additional service.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftvl7pjo0laxvik8hto2y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftvl7pjo0laxvik8hto2y.png" alt="image"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Both Unity and ROS share the same copy of the robot descriptor URDF. Unity will serve as main source of the joint state of the robot. MoveIt! will use the information streaming from Unity to plan the route and send the arm trajectory back to Unity which will actuate the joints.&lt;/p&gt;

&lt;p&gt;MoveIt! will communicate the trajectory to Unity using a custom ROS topic on which a custom created Unity MoveIt Handler publishes the trajectory to execute.&lt;/p&gt;

&lt;p&gt;The custom code for the project has 3 main components which are in Github:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://github.com/szandara/unity_moveit_manager/tree/master/src/unity_moveit_manager" rel="noopener noreferrer"&gt;unity_connector_manager.cpp&lt;/a&gt; which sends the trajectory to Unity after calling execute() on a planned MoveIt! trajectory.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/szandara/unity_moveit_manager/blob/master/src/unity_tcp_server/scripts/server_endpoint.py" rel="noopener noreferrer"&gt;unity_tcp_server.py&lt;/a&gt; which acts as proxy between ROS and Unity&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/szandara/unity_moveit_connector/blob/master/Editor/ROSMoveItControllerGeneric.cs" rel="noopener noreferrer"&gt;ROSMoveItControllerGeneric.cs&lt;/a&gt; which controls the robot in Unity and communicates with ROS.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  ROS
&lt;/h3&gt;

&lt;p&gt;Let's now install our ROS distribution. I am using ROS1 because lots of necessary libraries are missing in ROS2. ROS will only be installed inside the docker even though I have a ROS version also installed in my WLS2 for quick tests. &lt;br&gt;
Along with ROS, the docker image will contain few libraries which are available in Github and we will use for our demo.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First, create a workspace folder in your WSL home (or wherever you please)
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;zandara@XXX:$ cd ~
zandara@XXX:$ mkdir unity_demo
zandara@XXX:$ cd unity_demo
zandara@XXX:$ git clone https://github.com/szandara/unity_reachy_tutorial
zandara@XXX:$ cd unity_reachy_tutorial
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;We will now build the &lt;a href="https://github.com/szandara/unity_reachy_tutorial/blob/master/Dockerfile" rel="noopener noreferrer"&gt;Docker image&lt;/a&gt; which contains the custom code and the ROS distribution. Run

&lt;code&gt;./build_docker&lt;/code&gt;

and go grab a tea.&lt;/li&gt;
&lt;/ul&gt;

&lt;ul&gt;
&lt;li&gt;Next, we will collect the code for Reachy in ROS. This code is outside of the Docker and will be mounted when the Docker is started.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;zandara@XXX:$ cd src
zandara@XXX:$ git clone https://github.com/szandara/reachy_description_ros1
zandara@XXX:$ git clone https://github.com/pollen-robotics/reachy_moveit_config
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;I am using a fork of Reachy's URDF for ROS1 since they recently moved to ROS2. &lt;/p&gt;

&lt;p&gt;Now all is setup to start using our ROS system!&lt;/p&gt;
&lt;h3&gt;
  
  
  Unity 3D
&lt;/h3&gt;

&lt;p&gt;Let's now setup Unity to work with ROS over Docker. But first, let's install Unity3D, if you still do not have it. &lt;a href="https://unity3d.com/get-unity/download" rel="noopener noreferrer"&gt;https://unity3d.com/get-unity/download&lt;/a&gt;. I am working with the community version (2020.2.5f1).&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Let's create a project called &lt;em&gt;reachy_demo&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;Open Unity and go to the Package Manager. Window -&amp;gt; Package Manager -&amp;gt; + sign -&amp;gt; * Add package from git URL.&lt;/li&gt;
&lt;li&gt;Add the following packages.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://github.com/Unity-Technologies/ROS-TCP-Connector.git#v0.1.2 
https://github.com/Unity-Technologies/URDF-Importer.git#v0.1.2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Make sure they compile without errors. The two packages allow Unity to:

&lt;ul&gt;
&lt;li&gt;Import URDF files for robot models (which is the ROS standard).&lt;/li&gt;
&lt;li&gt;Communicate with a ROS proxy (which will run on the docker).&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Keep the ROS/Unity settings in &lt;em&gt;Robotics&lt;/em&gt; -&amp;gt; &lt;em&gt;ROS Settings&lt;/em&gt; as default (unless you need to change it for some reason) &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdsxughgyrwgn2mbg9nqw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdsxughgyrwgn2mbg9nqw.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Finally open the TCP 5005 port for ROS to talk to Unity. It's fairly &lt;a href="https://medium.com/r/?url=https%3A%2F%2Fwww.howtogeek.com%2F394735%2Fhow-do-i-open-a-port-on-windows-firewall%2F" rel="noopener noreferrer"&gt;straight-forward as explained here&lt;/a&gt;. See &lt;a href="https://dev.to/szandara/robotics-on-wsl2-using-ros-docker-and-unity-3d-part-i-3752?preview=8f8f29b8bfa6bff63d49a701398380b9c272ed4f2ef0dc3db12dde5bc8aa2f2644cf471565887242543e873ba753e99e078059d25eb0a1534dd1159f"&gt;Part I&lt;/a&gt; for the reasons.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Setup Reachy in Unity
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Go to GitHub and download &lt;a href="https://github.com/szandara/reachy_description_ros1" rel="noopener noreferrer"&gt;https://github.com/szandara/reachy_description_ros1&lt;/a&gt; as a zip file.&lt;/li&gt;
&lt;li&gt;Go to your Unity Asset directory and create a subfolder called URDF.&lt;/li&gt;
&lt;li&gt;Copy and extract the downloaded reachy_description.zip into &lt;em&gt;Assets/URDF/reachy&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;Copy the file &lt;em&gt;Assets/URDF/reachy/reachy_description_ros1/reachy.URDF&lt;/em&gt; to &lt;em&gt;Assets/URDF/reachy/reachy.URDF&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;Right click on &lt;em&gt;reachy.URDF&lt;/em&gt; and &lt;em&gt;Import Robot from selected URDF&lt;/em&gt;. A window will popup giving you few options. Change Mesh Decomposer to Unity unless you have VHACD.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxzzrk6nvvsffcgu5b0gn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxzzrk6nvvsffcgu5b0gn.png" alt="image"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Select &lt;em&gt;reachy&lt;/em&gt; from the GameObject list on the left. In the inspector on the right, find Controller (Script) and set the following values.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr67nayng3dtxds6rzv7o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr67nayng3dtxds6rzv7o.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note that these are arbitrary values which I manually tuned. Accurate values could be provided by the manufacturer.&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Select &lt;em&gt;torso&lt;/em&gt; from the GameObject list on the left and tick &lt;em&gt;Immovable&lt;/em&gt; in &lt;em&gt;Articulation Body&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fumwjlyfjrqrs3vmfxnhd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fumwjlyfjrqrs3vmfxnhd.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We are done with importing Reachy. We should now see it in our simulated world!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F840j4ymabs8f60kg2e0o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F840j4ymabs8f60kg2e0o.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Setup MoveIt! in Unity
&lt;/h3&gt;

&lt;p&gt;Here we setup a script to control Unity's ArticulationBody objects with MoveIt! messages from ROS. I have uploaded the script in this repository &lt;a href="https://github.com/szandara/unity_moveit_connector/blob/master/Editor/ROSMoveItControllerGeneric.cs" rel="noopener noreferrer"&gt;https://github.com/szandara/unity_moveit_connector/blob/master/Editor/ROSMoveItControllerGeneric.cs&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Copy paste the content of &lt;a href="https://github.com/szandara/unity_moveit_connector/blob/master/Editor/ROSMoveItControllerGeneric.cs" rel="noopener noreferrer"&gt;the file&lt;/a&gt; directly into a file named &lt;em&gt;Assets/moveit/ROSMoveItControllerGeneric.cs&lt;/em&gt; make sure Unity compiles it without errors.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Finally, add the script to Reachy by selecting &lt;em&gt;r_shoulder&lt;/em&gt; then &lt;em&gt;Add Component&lt;/em&gt; -&amp;gt; &lt;em&gt;Scripts&lt;/em&gt; -&amp;gt; &lt;em&gt;ROS Move It Controller Generic&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Add the parameters as seen in this example&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;Joint State Topic Name&lt;/em&gt;: joint_states&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Move It Move Group&lt;/em&gt;: unity_right_arm_controller&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Joint Group&lt;/em&gt;: Drag and Drop the &lt;em&gt;r_shoulder&lt;/em&gt; joint from the Unity tree as visible in this screenshot.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F248scen0vlquo9vovn5h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F248scen0vlquo9vovn5h.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We are done! We have setup Reachy to talk to ROS!&lt;/p&gt;
&lt;h2&gt;
  
  
  Combining all
&lt;/h2&gt;

&lt;p&gt;As last step, we need to start the system. Let's dive right into it.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First, let's start Unity if it's not started already and open our project &lt;em&gt;reachy_demo&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;Open a WSL shell and go to our project folder &lt;em&gt;unity_demo&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;Edit the file &lt;a href="https://github.com/szandara/unity_reachy_tutorial/blob/master/src/unity_reachy_tutorial/launch/unity_connector.launch" rel="noopener noreferrer"&gt;unity_demo/src/unity_reachy_tutorial/src/unity_reachy_tutorial/launch/unity_connector.launch&lt;/a&gt; and set these parameters using the values that were configured in Unity. Note that &lt;em&gt;UNITY_IP&lt;/em&gt; is set by Windows and it's the IP used to communicate with WSL2. You can find this IP from WSL by running

&lt;code&gt;grep nameserver /etc/resolv.conf&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    &amp;lt;param name="ROS_IP" type="str" value="$(env ROS_IP)" /&amp;gt;
    &amp;lt;param name="ROS_TCP_PORT" type="int" value="10000" /&amp;gt;
    &amp;lt;param name="TCP_NODE_NAME" type="str" value="TCPServer" /&amp;gt;
    &amp;lt;param name="TCP_BUFFER_SIZE" type="int" value="1024" /&amp;gt;
    &amp;lt;param name="TCP_CONNECTIONS" type="int" value="10" /&amp;gt;

    &amp;lt;param name="UNITY_IP" type="str" value="XXX.XXX.XXX.XXX" /&amp;gt;
    &amp;lt;param name="UNITY_SERVER_PORT" type="int" value="5005" /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Run the following
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;zandara@XXX:$ ./launch_docker
root@docker:~# source /opt/unity_demo/unity_reachy_tutorial/devel/setup.bash 
root@docker:~# roslaunch unity_reachy_tutorial reachy_demo.launch
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;You should see a confirmation that you can start planning.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Open another WSL and go to our project folder &lt;em&gt;unity_demo&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;Run the following
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;zandara@XXX:$ ./launch_docker
root@docker:~# rosrun moveit_commander moveit_commander_cmdline.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;You should see the MoveIt command line.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Go to Unity and start the game, there should be no errors in the console&lt;/li&gt;
&lt;li&gt;Go to the MoveIt command line (in WSL2) and run the following
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt; use right_arm
&amp;gt; current
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Make sure you see no errors. If you receive an error the problem could be related to the time offset of Windows vs WSL2. To fix it, open a WSL2 console and run the following&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo ntpdate time.windows.com&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If you have no errors continue planning the route in MoveIt
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt; rec c
&amp;gt; goal = c
&amp;gt; goal[0] = -2.1
&amp;gt; plan goal
&amp;gt; execute
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should see Reachy moving its right arm to the top! Congratulations in planning your first Unity simulation!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsg3br56dcbc26krzyp6w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsg3br56dcbc26krzyp6w.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusions
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;We have shown how to setup Windows to work as powerful Linux development environment.&lt;/li&gt;
&lt;li&gt;We have shown how Unity can be used as simulation environment for robotics&lt;/li&gt;
&lt;li&gt;We have shown how ROS and Unity exchange messages&lt;/li&gt;
&lt;li&gt;We have shown how to control Reachy on Unity with MoveIt!.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I had lots of fun doing this project and I am going to pursue a personal project using this setup. However, the solution is far from perfect. The pitfalls experienced due to Windows and WSL2 not working well together is substantial and by no means ensure a relaxed development environment for professional use. &lt;/p&gt;

&lt;p&gt;The lack of support for ROS2 by Unity has also lead to produce a probably soon outdated ROS project and an eventually painful migration. &lt;a href="https://github.com/Unity-Technologies/Unity-Robotics-Hub" rel="noopener noreferrer"&gt;Unity has announced&lt;/a&gt; that ROS2 support is under development and I will make sure to update this article with the new ROS2 version.&lt;/p&gt;

&lt;p&gt;Nonetheless, it was rewarding to know that I can now develop robotics comfortably from my Windows host!&lt;/p&gt;

</description>
      <category>robotics</category>
      <category>wsl</category>
      <category>unity3d</category>
      <category>ros</category>
    </item>
    <item>
      <title>Robotics on WSL2 using ROS, Docker and Unity 3D (Part I)</title>
      <dc:creator>Simone Zandara</dc:creator>
      <pubDate>Mon, 15 Mar 2021 18:23:04 +0000</pubDate>
      <link>https://dev.to/szandara/robotics-on-wsl2-using-ros-docker-and-unity-3d-part-i-3752</link>
      <guid>https://dev.to/szandara/robotics-on-wsl2-using-ros-docker-and-unity-3d-part-i-3752</guid>
      <description>&lt;p&gt;Have you ever wanted to just be able to write code on Windows but with the familiar tools you always use at work on your Linux station? Have you ever wanted to be able to just close your Cyberpunk 2077 quest and start tinkering with your latest robot project in ROS? &lt;/p&gt;

&lt;p&gt;I have always developed under Linux but I recently decided to leverage my Windows laptop for my coding projects. I do occasionally game and use graphic applications so I did not really want to move to Linux and I was super lazy to partition the hard drive. Moreover lots of tools for sensors or robots are developed for Windows only and it's often inconvenient to switch back and forth.&lt;/p&gt;

&lt;p&gt;I decided to give a try to the new Windows WSL feature. For those who don't know, &lt;a href="https://medium.com/r/?url=https%3A%2F%2Fdevblogs.microsoft.com%2Fcommandline%2Fannouncing-wsl-2%2F" rel="noopener noreferrer"&gt;WSL&lt;/a&gt; is a Windows feature which allows you to have a running Linux image in your Windows Desktop. Yes you heard correctly! No more need to partition your drive! &lt;br&gt;
In this article I will go through how I set up my old laptop to run some cool robotics simulation. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa7qwfj6gynx0e6ru4p6q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa7qwfj6gynx0e6ru4p6q.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's dive right into it!&lt;/p&gt;
&lt;h2&gt;
  
  
  Setup WSL (the right one!)
&lt;/h2&gt;

&lt;p&gt;WSL is under quite some development and there are actually 2 versions around. The latest version &lt;a href="https://medium.com/r/?url=https%3A%2F%2Fdevblogs.microsoft.com%2Fcommandline%2Fannouncing-wsl-2%2F" rel="noopener noreferrer"&gt;WLS2&lt;/a&gt; has much better support for GPU hardware and docker than its predecessor. To install WSL2 you need to have a developer preview of Windows which you can conveniently install from your Windows Update. After joining &lt;a href="https://insider.windows.com/en-us/getting-started" rel="noopener noreferrer"&gt;https://insider.windows.com/en-us/getting-started&lt;/a&gt; and updating your Windows to the latest build, follow the steps below&lt;br&gt;
&lt;a href="https://docs.microsoft.com/en-us/windows/wsl/install-win10" rel="noopener noreferrer"&gt;https://docs.microsoft.com/en-us/windows/wsl/install-win10&lt;/a&gt;&lt;br&gt;
Once done, choose your Linux distribution and set it up the way you like. I chose Ubuntu 20.4.&lt;/p&gt;

&lt;p&gt;Finalize by setting up your display in WSL2. Add this to your &lt;em&gt;~/.bashrc&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export DISPLAY="`grep nameserver /etc/resolv.conf | sed 's/nameserver //'`:0"
export LIBGL_ALWAYS_INDIRECT=1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Note: In reality, I had a pretty hard time updating my outdated Windows version to the latest build. Updates kept on failing with weird reasons and I had to manually turn off several services for some updates to be installed. Good luck!&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  GPU &amp;amp; Docker
&lt;/h2&gt;

&lt;p&gt;For the sake of this demo, having a working GPU is not necessary, however, if you have one, I strongly encourage you to setup your WSL system to use it so you will be ready to move your robot to the deep learning world. If you do not have a GPU skip to the Docker Only section. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note: when installing Docker, use the same hard drive of the WSL installation or you will notice an extremely slow Docker building or running.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  NVIDIA Docker
&lt;/h3&gt;

&lt;p&gt;To setup GPU support for WSL2 follow the instructions as reported from the NVIDIA official page. &lt;a href="https://docs.nvidia.com/cuda/wsl-user-guide/index.html" rel="noopener noreferrer"&gt;https://docs.nvidia.com/cuda/wsl-user-guide/index.html&lt;/a&gt;. This guide will first help you to setup WSL2 for your CUDA drivers and then help you setup your Docker installation with CUDA support. You can stop at Simple CUDA Containers.&lt;/p&gt;

&lt;p&gt;After the installation, if you are having troubles with permissions, make sure you set them up properly. Usually you have missed running this command&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo usermod -aG docker $USER&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note: This Docker installation differs from Docker Desktop which is a similar initiative from the Windows developers. If you have Docker Desktop installed you might have hard time getting the Nvidia Docker installation to work. I have tried to use Docker Desktop but did not manage to get my GPU running even though the Windows developers claim it's ready (&lt;a href="https://www.docker.com/blog/wsl-2-gpu-support-is-here/" rel="noopener noreferrer"&gt;https://www.docker.com/blog/wsl-2-gpu-support-is-here/&lt;/a&gt;).&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Docker Only (No GPU)
&lt;/h3&gt;

&lt;p&gt;If you do not have a GPU I strongly recommend you to install Docker Desktop as it's very simple and can be done directly from Windows with a couple of clicks. &lt;a href="https://docs.docker.com/docker-for-windows/install/" rel="noopener noreferrer"&gt;https://docs.docker.com/docker-for-windows/install/&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Last important adjustments
&lt;/h2&gt;

&lt;p&gt;While setting up the rest of this tutorial I had lots of WTF moments which I listed below.&lt;/p&gt;

&lt;h4&gt;
  
  
  Firewall (&lt;a href="https://github.com/microsoft/WSL/issues/5338" rel="noopener noreferrer"&gt;Github issue&lt;/a&gt;)
&lt;/h4&gt;

&lt;p&gt;WSL2 and Windows do not communicate through the same network interface but through a virtual network. WSL2 and Windows each share a different IP which you can see through the ifconfig. That said, I realized that Windows was blocking incoming connections from WSL2 and I had to add an exception to the firewall to allow ROS to communicate with Unity. &lt;a href="https://www.howtogeek.com/394735/how-do-i-open-a-port-on-windows-firewall/" rel="noopener noreferrer"&gt;How To&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Time sync (&lt;a href="https://github.com/microsoft/WSL/issues/4149" rel="noopener noreferrer"&gt;Github issue&lt;/a&gt;)
&lt;/h4&gt;

&lt;p&gt;WSL2 and Windows time will easily drift causing both systems to have different time. Some people experienced high discrepancies, however, I had only few seconds difference. Nonetheless, those few seconds were enough to cause ROS to reject the messages incoming from Unity. To fix the issue I have setup a continuous sync in WSL2.&lt;/p&gt;

&lt;p&gt;We will go ahead and let WSL2 sync from Windows time each 10 minutes.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo crontab -e&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Then add the following line&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;10 * * * * ntpdate time.windows.com&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;h4&gt;
  
  
  Service startup
&lt;/h4&gt;

&lt;p&gt;WSL2 does not support system.d or any sort of service start.  Among many different ways, I have chosen the simplest one to make it happen (&lt;a href="https://www.how2shout.com/linux/how-to-start-wsl-services-automatically-on-ubuntu-with-windows-10-startup/" rel="noopener noreferrer"&gt;https://www.how2shout.com/linux/how-to-start-wsl-services-automatically-on-ubuntu-with-windows-10-startup/&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;Add the following lines to your /etc/sudoers file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;%sudo ALL=(ALL) NOPASSWD: /usr/sbin/service docker *
%sudo ALL=(ALL) NOPASSWD: /usr/sbin/service cron *
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then go to your Windows search bar and type &lt;em&gt;Run&lt;/em&gt; and inside it type&lt;br&gt;
&lt;br&gt;
 &lt;code&gt;shell:startup&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;It will open a folder. Inside it, create a file &lt;em&gt;wslservices.bat&lt;/em&gt; with this content&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;wsl.exe sudo service docker start
wsl.exe sudo service cron start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can add other services if required.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusions
&lt;/h2&gt;

&lt;p&gt;You are now setup to work with WSL2 and do software development using the convenience of Linux while keeping your Windows system running! I have used this setup for other projects related to deep learning and it's extremely convenient if you like me don't like swapping OS often. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/szandara/robotics-on-wsl2-using-ros-docker-and-unity-3d-part-ii-4l45"&gt;Continue to Part II&lt;/a&gt; where we will setup our demo to use Unity and ROS over WSL2 and Docker.&lt;/p&gt;

</description>
      <category>robotics</category>
      <category>wsl</category>
      <category>unity3d</category>
      <category>ros</category>
    </item>
  </channel>
</rss>
