NXP-CUP 2024: Simulation Install instructions

Cognipilot simulation installation specific instructions for nxp-cup

To follow this tutorial you first need to follow and install everything explained in: CogniPilot developer guide on MR-B3RB

If your installation has been successful you must be able the launch the Gazebo simulation by running the following commands in your development computer:

Please ensure that these commands function correctly and that your setup resembles what is shown in this example video

ros2 launch b3rb_gz_bringup sil.launch.py
ros2 launch electrode electrode.launch.py sim:=true

Launching the Gazebo Harmonic simulation will enable you to control the robot via the Foxglove interface. As explained in this section: b3rb_simulation

Explanation of repository to be updated

Next, we will install all necessary packages for developing the algorithm for the NXP CUP 2024, applicable to both the MR-b3rb simulation and the actual robot.

To simplify repository updates, we've created a shell script. This script automates the process of updating all repositories to the latest versions hosted on the NXPHoverGames GitHub, specifically for the NXP Cup.

The changes on the repositories are:

  • Synapse Protobuf and Synapse Tinyframe: Define the Pixy Vector message in the Protobuf language and provide essential definitions and functions for the TinyFrame library to operate correctly. For more information, refer to the Synapse documentation.

  • Synapse msgs and Synapse ros: Extend ROS with the Pixy Vector message definition and support Synapse which the facilitates communication between NavQPlus (ROS2) and CANHUBK344 (Zephyr).

  • Dream world: Adds a simulated race track environment to the workspace.

  • B3RB simulator: Includes the launch file for the node that processes the race track images.

  • Electrode: Integrates support for the debug image and pixy vector in Foxglove, facilitating debugging and visualization.

  • Cerebri: Implements a subscribing mechanism to receive the Pixy Vector message and controls for the line follower algorithm.

  • NXP CUP Vision: Added ROS2 package for processing race track images, transforming perspectives, detecting track edges, and publishing both the debug image and the Pixy Vector, pivotal for visual processing.

Bash script to update the repositories

This file ensures that all the repositories are updated. Save this script in ~/cognipilot:

#!/bin/bash

declare -A repos=(
    ["cranium/src/synapse_protobuf"]="https://github.com/NXPHoverGames/synapse_protobuf"
    ["cranium/src/synapse_tinyframe"]="https://github.com/NXPHoverGames/synapse_tinyframe"
    ["cranium/src/synapse_msgs"]="https://github.com/NXPHoverGames/synapse_msgs"
    ["cranium/src/synapse_ros"]="https://github.com/NXPHoverGames/synapse_ros"
    ["cranium/src/dream_world"]="https://github.com/NXPHoverGames/dream_world"
    ["cranium/src/b3rb_simulator"]="https://github.com/NXPHoverGames/b3rb_simulator"
    ["electrode/src/electrode"]="https://github.com/NXPHoverGames/electrode"
    ["ws/cerebri"]="https://github.com/NXPHoverGames/cerebri"
    ["cranium/src/nxp_cup_vision"]="https://github.com/NXPHoverGames/nxp_cup_vision"
)

# Update existing repositories or clone if they don't exist
for repo in "${!repos[@]}"; do
    echo "Processing $repo..."
    repo_path="${repo}" # Derive the full path
    
    # Check if the repository directory exists. If it does not, clone it.
    if [ ! -d "${repo_path}" ]; then
        echo "Repository ${repo_path} does not exist. Cloning..."
        git clone --branch nxp-cup "${repos[$repo]}" "${repo_path}"
        echo "Cloned ${repo} into ${repo_path}."
    fi
    
    # Navigate to the repository directory
    cd "${repo_path}" || { echo "Failed to change directory to ${repo_path}. Does it exist?"; continue; }
    
    # Set the new remote URL
    git remote set-url origin "${repos[$repo]}"
    echo "Remote changed to ${repos[$repo]}"

    # Fetch changes from the new remote
    git fetch origin
    echo "Fetched changes from origin."

    # Checkout the specific branch
    git checkout nxp-cup
    if [ $? -eq 0 ]; then
        echo "Checked out nxp-cup branch."
        # Pull the latest changes from the branch
        git pull origin nxp-cup
        echo "Pulled latest changes from nxp-cup branch."
    else
        echo "Failed to checkout nxp-cup branch. Does it exist?"
    fi
    
    # Return to the original directory
    cd - > /dev/null
done

Save this script as update_repos_native.sh in the ~/cognipilot directory, using any text editor of your choice, such as Vim, Gedit, Nano, or VSCode.

Building cranium, electrode and cerebri

Then, open the terminal and execute the following commands:

cd ~/cognipilot
chmod +x update_repos_native.sh
./update_repos_native.sh

This must have updated all your repositories. Please review the output of this script. It's possible that you have made local changes to the repositories, and you may need to stash them.

To build the software, navigate to the cranium/src directory within ~/cognipilot:

cd ~/cognipilot/cranium/
colcon build --symlink-install
cd ~/cognipilot/cranium/
source install/setup.bash

Repeat the build process for the electrode directory:

cd ~/cognipilot/electrode/
colcon build --symlink-install
cd ~/cognipilot/electrode/
source install/setup.bash

Update the West workspace for cerebri.

cd ~/cognipilot/ws/cerebri
west update
west build -b native_sim app/b3rb/ -p -t install
source ~/.bashrc

Testing the update

Now, you are ready to run the simulation:

To launch the Gazebo simulation featuring the MR-B3RB robot on a simple raceway, execute:

ros2 launch b3rb_gz_bringup sil.launch.py world:=nxp_raceway_octagon

To start the Foxglove viewer for the simulation, run:

ros2 launch electrode electrode.launch.py sim:=true 

These commands will initiate the Gazebo simulation with the MR-B3RB robot and the raceway, alongside launching the Foxglove viewer.

To initiate the robot's movement, press the AUTO button and the arm button on the joystick. This action will activate the robot's line-following mode and set it to the armed state, preparing it for operation.

Once the AUTO and arm buttons on the joystick are pressed, the robot will immediately begin to navigate around the racetrack. To understand the underlying code and setup, and to explore ways to obtain a better performance for the NXP CUP 2024, proceed to the next tutorial.

Last updated