ubuntu18.04 下ros melodic vscode配置開發環境記錄
首先准備可以用命令行編譯通過的ros工作空間及其相應節點並配置好txt文件等。注意不要用vscode 下的create catikn package創建功能包,否則編譯出來好像沒有可執行文件或者可執行文件多了個.pc的后綴,可能我創建的時候有問題,但不管了,用命令行創建就好了。
vscode 插件選擇如下 (第一個 ROS 0.6.6)
1)在ros工作空間下第一級目錄下啟動輸入 啟動scode.
code .
2)選擇Terminal->configue default build Task打開task.json文件
task.json內容要配置為如下:
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"command": "catkin_make -DCMAKE_BUILD_TYPE=Debug",
"problemMatcher": [
"$catkin-gcc"
],
"group": "build",
"label": "build",
"detail": "compiler : /usr/bin/g++"
},
]
}
c_cpp_properties.json
"cppStandard": "c++17"配置的正確與否直接決定C++ intelligence的代碼自動補全功能是否有效
"includePath" 里面包含頭文件路徑
{
"configurations": [
{
"browse": {
"databaseFilename": "",
"limitSymbolsToIncludedHeaders": true
},
"includePath": [
"/opt/ros/melodic/include/**",
"/usr/include/**"
],
"name": "ROS",
"intelliSenseMode": "gcc-x64",
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu11",
"cppStandard": "c++17"
}
],
"version": 4
}
ctrl+shift+P: Task Run Build Task編譯
調試:debug選項下create a launch.json file(c++ GDB 調試)注意創建launch.json file文件之后要檢查下你之前配置的tasks.json文件有沒有被ide修改了,修改了就改回來。
launch.json改為如下,主要制定兩個:
"program" :自己工作空間下workspace/devel/lib/節點名/可執行文件
"preLaunchTask":要填成跟tasks.json文件中“label"標簽一樣的內容。其實直接把這個標簽刪除也可以。
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g++ - 生成和調試活動文件",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/devel/lib/myros/myros_node",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "為 gdb 啟用整齊打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "build",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
后面在要調試的cpp文件里面打斷點,在debug選項卡下點擊run and Debug就可以開始調試了。