Skip to content

luisfico/vscodeRos2ws

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

VSCode ROS2 Workspace Template

This template will get you set up using ROS2 with VSCode as your IDE.

See how I develop with vscode and ros2 for a more in-depth look on how to use this workspace.

Features

a

Style

ROS2-approved formatters are included in the IDE.

  • c++ uncrustify; config from ament_uncrustify
  • python autopep8; vscode settings consistent with the style guide

Tasks

There are many pre-defined tasks, see .vscode/tasks.json for a complete listing. Feel free to adjust them to suit your needs.

Take a look at how I develop using tasks for an idea on how I use tasks in my development.

Debugging

This template sets up debugging for python files and gdb for cpp programs. See .vscode/launch.json for configuration details.

Continuous Integration

The template also comes with basic continuous integration set up. See .github/workflows/ros.yaml.

To remove a linter just delete it's name from this line:

      matrix:
          linter: [cppcheck, cpplint, uncrustify, lint_cmake, xmllint, flake8, pep257]

How to use this template

Prerequisites

You should already have Docker and VSCode with the remote containers plugin installed on your system.

Get the template

Click on "use this template"

template_use

Create your repository

On the next dialog, name the repository you would like to start and decide if you want all of the branches, or just the latest LTS: Foxy.

template_new

Github will then create a new repository with the contents of this one in your account. It grabs the latest changes as "initial commit".

Clone your repo

Now you can clone your repo as normal

template_download

Open it in vscode

Now that you've cloned your repo onto your computer, you can open it in VSCode (File->Open Folder).

When you open it for the first time, you should see a little popup that asks you if you would like to open it in a container. Say yes!

template_vscode

If you don't see the pop-up, click on the little green square in the bottom left corner, which should bring up the container dialog

template_vscode_bottom

In the dialog, select "Remote Containers: Reopen in container"

VSCode will build the dockerfile inside of .devcontainer for you. If you open a terminal inside VSCode (Terminal->New Terminal), you should see that your username has been changed to ros, and the bottom left green corner should say "Dev Container"

template_container

Update the template with your code

  1. Specify the repositories you want to include in your workspace in src/ros2.repos or delete src/ros2.repos and develop directly within the workspace.
    1. If you are using a ros2.repos file, import the contents Terminal->Run Task..->import from workspace file
  2. Install dependencies Terminal->Run Task..->install dependencies
  3. Develop!

---------------- FAST USAGE---------------- !!!

  1. Install dependencies
    sudo apt update -y && sudo apt install gitk -y && sudo apt install ~nros-foxy-rqt* -y && sudo apt install gedit -y
  1. Install dependencies of ROS packages Terminal->Run Task..->install dependencies

  2. Build ros project Terminal->Run Task..->fast build

  3. Run demo (Publisher/Subscriber) :

    ros2 run simple_publisher publisher_main
    ros2 run simple_subscriber subscriber_main

---------------- MAIN COMMANDS---------------- !!!

  • To build ROS2 project

     $ colcon build && source install/local_setup.sh
    
  • Run a ROS2 node

     $ ros2 run <package_name> <executable_name>
    
  • Run a ROS2 launcher (multiple nodes)

     $ ros2 launch <package_name> <script_name>.launch.py
    
  • List running ROS2 nodes

     $ ros2 node list
    
  • List visible topic names (a topic is visible if at least 1 node is publishing or subscribing to it)

     $ ros2 topic list
    
  • Echo what's published on a topic

     $ ros2 topic echo <topic_name>
    
  • Show ROS2 nodes graph

     $ ros2 run rqt_graph rqt_graph
    

---------------- Additional tips---------------- !!!

To show the git branch with colours in terminal Bash prompt :

    $ gedit ~/.bashrc 

Adding this to .bashrc:

parse_git_branch() { git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* (.*)/(\1)/' }

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published