Node Launch - CPP-F1TENTH-SDP/Labs GitHub Wiki

NOTE: Some code blocks contain multiple lines with appropriate spacing. This allows you to copy and paste in PowerShell/Terminal and run multiple commands at once. To paste, RIGHT click in PowerShell/Terminal.

iGPU/NVIDIA Node Launch

Note: Docker container self-destructs after closing simulation, you need to drag & drop the <node> folder into src every time.

  1. Download <node>.zip and unzip the folder.

  2. Open a PowerShell/Terminal and follow iGPU/NVIDIA Launch, 🛑STOP after running:

    source /opt/ros/foxy/setup.bash
    source install/local_setup.bash
    
    
  3. Run:

    tmux
    
  4. After tmux, hit CTRL + B, then C. You now have 2 bash instances.

    Note: Do not use CTRL for the key after 'then'. For more tmux commands visit: https://tmuxcheatsheet.com/

  5. Hit CTRL + B, then P (bash 0). Launch the simulation using:

    ros2 launch f1tenth_gym_ros gym_bridge_launch.py
    
  6. In Docker Desktop, go to the active container and click on the vertical ellipsis, then "View Files". Under "Files", find the folder sim_ws.

  7. In sim_ws, there is a folder named src. Drag & drop the unzipped folder into the src folder.

    Be sure that you are dragging the folder into src and not the contents of the folder.

  8. Hit CTRL + B, then N (bash 1) & run:

    colcon build
    source /opt/ros/foxy/setup.bash
    source install/local_setup.bash
    
    
  9. Then, run <node> using:

    ros2 run <node> <node>
    

noVNC Node Launch

  1. Download <node>.zip and unzip the folder.

  2. Launch the simulation by following noVNC Launch.

  3. In Docker Desktop, go to sim 1 container and click on the vertical ellipsis, then "View Files". Under "Files", find the folder sim_ws.

  4. In sim_ws, there is a folder named src. Drag & drop the unzipped folder into the src folder.

    Be sure that you are dragging the folder into src and not the contents of the folder.

  5. Open another PowerShell/Terminal and run:

    colcon build
    source /opt/ros/foxy/setup.bash
    source install/local_setup.bash
    
    
  6. Then, run <node> using:

    ros2 run <node> <node>
    

Keyboard Control

  1. Have the simulation launched and running.
  2. Open another window/tab of PowerShell/Terminal and run:
    source /opt/ros/foxy/setup.bash
    source install/local_setup.bash
    ros2 run teleop_twist_keyboard teleop_twist_keyboard
    
    
  3. To use the keyboard, make sure that the window/tab from step 2 is focused. 2 ways to do this is:
    1. Split screen the PowerShell/Terminal and simulation

      OR

    2. Maximize the simulation and move the terminal to a corner.

Changing the Map

Note: Do this before launching the simulation.

Download the .png and .yaml files from the F1TENTH GitHub and move it to a memorable location.

  1. In Docker Desktop, go to active container and click on the vertical ellipsis, then "View Files". Under "Files", find the folder sim_ws.

  2. In sim_ws, go to src/f1tenth_gym_ros/config. Right click sim.yaml and select "Edit file".

    Locate the maps directory within the config file:

    # map parameters
    map_path: '/sim_ws/src/f1tenth_gym_ros/maps/Spielberg_map'
    map_img_ext: '.png'
    

    Edit the "map_path" line to change the map you want to use.

    E.g: To change the Spielberg_map back to levine, edit the last part of "map_path".

    map_path: '/sim_ws/src/f1tenth_gym_ros/maps/levine'
    
  3. Go to sim_ws/src/f1tenth_gym_ros/maps and drag & drop the two map files you downloaded earlier into the maps folder.

  4. Run the following commands to rebuild and launch the simulation with the new map:

    colcon build
    source /opt/ros/foxy/setup.bash
    source install/local_setup.bash
    ros2 launch f1tenth_gym_ros gym_bridge_launch.py
    
    

Lab 2 - safety_node

Download the latest safety_node.zip from Releases.

