I frequently write code on my computer and want to build, deploy, and run it fast. How do I make sure I’m always running the same code on both machines? I work on an Ubuntu desktop and my robot runs Ubuntu. Both computers are running on Intel NUCs.

Note:
This works with both ROS 1 and ROS 2, but this article is written with ROS 2 users in mind.

lsyncd to the rescue!

Enter lsyncd (Live Syncing Daemon), which automagically deploys my local changes to the robot. It monitors the workspace on my computer for changes and replicates them fast to the robot. Plus, whenever I build my code, I only need to do it in one computer, not both.

On Ubuntu, you can install it with apt install lsyncd.

Note:
These instructions are for Ubuntu. If you’re running a different Linux flavor on your workstation or your robot is not running Linux, you may need to adjust the instructions.

This is *not* a versioning or backup solution. You should start using GitHub or something like it to protect your hard work from getting lost.

I am assuming you have set up your computer to authenticate with an ssh key to the robot computer. If you haven’t yet, do that first.

I have the luxury that the two computers have compatible binaries – both are running Ubuntu on x64 CPUs, so my builds on one machine will work on the other. If this is not the case (e.g. you’re deploying from a laptop to a Raspberry Pi) you should configure the sync daemon to only sync code, not your builds (see below).

configuring the sync daemon

  • Make sure you have no unsaved work on the robot! This will overwrite it!
  • If you don’t want to sync your ROS 2 installation (say you install ROS 2 via apt) delete that first sync block entirely. Otherwise make sure your user can write to /opt/ros/master by executing sudo mkdir -p /opt/ros/master && sudo chown -R $(whoami) /opt/ros/master
  • Modify host='gauss.local' to your robot’s hostname or IP address.
  • Modify the source= lines to point to your ROS 2 installation and workspace paths on your workstation. Modify the target= lines to point to your ROS2 installation and workspace paths on the robot.
  • If you are building with '--symlink-install', you will need to remove '/build' from the exclude list. Python packages built with this option depend on the contents of your build directory.
    If you don’t want to sync your builds, add '/install' to the exclude list.
  • Copy the installation file to /etc/lsyncd/lsyncd.lua
-- Lua configuration file for lsyncd
-- Install me to /etc/lsyncd/lsyncd.lua

sync{default.rsyncssh,
  source='/opt/ros/master',
  delete=true,
  host='gauss.local',
  targetdir='/opt/ros/master',
  exclude={ '.git', '/build', '/log' },
  rsync = {
    perms = true,
    _extra = {
    	"--copy-unsafe-links"
    }
  }
}
sync{default.rsyncssh,
  source='/home/dan/ros2_ws',
  delete=true,
  host='gauss.local',
  targetdir='/home/dan/ros2_ws',
  exclude={ '.git', '/build', '/log' },
  rsync = {
    perms = true,
    _extra = {
    	"--copy-unsafe-links"
    }
  }
}

launching the sync daemon on startup

Change User=dan to your own username. Then install the below file to /etc/systemd/system/lsyncd.service

# Config file for systemd to turn lsyncd into a system service
# Install me to /etc/systemd/system/lsyncd.service

[Unit]
Description=Live Syncing Daemon
After=network.target

[Service]
Type=simple
User=dan
Restart=always
RestartSec=1
ExecStart=/usr/bin/lsyncd /etc/lsyncd/lsyncd.lua -nodaemon -insist

[Install]
WantedBy=multi-user.target

Kick it off with systemctl enable lsyncd --now, which tells your system to run it now and again whenever your computer starts up.

View the status with systemctl status lsyncd. You should see “Active: active” and the last few log messages will be seen on the bottom below the list of processes.

Congrats! Now your workspaces are ready to go!

Get In Touch

Need help using ROS to build an autonomous solution? Contact us to discuss our consulting capabilities.

Contact Us