Coral

Coral is a (experimental) renderer for maritime robotics simulation in ROS 2. The goal is to replace the classical Gazebo or RViz GUI to render nice, realistic images when performing maritime robotics experiments or simulation.
It is based on osgOcean and is inspired from the well-known UWSim in ROS 1.

The module can be explored and downloaded from GitHub

The log2plot module

This module allows logging data from C++ code (typically a robot control loop where you want to store the control inputs, error, robot command, etc.) in order to plot them with Python (matplotlib). The data files are in YAML and can also be generated from elsewhere as long as they follow the same syntax. The plotting script can also create videos and has many options to change the display.

The module can be explored and downloaded from Github:

git clone https://github.com/oKermorgant/log2plot.git

Configuring Qt Creator

Why an IDE and why Qt Creator

As we saw in class, I recommend the use of Qt Creator IDE to develop in C++. There are a few reasons for this:

  • As with all IDE's, you can jump to the wrong lines when a compilation error is detected.
  • It allows an easy use of the debugger, which is the modern and efficient way to hunt for bugs.
  • It gives auto-completion which is particularly useful for OpenCV, ROS or ViSP classes.
  • You can easily go through the project files.
  • The raw installation is enough, no plugins are required to use CMake and C++, even with ROS.

Other IDE's may have the same properties (KDevelop, VS Code, Eclipse, CLion...) but Qt Creator is recommended for labs. If you feel (or are sure you are) confident enough to use another tool, do what you want - but we cannot install all IDE's on the lab computers.

I recall below how to load a CMake project in Qt Creator. There are small differences depending on the project being a ROS package or not.
If anything goes wrong (like C++ files not appearing), just quit Qt Creator, delete the CMakeLists.txt.user file and follow the steps more carefully.

Components of a CMake-based C++ project

A standard way to share C++ source files is to regroup them under a CMake project. In this case, the project is composed of:

  • The source files (.h, .hpp, .cpp) that may be placed inside several sub-folders if needed
  • The CMakeLists.txt file that is at the root of the project and is basically the `how-to` compile all the source files
Most projects you download will already have these files. On the opposite, if you want to start a new project from scratch you should at least have a cpp source and the CMakeLists.txt file that tell how to compile it. For example it may simply contain:
project(my_awesome_project) # name of the project
add_executable(program_name source_file.cpp)
In both cases, at this point you have sources and CMakeLists.txt and want to configure, compile and possibly load it into an IDE.

Configuring the project

Configuring a CMake project is about creating a build directory and tell CMake where it is. This makes no difference whether you have created a project from scratch or downloaded one from Github or other place. The classical steps are, in a terminal:

cd my_project_folder
mkdir build # create a build directory
cd build # go inside
cmake .. # run cmake with the path to the parent folder, where CMakeLists.txt is
After that the project is configured but not compiled yet. It is time to run an IDE to start working on that.

Loading a project inside QtCreator

Standalone C++ projects are usually compiled in a build folder. This folder has to be manually created, for ease of use I recommend creating it in the project folder. This has to be done before loading the project in Qt Creator, and indicate this folder as the compilation one:

  • Create the build folder inside the C++ project directory
  • Launch Qt Creator and go through File... Open file or project to select your CMakeLists.txt
  • The IDE asks for a compilation folder, select the build folder that is in this project.
  • Qt Creator may also ask for several folders depending on the build configuration (default, debug, release...). In this case I advise to unselect everything but the Debug mode, which activates the Debug compilation.
Alternatively, Qt Creator may try to guess what the build folder is if you have already configured the project:
  • Create the build folder inside the C++ project directory
  • Configure the project using cmake
  • Launch Qt Creator and go through File... Open file or project to select your CMakeLists.txt
  • The IDE asks for a compilation folder, select the Imported Kit that should be set to the correct build folder

Loading ROS projects

ROS uses CMake but in its own fashion. The projects are called "packages" and the sources are located in the src folder of the ROS workspace. On the other hand, the build directory is not inside the same folder. It is in the build folder of the ROS workspace and has to be created by ROS itself.

