Index ROS2 in JetBrains (Clion & PyCharm)

When your environment is properly indexed, you will be able to see the type and usage of a certain bit of text in the rest of the code. It makes finding dependencies a lot easier and less confusing. In Visual Studio Code, this is partly done by sourcing, but in CLion and PyCharm, it needs a bit of setting up. Use the following guides for that.

Index ROS2 in Clion

To get code completion and static analysis for ROS code to work, you need to open Clion a bit differently than usual.

First thing you need is to make sure you have a compile_commands.json file in the build folder of either ROS2. This should be the case if the code is built with docker. If this is not the case, see jetbrains clion ros setup tutorial.

If there is already such a file, continue with the following steps:

  1. Open a new terminal and source ROS2 (type sfox).

  2. Open clion (type clion)
    • Tip: you can type clion > /dev/null 2> /dev/null & disown to be able to close the terminal, and not output any information to the terminal.

  3. OpenROS2 by opening the compile_commands.json file, and click on ‘Open as Project’. * ROS1 open: ~/march/ros1/build/compile_commands.json
    • ROS2 open: ~/march/ros2/build/compile_commands.json

  4. After the project is opened change your repository root:
    1. Click on ‘Tools’ in the top of clion (in the row of ‘File Edit View …’)

    2. Hover over ‘Compilation Database’

    3. Click on ‘Change Project Root’, and select March.

Now Clion should have correctly indexed your ROS2. Good luck and have fun with “popping code”.

Index ROS2 in PyCharm

To get code completion and static analysis for ROS code to work, you need to open PyCharm a bit differently than usual.

First-time setup steps:

  1. Create a virtual environment with the bash script.
    1. cd march

    2. bash create_venv.sh -n -clean
      • The -n erases the one if there is already there.

      • The -clean redownloads the packages that are not installed by ‘apt’

  2. Build your ros source code march_build.

  3. Source the virtual environment and ROS
    1. svenv or source ~/march/.venv_march/bin/activate

    2. source ROS (sfox)
      • For ROS2: sfox

  4. Open PyCharm with pycharm-professional. (Important: Do this in the same terminal as step 3).

  • Tip: you can type pycharm-professional > /dev/null 2> /dev/null & disown to be able to close the terminal, and not output any information to the terminal.

  1. Select folder for ROS2.

  2. Exclude parts of the built march code to prevent duplicate code fragment errors:
    1. Go to File | Settings | Project: ros2 | Project Structure:
      1. Click on File in the top left of pycharm.

      2. Click on Settings in the dropdown menu of File.

      3. Go to Project: [name of project]” -> “project settings.

    2. Select “build”, “log”, “install” and click on Excluded.

      Now on the left you will see these folders as excluded, and you will also see some files in the install folder listed as source.

For everyday startup, start the pycharm up as in step 3 & 4.