Setup the Development Environment

ssh-fs

SSH-FS allows you to mount a remote directory through ssh connections. You could mount the catkin_ws into your local directory for programming, and it will be automatically synchronized with the target machine (either your server or car controller).

Use the following command to install ssh-fs:

Ubuntu:

sudo apt install sshfs

MacOS:

brew install sshfs

In order to mount a directory with user permission, you need to enable user_allow_other in your local fuse driver:

sudo vim /etc/fuse.conf

# uncomment the following configuration
user_allow_other

To mount a remote director (e.g. /home/ros/catkin_ws), use the following command:

sshfs -o allow_other \
	-p <remote port> \
	<usr>@<server ip address>:/home/ros/catkin_ws/ \
	~/shadow_catkin_ws

vim

vim is a text-based editor that you could use directly through ssh.

The basic operation of vim could be found in this cheat sheet, or this video tutorial.

More learning materials:

You could create a .vimrc file under your home directory to tune the editor with your preferences.

" enable syntax highlighting
syntax enable

" show line numbers
set number

" set tabs to have 4 spaces
set ts=4

" indent when moving to the next line while writing code
set autoindent

" expand tabs into spaces
set expandtab

" when using the >> or << commands, shift lines by 4 spaces
set shiftwidth=4

" show a visual line under the cursor's current line
set cursorline

" show the matching part of the pair for [] {} and ()
set showmatch

" enable all Python syntax highlighting features
let python_highlight_all = 1

In addition, you could use ctags extension to index and jump between python variable/functions:

# install the ctags
sudo apt install exuberant-ctags

# create the tag data-base (run this command after you install any python packages)
ctags -R -o ./tags ./src/ \
	/opt/ros/melodic/lib/python2.7/dist-packages/ \
	/usr/lib/python2.7

# add tag file to .vimrc
echo "set tags=~/catkin_ws/tags" >> ~/.vimrc

After restart vim, you could use:

  • Ctrl + [ to jump to a tag.
  • Ctrl + T to jump back.
  • :tselect to open a tag.
  • :tnext and :tprev to jump between selected tags.

Visual Studio Code

Visual Studio Code is an IDE that could be installed from [here] (https://code.visualstudio.com).

In order to enable python development, you need to install the python extension.

  • Ctrl + Shift + p to open the console.
  • Type “> install extensions”
  • Type “python” in extension search bar.
  • Install the “python” extension.
  • Mount the ROS python library files to the local file system:
    sshfs -o allow_other \
          -p 12822 \
          hao@localhost:/opt/ros/melodic/lib/python2.7/dist-packages/ \
          ros-python-libs/
    
  • Add ROS library to the extraPaths of python.autoComplete options.
      "python.autoComplete.extraPaths": [
          "/home/hao/ros-python-libs/"
      ],
    
  • Set python 2.7 (used for ROS) as the default interpreter.
    "python.pythonPath": "/usr/bin/python"
    

After set the python extra-path, you could use:

  • Ctrl + Click to jump to a tag
  • Ctrl + Alt + - to jump back