Here are the steps to reproduce to load a new ROS package into Qt Creator (it should also work with other CMake-friendly IDE's). When I write "new ROS package", I mean a package that was just created or downloaded in your src folder. Modying an existing package does not require the following steps. Note that any IDE has to be run from a terminal that is set up for ROS or ROS 2, so it has access to the various workspaces. In the VM or in the lab computers, two shortcuts exist, to run Qt Creator explicitely for ROS 1 or ROS 2.

  • Have ROS create all the necessary directories by calling catkin build form the ROS workspace. For ROS 2, use colcon instead.
  • Launch Qt Creator and go through File... Open file or project to select your CMakeLists.txt
  • The IDE asks for a compilation folder, select the build/package_name folder from the ROS workspace.
  • As this folder already exists, Qt Creator will load the compilation settings. On lab computers, the Debug mode is already activated.
From my experience, ROS (1/2) is not always happy when calling cmake directly. if you have to modify the CMakeLists.txt file (to add a new source, dependency or other thing) it is usually better to:
  • Exit your IDE
  • Modify the CMakeLists.txt
  • Run catkin or colcon
  • Open the project in the IDE again
  • Automatic configuration script

    As seen in the previous section, and during some of the labs, Qt Creator can be tricky to configure when we want to load a CMake project, and even more when loading a ROS package.

    This repository includes a script (for Linux / macOS) to automatically generate the QtCreator (and VS Code) configuration file CMakeLists.txt.user (non-ROS and ROS projects).
    Just run the following line from the folder where CMakeLists.txt is:

    ide_config.py
    You may also define an alias in your .bashrc file. This is already done in the virtual machine and in the lab computers:
    alias ideconf="path/to/ide_config.py"

    Using QtCreator

    When loading a CMakeLists.txt, QtCreator will read the content and display all sources (.h and .cpp) that are listed as useful to create executables or libraries. Here are the main tools from the GUI:

    • To create a new source file, go through File... New file or project then C++ source file.
    • Each time you modify the CMakeLists.txt file (to add a new source or new binary), right-click on the project and select Run CMake It may be done automatically by Qt Creator.
      • Note that calling CMake from Qt Creator may fail for ROS projects. It is best to call catkin or colcon and reopen the project.
    • You can select the executable that is run by clicking on the computer in the lower-left section
    • This executable is actually run by clicking on the green triangle. Sources are recompiled if needed.
    • This executable is run in Debug mode by clicking on the green triangle with a bug. The Debug display of Qt Creator will appear.
    • If your executable requires keyboard input, you have to tell QtCreator to run this one in a separate terminal:
      • Open the left Project panel
      • Go to the Run panel
      • Select your executable and tick the "Run in terminal" box

    ROS (1/2) nodes can be run from Qt Creator (as soon as a ROS master is available, for ROS 1). Launch files cannot be used, so topics / parameters have to be set from the C++ code. This is very useful for initial debugging, before remapping everything with launch files.

ROS 1 and 2 utility scripts

This repository includes the ros_management.bash script that helps dealing with both ROS 1 and 2 if sourced in your .bashrc:

ros1_workspaces="/opt/ros/noetic ~/code/libs/ros ~/code/ros"
ros2_workspaces="/opt/ros/foxy ~/code/libs/ros2 ~/code/ros2"
source /path/to/ros_management.bash -k -p -ros2 # init ROS 2 workspaces, keep configuration for next terminals
ros1ws # init ROS 1 workspaces, adds [ROS1] to the prompt to inform user
# ros2cd # tries to make it to the source directory of the package

You will also find a ROS cheat sheet that motivates how and when using ROS tools versus standard ones (CMake / IDE) when working on packages.

A few utility scripts used at ECN can be found on this repository. They are tailored for the installation and maintenance of the ECN compter and virtual machines, but feel free to use any part of the scripts.

Duels framework

Duels is a C++ framework to build AIs that play various 1 vs 1 games. It can be installed through Debian packages (available on Github) for Ubuntu Focal or Jammy.
The source can also be used to create new games with embedded AIs and let other people play against it.
All the mechanics (rules) and AI are in C++ while the UI uses Pygame. Communication is done through zero-MQ.

Clickshare for Linux

In the following link you can find a tar file containing the Clickshare tool for Linux computers. All libraries should be shipped in. The first run will ask for the admin password in order to update some USB rules, then it will run directly.

Just untar this file and run clickshare.sh