ROS 2 with VSCode and macOS
VSCode is one of the most powerful code editors I have tried in a long time. While I know it using Electron as a framework has gotten some people erked at the thought, I rather enjoy the customizability afforded to it by the JavaScript/HTML/CSS backend. However, not all Electron text editors are made the same. Atom, which is a competitior to VSCode (well…maybe not anymore), relies on Electron and a very similar way of doing things, but Microsoft had the advantage of adding some of that special Intellisense code to it. VSCode is far superior when it comes to coding in C++ because Atom really can’t do it. So when I program in ROS on both my Linux and macOS rigs, I tend to just use VSCode out of ease of use, but there are always a couple issues when first setting up the system which I will address in this blog post.
VSCode with ROS 2 and macOS
I could never really get the original ROS to work with macOS. It always seemed like a bunch of hurdles to jump through, especially if you wanted to use the latest version. ROS 2, however, has among its goals to be compatible with multiple platforms (Windows, macOS, and Linux). They have a long road ahead, but they have made some great progress and amazing features.
Binary or Source installation of ROS 2 on macOS can be here and here, respectively.
Once installed, you can easily start writing a project using VSCode. All you need to do is modify the file that is generated in the .vscode
folder of the project called c_cpp_properties.json
. In the includePath
json tag, add the path (line 13) to where the ROS 2 installation’s include
folder is as such:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
{
"configurations": [
{
"name": "Mac",
"browse": {
"path": [
"${workspaceFolder}"
],
"limitSymbolsToIncludedHeaders": true
},
"includePath": [
"${workspaceFolder}",
"/Users/YOURUSERNAME/ros2_install/ros2-osx/include"
],
"defines": [],
"macFrameworkPath": [
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks"
],
"compilerPath": "/usr/bin/clang",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
There you have it! Intellisense will now help you autocomplete your future ROS 2 code.