Note: The correct download has a cube icon and lists the size of the file.

Run using:

ros2 run safety_node safety_node

Lab 3 - wall_follow

Download the latest wall_follow.zip from Releases.

Note: The correct download has a cube icon and lists the size of the file.

Run using:

ros2 run wall_follow wall_follow

Lab 4 - gap_follow

⚠️Complete but Unoptimized⚠️

Download the latest gap_follow.zip from Releases.

Note: The correct download has a cube icon and lists the size of the file.

Run using:

ros2 run gap_follow reactive_node

Lab 6 - SLAM and Pure Pursuit

Download the latest 'my_f1tenth_bot' package from Releases.

Note: The correct download has a cube icon and lists the size of the file.

If Using the Gazebo Simulator to provide SLAM and Localization:

Run SLAM using:

 ros2 launch my_f1tenth_bot sim.launch.py

Create a map by driving across the map using the teleop_twist_keyboard or one of the movement nodes like wall_follow

Save the map by running:

ros2 run nav2_map_server map_saver_cli -f /enter_the_path_location_where_you_want_the_map_saved

After running SLAM and saving the map, you need to run localization using AMCL and record the poses into a csv file using the csv_list.py

Run Localization by running 3 commands:

ros2 launch my_f1tenth_bot localization.launch.py

Change the map:=variable to the file location of your saved SLAM map.

ros2 launch nav2_bringup localization_launch.py map:=/home/hayden/ros2_ws/src/my_f1tenth_bot/maps/levine.yaml use_sim_time:=True
ros2 launch nav2_bringup navigation_launch.py use_sim_time:=True map_subscribe_transient_local:=True

After the csv file is created change the map_path and map_img_ext in the f1tenth_gym_ros/config/sim.yaml file. Change the map_path to where the saved SLAM map is.

map_path: '/sim_ws/src/nodes/my_f1tenth_bot/maps/levine'
map_img_ext: '.pgm' 

Final Step: Run the f1tenth_gym_ros simulation and the pure_pursuit.py node

ros2 launch f1tenth_gym_ros gym_bridge_launch.py
ro2 run my_f1tenth_bot pure_pursuit.py

Optimized launch settings and Scripts for Automatic Simulation Restart on Edits

This will work for simulations running on both NOVNC and the iGPU/NVIDIA launch using rocker but there are slightly different steps that I explain below.

There is also an alternative to rocker only for computers with an NVIDIA GPU called the Nvidia Container Toolkit that is slightly more convenient. Steps can be found near the bottom if you are interested.

Link to Video Demo: https://youtu.be/zE94DPURdSI

Link to script + DockerFile/docker-compose.yml files: https://github.com/CPP-F1TENTH-SDP/Labs/releases/tag/v1.0_bash_scripts

Setup Steps for running the simulation on iGPU/NVIDIA or NOVNC:

  1. Place a nodes and scripts folder inside your f1tenth_gym_ros folder on your local PC

The nodes folder will hold all the nodes you want to run and the scripts folder can be downloaded from the link above. Put all the .sh files into the scripts folder.

Node: If you are on an Arm MacBook (M1/M2 MacBook) replace the run_sim.sh script contents with the run_sim_for_arm_mac.sh script contents. Everything else works the same including the Dockerfile/docker-compose.yml (Tested on my M2 MacBook Air)

image

  1. Copy and Paste the configurations from the DockerFile and docker-compose.yml

The DockerFile is essentially unchanged but has an extra package called "bc" added to the apt-get install list. This "bc" package is needed in the watch scripts that we will use later.
The docker-compose.yml file will handle the mounting of our f1tenth_gym_ros folder to the docker container.

image

  1. Run (and Close) the Docker containers using docker compose commands

Command To Run for the First Time: docker compose up --build -d Command To Run After Building: docker compose up -d Closing Docker Containers: docker compose down

How to Use:

Prereqs) Open Docker Desktop and Enter the f1tenth_gym_ros folder through Bash/WSL Example:

image

NOVNC to Run Simulation:

1) Run the needed docker compose command to start the container

If you are running this for the first time run to run all commands in the DockerFile and start containers:

