Showing posts with label vscode. Show all posts
Showing posts with label vscode. Show all posts

Tuesday, November 27, 2018

Python docker vscode and remote debugging

  • Docker file (Dockerfile)
    • install project requirements
    • base on python 3.6
FROM python:3.6-alpine COPY requirements.txt /tmp/requirements.txt WORKDIR /tmp RUN pip install -r requirements.txt WORKDIR /project CMD ["sh"]
  • requirements.txt
    • ptvsd: version 4.1.4 (4.2.X version has issue with run debugging multiple times)
ptvsd==4.1.4
  • Docker compose file base on image image: image name build: Docker file path volumes: shared project note that host folder point to current parent folder the remote path add project folder name automaticall
version: '2' services: dev-image: image: python_36 build: . ports: - 3000:3000 privileged: true container_name: pydev volumes: - ../:/project
  • vscode launch.json file
{ "name": "Attach (Remote Debug)", "type": "python", "request": "attach", "port": 3000, "host": "localhost", "pathMappings": [ { "localRoot": "${workspaceFolder}", "remoteRoot": "/project/" } ] }
  • python simple example
import ptvsd import time import os print("Waiting to attach") address = ('0.0.0.0', 3000) ptvsd.enable_attach(address) ptvsd.wait_for_attach() time.sleep(2) x = 1 print(x)

run docker (tasks.json)

  • start docker
    • --service-port:
    • dev-image: compose file service name
    • --name: container name
docker-compose -f docker-compose.yml run --service-ports --name devenv dev-image
  • run remote application
#docker exec -it devenv python "<relative path from working directory>/simple.py" docker exec -it devenv python "python_remote/src/simple.py"
  • stop docker
docker-compose -f docker-compose.yml down
{ "version": "2.0.0", "tasks": [ { "label": "start_docker", "type": "shell", "options": { "cwd": "${workspaceFolder}/python_remote" }, "command": "docker-compose -f docker-compose.yml run --service-ports --name devenv dev-image sh", "problemMatcher": [] }, { "label": "stop_docker", "type": "shell", "command": "docker-compose -f docker-compose.yml down", "options": { "cwd": "${workspaceFolder}/python_remote" }, "problemMatcher": [] }, { "label": "run remote", "type": "shell", "command":["docker exec devenv", "python", "${relativeFile}"], "problemMatcher": [] } ] }

Sunday, October 21, 2018

VSCode cmake and debug

VSCode build with cmake

  • ctrl+shift+p -> Tasks: Configure Task

vscode open tasks.json

  • Project fs structure
├── bin ├── build ├── doc └── src ├── CMakeLists.txt └── hello.cpp └── CMakeLists.txt
  • Add three task
    • cmake: run cmake from build sub folder
    • make: run make depend on cmake
    • build: bind the above
{ "version": "2.0.0", "tasks": [ { "label": "cmake", "type": "shell", "options": { "cwd": "${workspaceRoot}/build" }, "command": "cmake", "args": [ ".." ] }, { "label": "make", "type": "shell", "options": { "cwd": "${workspaceRoot}/build" }, "command": "make", "dependsOn": "cmake" }, { "label": "build", "type": "shell", "dependsOn": "make", "command": "echo", "group": { "kind": "build", "isDefault": true } } ] }
  • Note: task build command key need to be fill with some value echo

cmake files

  • root cmake
    • set bin folder as binary output
    • set c++ version: set(CMAKE_CXX_STANDARD 11)
cmake_minimum_required(VERSION 3.0) project(tutorials) #set binary output set(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/bin) message(${EXECUTABLE_OUTPUT_PATH}) #set flags set(CMAKE_CXX_STANDARD 11) #add source directory add_subdirectory(src)
  • src
add_executable(hello hello.cpp)

Debug Task

  • Control cmake settings from command line
  • Add args to task
  • Add option variable and if statement to cmake

Main CMakeLists.txt

  • Add boolean variable control
option (MODE_DEBUG "Set debug mode" OFF) if (MODE_DEBUG) message("DEBUG MODE") set (CMAKE_BUILD_TYPE Debug) endif()
  • Add new task to VSC with args -DMODE_DEBUG=TRUE
{ "label": "cmake_with_debug", "type": "shell", "options": { "cwd": "${workspaceRoot}/build" }, "command": "cmake", "args": [ "..", "-DMODE_DEBUG=TRUE" ] }
  • Add VSC keybinding
{ "key": "ctrl+shift+d", "command": "workbench.action.tasks.runTask", "args": "cmake_with_debug" }

Debug

launch.json

  • Changed to debug mode
  • From combo box -> Add configuration
    • open launch.json
  • Set program to debug
"program": "${workspaceFolder}/bin/hello",

Sunday, August 5, 2018

VSCode tips for ROS

Tip1 - Adding a file extension to a language

You can add new file extensions to an existing language with the files.associations setting, for example assign gazebo .world file to XML

"files.associations":{
 ".world": "xml"
}


Tip2 - use code runner to check urdf files

code runner:  Run code snippet or code file for multiple languages
  • install 'Code runner' extension into vscode 
  • install check_urdf (apt-get install liburdfdom-tools)
  • from settings append file extension into code runner mapping
"code-runner.executorMapByFileExtension": { 
".urdf": "check_urdf"

Tip3 - use code runner to check xacro files

ROS node xacro in package xacro convert xacro  file to urdf

rosrun xacro xacro <file_name.xacro>

The idea is to run the above command redirect the output to tmp file and then run check_urdf on it.

"files.associations":{
".xacro": "rosrun xacro xacro --inorder $fullFileName > /tmp/tmp.urdf && check_urdf /tmp/tmp.urdf"
}


code runner supported parameters
  • $workspaceRoot: The path of the folder opened in VS Code
  • $dir: The directory of the code file being run
  • $dirWithoutTrailingSlash: The directory of the code file being run without a trailing slash
  • $fullFileName: The full name of the code file being run
  • $fileName: The base name of the code file being run, that is the file without the directory
  • $fileNameWithoutExt: The base name of the code file being run without its extension

Monday, July 30, 2018

VSCode ROS extensions

List of nice VSCode extensions helping work with ROS

Special for ROS

Common but useful
  • Python (link)
  • XML Tools (link)
  • YAML Support by Red Hat (link)