# Debugging with Foxglove

This tutorial describes how to perform debugging using Foxglove.

## FOXGLOVE INSTALLATION

After you have completed the initial setup for CogniPilot on a native ubuntu machine, open a new terminal and run "build\_foxglove" to install foxglove on your machines.

* Note: If this command is not found, restart your system and try again.
* Select "y" when asked for clone repositories using git with already setup github ssh keys.
* Select "1" when asked for which release to be used - airy (1) or main (2).

## FOXGLOVE DEBUGGING

### PREREQUISITES

**NOTE: When working with hardware buggy, the debug topics must be added to the default\_value of topic\_whitelist in b3rb\_robot/b3rb\_bringup/launch/robot.launch.py as well, as shown in the steps below. Then build, source and run. The changes made on cranium must be done on NavQPlus and not the UBUNTU HOST MACHINE.**

1. Camera Images: We can publish debug images from "b3rb\_ros\_line\_follower/b3rb\_ros\_line\_follower/b3rb\_ros\_edge\_vectors.py". For publishing debug images from other ROS2 nodes, follow similar process.
   * Create a new publisher in the **init** function as shown in the attached image. We need to create a new topic and in our case we have chosen "/debug\_images/vector\_image".
   * ![alt text](/files/hXgiqczyDD3G3gKCmRAT)
   * Now, pass this publisher (self.publisher\_vector\_image) and the image as arguments to the "publish\_debug\_image" function whenever you want to output your debug images.
   * Open a new terminal and run the following commands.
     * cd \~/cognipilot/cranium
     * colcon build
     * source install/setup.bash
   * Append the same topic name "/debug\_images/vector\_image" to the default\_value of topic\_whitelist in electrode/src/electrode/launch/electrode.launch.py as shown in the attached image.
   * ![alt text](/files/EdZpdL8mwTpFMjFrPZgK)
   * **When working with hardware buggy** append the same topic name "/debug\_images/vector\_image" to the default\_value of topic\_whitelist in b3rb\_robot/b3rb\_bringup/launch/robot.launch.py. The snippet of this argument is attached in the image below.
     * ![alt text](/files/0BJNKIxtiEnegya0SJH7)
     * Open a new terminal and run the following commands.
       * cd \~/cognipilot/cranium
       * colcon build
       * source install/setup.bash
   * Open a new terminal and run the following commands.
     * cd \~/cognipilot/electrode
     * colcon build
     * source install/setup.bash
2. LIDAR Data:
   * Append "/scan" to the default\_value of topic\_whitelist in electrode/src/electrode/launch/electrode.launch.py as shown in the attached image.
   * ![alt text](/files/hlvrGvaGU6QGIacFqbjA)
   * **When working with hardware buggy** append "/scan" to the default\_value of topic\_whitelist in b3rb\_robot/b3rb\_bringup/launch/robot.launch.py. The snippet of this argument is attached in the image below.
     * ![alt text](/files/0BJNKIxtiEnegya0SJH7)
     * Open a new terminal and run the following commands.
       * cd \~/cognipilot/cranium
       * colcon build
       * source install/setup.bash
   * Open a new terminal and run the following commands.
     * cd \~/cognipilot/electrode
     * colcon build
     * source install/setup.bash

### USING FOXGLOVE

* Open a new terminal and run the following command after starting the simulation (which is done using the command "ros2 launch b3rb\_gz\_bringup sil.launch.py world:=\<track\_name>")
  * ros2 launch electrode electrode.launch.py sim:=True
  * Then open connection to the url "ws\://localhost:8765"
* Camera Images.
  * Create a new Image panel as shown in the attached image.
  * ![alt text](/files/c3CvXLpBFyvEJhBJZkmi)
  * Then click on panel settings and select the topic for which you created a publisher in the "prerequisites" section.
  * ![alt text](/files/qEohM9kXcmu00pL81cRv)
  * Now this panel will display the image whenever you publish a debug image from your code to the said topic.
* LIDAR Data.
  * Create a new 3D panel by clicking on the add panel button from the top-left corner as shown in the attached image.
  * ![alt text](/files/uPhZfJKlErRWmXaEWpNk)
  * ![alt text](/files/sl5Dy3adpXGVg7jNeKC2)
  * You may switch to 2D camera since the LIDAR is 2D.
  * ![alt text](/files/bPXHxVcNeLc1MG2bAgqB)
  * Then click on panel settings.
  * ![alt text](/files/3Aq5rUhNisSZxdeODBER)
  * Toggle visibility of "/scan" under Topics.
  * ![alt text](/files/Tp9rmnbmCY1hkgvlc4DJ)
  * Then select "lidar\_link" in Display frame under Frame.
  * ![alt text](/files/sIQihpEwbMU6ukXWW9WZ)
    * If you don't immediately see the "lidar\_link" option available, then close the settings panel, play the simulation for a few seconds, then try again.
  * You may close the panel settings after this.
  * Please see the attached images for sample output.
  * ![alt text](/files/WkwYolMaLscroHQnDfzZ)
  * ![alt text](/files/Fb4i6XPGbc7HyNTA6hzM)
  * ![alt text](/files/2nyzspefmyzoW5R7d7Ic)
  * ![alt text](/files/wN2lZfqlU5RxgAaODgSW)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://nxp.gitbook.io/nxp-aim/debugging-with-foxglove.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