docker compose up --build -d

If you have already run --build once you can run for a faster start:

docker compose up -d

To close containers run:

docker compose down

2) Start the run_sim.sh script by running:

If the package and nodes have different names:

scripts/new_sim.sh <your_package> <your_node>

If the package and node name are the same you only need to enter the name once:

scripts/new_sim.sh <your_node>

will be any node you want to run. Example of running wall_follow

Example of Step 1 and 2:
image

After running this script you should see:

image

3) Open http://localhost:8080/vnc_lite.html on an internet browser (The script should handle this step for you)

It should look like this: image

4) Use tmux kill-session and Ctrl + C to exit when finished

tmux kill-session

image

image

Extra Notes)

Make New Terminals: Use "Ctrl + b" + "c" to create a new terminal using Tmux. This terminal will already be sourced and can run any ros2 command

image

iGPU/NVIDIA to Run Simulation

1) Run these 2 commands manually or through the setup_sim.sh script in the scripts folder:

. ~/rocker_venv/bin/activate
rocker --nvidia --x11 --volume .:/sim_ws/src/f1tenth_gym_ros --volume /mnt/c/Users/<YOUR_USER>/f1tenth_gym_ros/scripts:/sim_ws --volume /mnt/c/Users/<YOUR_USER>/f1tenth_gym_ros/nodes:/sim_ws/src/nodes -- f1tenth_gym_ros

<YOUR_USER> is the user on your PC

2) Run the run_sim.sh script by running:

if the node and package name are different enter:

./run_sim.sh <package> <node> rocker

If the node and package name are the same enter:

./run_sim.sh <node> rocker

will be any node you want to run.

Example of running wall_follow
image

After running this script you should see:

image

RViz2 will also open on your computer
image

3) Use tmux kill-session and Ctrl + C to exit when finished

tmux kill-session

image

image

You can also enter exit to go back to the bash terminal:

exit

image

Extra Notes)

Make New Terminals: Use "Ctrl + b" + "c" to create a new terminal using Tmux. This terminal will already be sourced and can run any ros2 command

image

Nvidia Container Toolkit Setup: Rocker Alternative for NVIDIA GPU Users ONLY

Prerequisites: Update the NVIDIA drivers for your GPU - https://www.nvidia.com/en-us/drivers/

Link to Guide/Demo Video: https://youtu.be/gt_lfLW8lA0

1) Install Docker on your WSL/Ubuntu Environment

In order to use the nvidia-container-toolkit we need to have docker in our WSL environment as just running Docker Desktop on our Windows Machine won't give Docker access to our gpu.

All commands are from the installation steps here: https://docs.docker.com/engine/install/ubuntu/

Open up command prompt and enter the following commands:

bash
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Note: If you have any issues with running docker commands without the sudo prefix in front follow the instructions here: https://docs.docker.com/engine/install/linux-postinstall/

Step 2: Installing the Nvidia Container Toolkit

Official Documentation: https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html

Enter the following commands:

curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg \
  && curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list | \
    sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' | \
    sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list
sudo apt-get update
sudo apt-get install -y nvidia-container-toolkit
sudo nvidia-ctk runtime configure --runtime=docker
sudo systemctl restart docker

2) Verify that Docker has access to your GPU

Enter the command

nvidia-smi

4) Edit the docker-compose.yml (and run_sim.sh file if you are using my scripts)

I provided the files in this GitHub repository all that is needed is for you to copy-paste the new code in if you followed my previous guide to installing scripts that you can use in the docker container.

5) Running the simulation

First start all the containers with the following command:

docker compose up -d

If using an internet browser to view the simulation through NOvnc enter the command:

scripts/run_sim.sh <your_package> <your_node> novnc 

If running the RViz2 simulator directy on your PC enter the command:

scripts/run_sim.sh <your_package> <your_node> local

Note: If the package and node executable have the same exact name which is the case for the safety_node and wall_follow_node you can enter

scripts/run_sim.sh wall_follow <local or novnc here>
⚠️ **GitHub.com Fallback** ⚠️