f1tenth / f1tenth_gym_ros

Containerized ROS communication bridge for F1TENTH gym environment.
MIT License
154 stars 106 forks source link

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:

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.

Native on Ubuntu 20.04

Install the following dependencies:

Installing the simulation:

With an NVIDIA gpu:

Install the following dependencies:

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

Installing the simulation:

  1. Clone this repo
  2. Bringup the novnc container and the sim container with docker-compose:
    docker-compose up
  3. 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
  4. 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 /opt/ros/foxy/setup.bash
    $ source install/local_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 tmux.

Configuring the simulation

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

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.

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

There are multiple ways to launch your own agent to control the vehicles.