【ROS2】vscode环境配置

1、打开vscode,在vscode下有两个json文件:

【ROS2】vscode环境配置_第1张图片

2、修改c_cpp_properties.json

注意 "includePath"要替换为自己的路径
注意自己的ROS2版本,我的是ros/bouncy

{
  "configurations": [
      {
          "name": "Linux",
          "includePath": [
        "/opt/ros/bouncy/include/**",
        "/home/hahalim/ros2_ws/src/my_node/include/**",
        "/usr/include/**"
          ],
          "defines": [],
          "compilerPath": "/usr/bin/gcc",
          "cStandard": "c99",
          "cppStandard": "c++14",
          "intelliSenseMode": "clang-x64"
      }
  ],
  "version": 4
}

3、修改setting.json

注意自己的ROS2版本,我的是ros/bouncy

{
    "editor.tabSize": 8,
    "editor.rulers": [
        100
    ],
    "files.associations": {
        "*.repos": "yaml",
        "*.world": "xml",
        "*.xacro": "xml",
        "chrono": "cpp"
    },
    // Autocomplete from ros python packages
    "python.autoComplete.extraPaths": [
        "/opt/ros/bouncy/lib/python3.8/site-packages/"
    ],
    // Environment file lets vscode find python files within workspace
    "python.envFile": "${workspaceFolder}/.env",
    // Use the system installed version of autopep8
    "python.formatting.autopep8Path": "/usr/bin/autopep8",
    "python.formatting.autopep8Args": [
        "--max-line-length=100"
    ],
    "C_Cpp.default.intelliSenseMode": "clang-x64",
    "C_Cpp.formatting": "Disabled",
    "uncrustify.useReplaceOption": true,
    "uncrustify.configPath.linux": "/opt/ros/bouncy/lib/python3.8/site-packages/ament_uncrustify/configuration/ament_code_style.cfg",
    "cSpell.words": [
        "RTPS",
        "athackst",
        "autopep",
        "cmake",
        "cppcheck",
        "cpplint",
        "deque",
        "devcontainer",
        "ints",
        "noqa",
        "pytest",
        "rclcpp",
        "rclpy",
        "repos",
        "rosdistro",
        "rosidl",
        "uncrustify",
        "xmllint"
    ],
    "search.exclude": {
        "**/node_modules": true,
        "**/bower_components": true,
        "**/*.code-search": true,
        "**/build": true,
        "**/install": true,
        "**/log": true
    },
    "python.analysis.extraPaths": [
        "/opt/ros/bouncy/lib/python3.8/site-packages/"
    ],
    "cSpell.allowCompoundWords": true,
    "cSpell.ignorePaths": [
        "**/package-lock.json",
        "**/node_modules/**",
        "**/vscode-extension/**",
        "**/.git/objects/**",
        ".vscode",
        ".vscode-insiders",
        ".devcontainer/devcontainer.json"
    ],
    "terminal.integrated.fontFamily": "monospace"
}

4、最后使用Ctrl+Shift+B进行编译即可,选择colcon build

你可能感兴趣的:(ROS2,ubuntu,vscode)