Skip to content

1.4.2 Installing VScode

VScode, short for Visual Studio Code, is a lightweight code editor developed by Microsoft. It is free, open-source, and highly functional. It supports syntax highlighting, intelligent code completion, custom hotkeys, bracket matching, code snippets, code diff comparison, GIT, and other features for almost all major programming languages. It supports plugin extensions and is optimized for web development and cloud application development. The software is cross-platform, supporting Windows, Mac, and Linux.

1. Download

VSCode download: https://code.visualstudio.com/docs?start=true

Historical version download link: https://code.visualstudio.com/updates

2. VScode Installation and Uninstallation

2.1 Installation

Method 1: Double-click to install (or right-click and select install)

Method 2: sudo dpkg -i xxxx.deb

2.2 Uninstallation

text

bash
sudo dpkg --purge code

3. Integrating ROS Plugins in VScode

To develop ROS programs using VScode, you need to install some plugins first. Commonly used plugins are as follows:

4. VScode Usage_Basic Configuration

4.1 Create a ROS Workspace
bash
mkdir -p xxx_ws/src (must have src)
cd xxx_ws
catkin_make
4.2 Launch VScode

Enter xxx_ws and launch vscode

bash
cd xxx_ws
code .
4.3 Compiling ROS in VScode

Use the shortcut Ctrl + Shift + B to invoke compilation, and select: catkin_make:build

You can click configure to set it as default, modifying the .vscode/tasks.json file:

json
{
    // For documentation on tasks.json format, see
    // https://go.microsoft.com/fwlink/?LinkId=733558
    "version": "2.0.0",
    "tasks": [
        {
            "label": "catkin_make:debug", // Descriptive information for the prompt
            "type": "shell",  // Can choose shell or process. If shell, the code runs a command in the shell; if process, it runs as a process.
            "command": "catkin_make", // This is the command we need to run
            "args": [], // If suffixes need to be added after the command, write them here, e.g., -DCATKIN_WHITELIST_PACKAGES="pac1;pac2"
            "group": {"kind":"build","isDefault":true},
            "presentation": {
                "reveal": "always" // Options: always or silence, representing whether to output information
            },
            "problemMatcher": "$msCompile"
        }
    ]
}
4.4 Create a ROS Function Package

Select src, right-click ---> Create Catkin Package

Set the package name and add dependencies

4.5 Python Implementation

Create a new scripts folder under the function package, add a Python file, and add execute permissions.

python
#! /usr/bin/env python
"""
    Python version HelloVScode, outputs HelloVScode to the console upon execution.
    Implementation:
    1. Import package
    2. Initialize ROS node
    3. Log output HelloWorld

"""

import rospy # 1. Import package

if __name__ == "__main__":

    rospy.init_node("Hello_Vscode_p")  # 2. Initialize ROS node
    rospy.loginfo("Hello VScode, I am Python ....")  # 3. Log output HelloWorld

Add execute permissions: chmod +x *.py

4.6 Configure CMakeLists.txt

Python configuration:

txt
catkin_install_python(PROGRAMS scripts/custom_filename.py
  DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)
4.7 Compile and Execute

Compile: Ctrl + Shift + B

Execute: Same as before, but you can add a terminal in VScode. First, execute: source ./devel/setup.bash

PS:

If you execute the Python file without compiling first, an exception will be thrown.

  1. The first line interpreter declaration can use an absolute path to locate the python3 installation path #! /usr/bin/python3, but this is not recommended.
  2. Using #!/usr/bin/env python is recommended, but it may throw an exception: /usr/bin/env: "python": No such file or directory.
  3. Solution 1: #!/usr/bin/env python3 directly uses python3, but there is a problem: it is not compatible with previous ROS-related Python implementations.
  4. Solution 2: Create a symbolic link to the python command: sudo ln -s /usr/bin/python3 /usr/bin/python

5. Other IDEs

There are quite a few IDEs that can be used for ROS development. Besides VScode, there are Eclipse, QT, PyCharm, Roboware, etc. For details, please refer to the official website: http://wiki.ros.org/IDEs

QT Creator Plugin for ROS, reference tutorial: https://ros-qtc-plugin.readthedocs.io/en/latest/

Roboware reference: http://www.roboware.me/#/ (PS: Roboware is no longer updated, unfortunately...)