# Tutorial 2

# Setting up the Simulation Environment

In this tutorial, we'll walk through the process of setting up the simulation environment for AVC - F1Tenth. Additionally, we'll cover how to visualize the simulation with Foxglove Studio.

# Prerequisites


# Step 1: Build the Simulation Package

Change directories into your workspace root (ros2_ws) and execute the following.

colcon build
source install/local_setup.bash

Running colcon build without --packages-select builds every package.


# Step 2: Launch the Simulation

Next, you can launch the simulation:

ros2 launch f1tenth_gym_ros gym_bridge_launch.py

Wait for the command to execute and for the simulation to start. You should see output in your terminal indicating that the simulation has started successfully.


# Step 3: Launching the Foxglove Bridge

Once the simulation is running, the next step is to launch the Foxglove Bridge. This bridge facilitates communication between the simulation and Foxglove Studio, enabling you to visualize the simulation. Execute the following command in a split pane (Ctrl+b, ") to launch the Foxglove Bridge:

ros2 launch foxglove_bridge foxglove_bridge_launch.xml

At this point, you should have three terminals for the simulation. It should look something like this:


# Step 4: Visualizing the Simulation with Foxglove Studio

Open Foxglove Studio (either the installed version or the web version at https://studio.foxglove.dev/).

Then, open a new remote connection to ws://localhost:8765.

Inside Foxglove Studio:

  • Click on the 3D panel (in the middle), click panel in the top left.
  • Under Topics, enable visibility for all topics by clicking the eye icons.
  • Disable the labels by going to Transforms > Settings > Labels (Off).
  • Under the /scan topic dropdown:
    • increase the radius to 15
    • change Color by (intensity) to range
    • set Color map (gradient) to Rainbow
  • Click on Custom Layers > ⋮ (three dots) > Add URDF.
    • Select Topic as the source and enter /ego_robot_description in the topic input. The car should appear.
  • Mess around with the settings to get an environment you like.

# Step 5: Install Ackermann Messages

In another pane (Ctrl+b, %) or window (Ctrl+b, C and Ctrl+b, {0-9} to switch windows), navigate to your workspace's source directory:

cd /ros2_ws/src

Clone the Ackermann Messages Repository:

git clone -b ros2 https://github.com/ros-drivers/ackermann_msgs.git
rm -rf ackermann_msgs/.git

Navigate back to your workspace root (/ros2_ws/) and build:

cd /ros2_ws/
colcon build

Source the workspace:

source install/local_setup.bash

To use AckermannDriveStamped in Foxglove Studio (virtual controller, etc), stop the Foxglove bridge from step 2, build your workspace, source it, then run Foxglove bridge again.


# Step 6: Making the Car Move

You can command the car to move by publishing a AckermannDriveStamped message to /drive. Here is a command (which you can run in your terminal) that will make the car move forward:

ros2 topic pub /drive ackermann_msgs/msg/AckermannDriveStamped "drive: {steering_angle: 0.5, speed: 1.0}"

Feel free to mess around with the steering_angle and speed.


# Step 7: Resetting the Car Position

You can reset the position of the car in the simulation by publishing a pose estimate to /initialpose from inside Foxglove Studio.


# Step 8: Simulation settings

Explore the F1Tenth simulation's settings such as different maps and multiple vehicles under sim/config/sim.yaml. Remember to colcon build and source the sim environment (source install/local_setup.bash) to apply any modifications. Restarting the Docker also applies changes.


And there you have it! You've successfully set up and visualized the simulation environment for AVC - F1Tenth. If you encounter any issues, don't hesitate to refer back to this guide or reach out for further assistance. Happy simulating!