#
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
- Install Foxglove Studio from https://foxglove.dev/download, or you can use the web version at https://studio.foxglove.dev/.
- You must have completed the setup tutorial.
#
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.
In this tab, you can use CTRL + C
at any point to stop the simulation. Use the up arrow to start it up again.
#
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)
torange
- set
Color map (gradient)
toRainbow
- 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.
- Select
- 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
If you get a build error about something not linking, delete build/
and try again.
Source the workspace:
source install/local_setup.bash
Tip: if at any point a package can't be found after you build it, verify that your sourced the workspace!
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
andspeed
.
A better alternative for manually controlling the car is an extension called virtual-joystic
by Yulong. You can add it by finding Settings
> Extensions
> virtual-joystick
then adding a panel for it.
#
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!