Skip to content

Containerized ROS communication bridge for F1TENTH gym environment.

License

Notifications You must be signed in to change notification settings

Adi-Levy/f1tenth_gym_ros

 
 

Repository files navigation

F1TENTH gym environment ROS2 communication bridge

This is a containerized ROS communication bridge for the F1TENTH gym environment that turns it into a simulation in ROS2.

Installation

Supported System:

  • 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)
  • Windows 10/11 over WSL2 without an NVIDIA gpu (using noVNC) - jump to Without Nvidia GPU section

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.

If you are using a Windows system, you'll have to use WSL (Windows Subsystem for Linux). Please refer to the guide here for WSL 2 installation and configuration. It is recommended to use Ubuntu 20.04 as the base OS for WSL 2 as well as the Windows terminal app (guid for setting up windows terminal can be found here).

Native on Ubuntu 20.04

Install the following dependencies:

  • ROS 2 Follow the instructions here to install ROS 2 Foxy.
  • 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/f1tenth/f1tenth_gym_ros
  • 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 the map_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/foxy/setup.bash
    cd ..
    rosdep install -i --from-path src --rosdistro foxy -y
  • Build the workspace: colcon build

With an NVIDIA gpu:

Install the following dependencies:

  • Docker Follow the instructions here to install Docker. A short tutorial can be found here if you're not familiar with Docker. If you followed the post-installation steps you won't have to prepend your docker and docker-compose commands with sudo.
  • nvidia-docker2, follow the instructions here if you have a support GPU. It is also possible to use Intel integrated graphics to forward the display, see details instructions from the Rocker repo. If you are on windows with an NVIDIA GPU, you'll have to use WSL (Windows Subsystem for Linux). Please refer to the guide here (nvidia cuda driver), here (nvidia cuda driver install), and here (activating cuda on wsl).
  • rocker https://github.com/osrf/rocker. This is a tool developed by OSRF to run Docker images with local support injected. We use it for GUI forwarding. If you're on Windows, WSL should also support this.

Installing the simulation:

  1. Clone this repo
  2. Build the docker image by:
$ cd f1tenth_gym_ros
$ docker build -t f1tenth_gym_ros -f Dockerfile .
  1. To run the containerized environment, start a docker container by running the following. (example showned here with nvidia-docker support). By running this, the current directory that you're in (should be f1tenth_gym_ros) is mounted in the container at /sim_ws/src/f1tenth_gym_ros. Which means that the changes you make in the repo on the host system will also reflect in the container.
$ rocker --nvidia --x11 --volume .:/sim_ws/src/f1tenth_gym_ros -- f1tenth_gym_ros

Without an NVIDIA gpu:

Install the following dependencies:

If your system does not support nvidia-docker2, noVNC will have to be used to forward the display.

  • Again you'll need Docker. Follow the instruction from above.
  • Additionally you'll need docker-compose. Follow the instruction here to install docker-compose.

If you are installing over Windows or WSL simply install the Docker Windows desktop app in order to install both of the above dependencies, here are the instructions.

Follow the instructions here in order to integrate Docker into WSL, as well as making sure that the Ubuntu distribution you are working with on WSL is enabled in the docker desktop app in settings->resources->WSL integration

Installing the simulation:

  1. Clone this repo
  2. Build the docker image by:
$ cd f1tenth_gym_ros
$ docker build -t f1tenth_gym_ros -f Dockerfile .
  1. Bringup the novnc container and the sim container with docker-compose:
docker-compose up

or

docker compose up
  1. In a separate terminal, run the following, and you'll have the a bash session in the simulation container. tmux is available for convenience.
docker exec -it f1tenth_gym_ros-sim-1 /bin/bash
  1. In your browser, navigate to http://localhost:8080/vnc.html, you should see the noVNC logo with the connect button. Click the connect button to connect to the session.

Launching the Simulation

  1. tmux is included in the contianer, so you can create multiple bash sessions in the same terminal.
  2. To launch the simulation, make sure you source both the ROS2 setup script and the local workspace setup script. Run the following in the bash session from the container:
$ source install/setup.bash
$ ros2 launch f1tenth_gym_ros gym_bridge_launch.py

A rviz window should pop up showing the simulation either on your host system or in the browser window depending on the display forwarding you chose.

You can then run another node by creating another bash session in either:

  • tmux in the container
  • a new terminal on the host system (if you are using WSL and Windows terminal this can be done by either opening a new tab or splitting the current terminal) and connecting to the same container with the docker exec command from above.

Configuring the simulation

  • 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 the yaml 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.

Topics published by the simulation

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

Topics subscribed by the simulation

/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

Keyboard Teleop

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.

Developing and creating your own agent in ROS 2

Create 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.

About

Containerized ROS communication bridge for F1TENTH gym environment.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 92.8%
  • Dockerfile 7.2%