# 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](https://1677675178-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MWeiLnwrIKZJWLFsXhf%2Fuploads%2Fgit-blob-7c4974d13ad046682435228a402416e35f4adb64%2FGetImage.png?alt=media)
   * 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](https://1677675178-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MWeiLnwrIKZJWLFsXhf%2Fuploads%2Fgit-blob-5c37ee4be7db8dabb047724f24ddb761d107e429%2FGetImage_2.png?alt=media)
   * **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](https://1677675178-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MWeiLnwrIKZJWLFsXhf%2Fuploads%2Fgit-blob-3e494e8acc46dccc0d527e6efa4e495a3d8578d7%2Ftopic_whitelist.png?alt=media)
     * 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](https://1677675178-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MWeiLnwrIKZJWLFsXhf%2Fuploads%2Fgit-blob-0d2d7898848ae8513edcc730e574d46fe0ba5f63%2FGetImage_3.png?alt=media)
   * **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](https://1677675178-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MWeiLnwrIKZJWLFsXhf%2Fuploads%2Fgit-blob-3e494e8acc46dccc0d527e6efa4e495a3d8578d7%2Ftopic_whitelist.png?alt=media)
     * 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](https://1677675178-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MWeiLnwrIKZJWLFsXhf%2Fuploads%2Fgit-blob-a9cd540073037b79a9fcfee8152d306e0f08cc80%2FGetImage_4.png?alt=media)
  * Then click on panel settings and select the topic for which you created a publisher in the "prerequisites" section.
  * ![alt text](https://1677675178-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MWeiLnwrIKZJWLFsXhf%2Fuploads%2Fgit-blob-6b82493f4a292162e88d64b819c899c2034fb8ae%2FGetImage_5.png?alt=media)
  * 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](https://1677675178-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MWeiLnwrIKZJWLFsXhf%2Fuploads%2Fgit-blob-5bf520202eb44574acc862b136be368ca57f5966%2FGetImage_6.png?alt=media)
  * ![alt text](https://1677675178-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MWeiLnwrIKZJWLFsXhf%2Fuploads%2Fgit-blob-3e168e507850f198d469e14c5e1a62fa25f7d05a%2FGetImage_7.png?alt=media)
  * You may switch to 2D camera since the LIDAR is 2D.
  * ![alt text](https://1677675178-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MWeiLnwrIKZJWLFsXhf%2Fuploads%2Fgit-blob-f74daca25273659c674d74b782f6ccce7603cfd9%2FGetImage_8.png?alt=media)
  * Then click on panel settings.
  * ![alt text](https://1677675178-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MWeiLnwrIKZJWLFsXhf%2Fuploads%2Fgit-blob-ad522aa57c0e6feb2d3c3b59d4b1876f65a1296b%2FGetImage_9.png?alt=media)
  * Toggle visibility of "/scan" under Topics.
  * ![alt text](https://1677675178-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MWeiLnwrIKZJWLFsXhf%2Fuploads%2Fgit-blob-a2701bcd63991a816422e4b30e418bbcd0280763%2FGetImage_10.png?alt=media)
  * Then select "lidar\_link" in Display frame under Frame.
  * ![alt text](https://1677675178-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MWeiLnwrIKZJWLFsXhf%2Fuploads%2Fgit-blob-87deb1c27fd9a397a81512854911a42291d78ef2%2FGetImage_11.png?alt=media)
    * 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](https://1677675178-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MWeiLnwrIKZJWLFsXhf%2Fuploads%2Fgit-blob-885212c352a96a909c9815d686307064e3d1f636%2FGetImage_12.png?alt=media)
  * ![alt text](https://1677675178-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MWeiLnwrIKZJWLFsXhf%2Fuploads%2Fgit-blob-7cac079a89313e98c96778acb90aacbe78422609%2FGetImage_13.png?alt=media)
  * ![alt text](https://1677675178-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MWeiLnwrIKZJWLFsXhf%2Fuploads%2Fgit-blob-047d2071b3098cd3b06dbaeb60e89600bdd4ab60%2FGetImage_14.png?alt=media)
  * ![alt text](https://1677675178-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MWeiLnwrIKZJWLFsXhf%2Fuploads%2Fgit-blob-761c317dcf46ee67026c08b648b51a84da025b8c%2FGetImage_15.png?alt=media)
