This is a containerized ROS communication bridge for the F1TENTH gym environment that turns it into a simulation in ROS2.
Supported System:
- Ubuntu (tested on 22.04) native with ROS 2
- Ubuntu (tested on 20.04) native with ROS 2
- Ubuntu (tested on 20.04) with an NVIDIA gpu and nvidia-docker2 support
- Windows 10, macOS, and Ubuntu without an NVIDIA gpu (using noVNC)
This installation guide will be split into instruction for installing the ROS 2 package natively, and for systems with or without an NVIDIA gpu in Docker containers.
Install the following dependencies:
- ROS 2 Follow the instructions here to install ROS 2 Iron.
- F1TENTH Gym
git clone https://github.com/f1tenth/f1tenth_gym cd f1tenth_gym && pip3 install -e .
Installing the simulation:
- Create a workspace:
cd $HOME && mkdir -p sim_ws/src
- Clone the repo into the workspace:
cd $HOME/sim_ws/src git clone https://github.com/Autonomous-Racing-Labs/f1tenth_gym_ros.git
- Update correct parameter for path to map file:
Go to
sim.yaml
https://github.com/f1tenth/f1tenth_gym_ros/blob/main/config/sim.yaml in your cloned repo, change themap_path
parameter to point to the correct location. It should be'<your_home_dir>/sim_ws/src/f1tenth_gym_ros/maps/levine'
- Install dependencies with rosdep:
source /opt/ros/iron/setup.bash cd .. apt install python3-rosdep2 python3-colcon-ros rosdep update rosdep install -i --from-path src --rosdistro iron -y
- Build the workspace:
colcon build
- Run the simulation:
source /opt/ros/iron/setup.bash source install/local_setup.bash ros2 launch f1tenth_gym_ros gym_bridge_launch.py
- The configuration file for the simulation is at
f1tenth_gym_ros/config/sim.yaml
. - Topic names and namespaces can be configured but is recommended to leave uncahnged.
- The map can be changed via the
map_path
parameter. You'll have to use the full path to the map file in the container. The map follows the ROS convention. It is assumed that the image file and theyaml
file for the map are in the same directory with the same name. See the note below about mounting a volume to see where to put your map file. - The
num_agent
parameter can be changed to either 1 or 2 for single or two agent racing. - The ego and opponent starting pose can also be changed via parameters, these are in the global map coordinate frame.
The entire directory of the repo is mounted to a workspace /sim_ws/src
as a package. All changes made in the repo on the host system will also reflect in the container. After changing the configuration, run colcon build
again in the container workspace to make sure the changes are reflected.
In single agent:
/scan
: The ego agent's laser scan
/ego_racecar/odom
: The ego agent's odometry
/map
: The map of the environment
A tf
tree is also maintained.
In two agents:
In addition to the topics available in the single agent scenario, these topics are also available:
/opp_scan
: The opponent agent's laser scan
/ego_racecar/opp_odom
: The opponent agent's odometry for the ego agent's planner
/opp_racecar/odom
: The opponent agents' odometry
/opp_racecar/opp_odom
: The ego agent's odometry for the opponent agent's planner
In single agent:
/drive
: The ego agent's drive command via AckermannDriveStamped
messages
/initalpose
: This is the topic for resetting the ego's pose via RViz's 2D Pose Estimate tool. Do NOT publish directly to this topic unless you know what you're doing.
TODO: kb teleop topics
In two agents:
In addition to all topics in the single agent scenario, these topics are also available:
/opp_drive
: The opponent agent's drive command via AckermannDriveStamped
messages. Note that you'll need to publish to both the ego's drive topic and the opponent's drive topic for the cars to move when using 2 agents.
/goal_pose
: This is the topic for resetting the opponent agent's pose via RViz's 2D Goal Pose tool. Do NOT publish directly to this topic unless you know what you're doing.
The keyboard teleop node from teleop_twist_keyboard
is also installed as part of the simulation's dependency. To enable keyboard teleop, set kb_teleop
to True
in sim.yaml
. After launching the simulation, in another terminal, run:
ros2 run teleop_twist_keyboard teleop_twist_keyboard
Then, press i
to move forward, u
and o
to move forward and turn, ,
to move backwards, m
and .
to move backwards and turn, and k
to stop in the terminal window running the teleop node.
There are multiple ways to launch your own agent to control the vehicles.
- The first one is creating a new package for your agent in the
/sim_ws
workspace inside the sim container. After launch the simulation, launch the agent node in another bash session while the sim is running. - The second one is to create a new ROS 2 container for you agent node. Then create your own package and nodes inside. Launch the sim container and the agent container both. With default networking configurations for
docker
, the behavior is to put The two containers on the same network, and they should be able to discover and talk to each other on different topics. If you're using noVNC, create a new service indocker-compose.yml
for your agent node. You'll also have to put your container on the same network as the sim and novnc containers.