Giter VIP home page Giter VIP logo

f1tenth_gym's Introduction

Python 3.8 3.9 Docker

The F1TENTH Gym environment

This is the repository of the F1TENTH Gym environment.

This project is still under heavy developement.

You can find the documentation of the environment here.

Quickstart

We recommend installing the simulation inside a virtualenv. You can install the environment by running:

virtualenv gym_env
source gym_env/bin/activate
git clone https://github.com/f1tenth/f1tenth_gym.git
cd f1tenth_gym
pip install -e .

Then you can run a quick waypoint follow example by:

cd examples
python3 waypoint_follow.py

A Dockerfile is also provided with support for the GUI with nvidia-docker (nvidia GPU required):

docker build -t f1tenth_gym_container -f Dockerfile .
docker run --gpus all -it -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix f1tenth_gym_container

Then the same example can be ran.

Known issues

  • Library support issues on Windows. You must use Python 3.8 as of 10-2021
  • On MacOS Big Sur and above, when rendering is turned on, you might encounter the error:
ImportError: Can't find framework /System/Library/Frameworks/OpenGL.framework.

You can fix the error by installing a newer version of pyglet:

$ pip3 install pyglet==1.5.20

And you might see an error similar to

f110-gym 0.2.1 requires pyglet<1.5, but you have pyglet 1.5.20 which is incompatible.

which could be ignored. The environment should still work without error.

Citing

If you find this Gym environment useful, please consider citing:

@inproceedings{okelly2020f1tenth,
  title={F1TENTH: An Open-source Evaluation Environment for Continuous Control and Reinforcement Learning},
  author={O’Kelly, Matthew and Zheng, Hongrui and Karthik, Dhruv and Mangharam, Rahul},
  booktitle={NeurIPS 2019 Competition and Demonstration Track},
  pages={77--89},
  year={2020},
  organization={PMLR}
}

f1tenth_gym's People

Contributors

abhaybd avatar ayoubraji avatar bdevan5 avatar damowerko avatar eghignone avatar gongsta avatar hzheng40 avatar nandantumu avatar snoyes avatar travelbureau avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

f1tenth_gym's Issues

Model reference point is different when switching

The reference point for vehicle_dynamics_st() and vehicle_dynamics_ks() is not the same so switching between them is not correct. Instead of using vehicle_dynamics_ks() we can use vehicle_dynamics_cog (here) which will solve the problem.

Reset randomness

Currently, the scan still has random noise when reset is called.
Current behavior: reset() returns different observations with the same argument used depending on how many times reset() is called on the same instance of env. This creates an enormous inconvenience when trying to reproduce experiments.
Expected behavior: reset() should return the same observation with the same argument no matter how many times it's been called on the same env instance.

unexpected collision tracking trajectory in Monza

Describe the bug
Termination due to collision is triggered without any visible collision with the map boundaries.

To Reproduce
Steps to reproduce the behavior:

  1. Run the example script waypoint_follow.py from Monza or Austin.
  2. For example, make the env as follows:
env = gym.make(
        "f110_gym:f110-v0",
        config={
            "map": "Monza",
            "num_agents": 1,
            "timestep": 0.01,
            "integrator": "rk4",
            "control_input": "speed",
            "model": "st",
            "observation_config": {"type": "kinematic_state"},
            "params": {"mu": 1.0},
        },
        render_mode="human",
    )
  1. Experience collision at time 1.16

Expected behavior
No collision is expected, at least looking at the rendered simulation (see screenshot).

It looks to depend on the relatively high threshold in the collision detection method.
In fact, changing the ttc_thresh from 0.005 to 0.0000005, no collision occurs.
I think @nandantumu had a similar issue in other tracks too.

However, the problem is in the proximity of walls. Many new tracks present racelines with a very small margin to the wall.
If we lose further accuracy by changing the method for collision check (e.g., occupancy map), this issue might become more severe.

Screenshots
image

Desktop (please complete the following information):

  • OS: Ubuntu 20.04
  • Python 3.8
  • Branch v1.0.0

DockerfileUI entrypoint script "worker_online.py" is missing

Problem description:

The entrypoint script worker_online.py (referenced in DockerfileUI) is missing.

Steps to reproduce:

docker build -t f1tenth_gym_ui -f DockerfileUI .
xhost local:$USER
docker run --gpus all -it --name=f1tenth_gym_ui_container --rm -p 5557:5557 -p 5558:5558 -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix f1tenth_gym_ui

Output:

python3: can't open file 'worker_online.py': [Errno 2] No such file or directory

Supported RL framework?

Hi there,

Thanks for your nice work! I tried to train an RL agent using stable baselines for your gym. But I've got several bugs since your gym is slightly different than the standard OpenAI gym. I was wondering which RL framework did you use in your RL experiments or which RL framework is compatible with your gym? Here are a few differences I encountered for stable baselines (these are rather easy to solve but I was just wondering which RL framework would work out of box with your env)

  • no observation_space and action_space defined
  • reset method returns more than just obs
  • to be discovered...

v1.0.0 Waypoint follow example results in frequent crashes

Describe the bug
The root cause of this behavior is that the reset function does not provide the opportunity to choose the raceline on the track that is used for restarts. The PurePursuit controller overcorrects, and this results in a crash.

To Reproduce
Steps to reproduce the behavior:

  1. Run the waypoint follow example

Expected behavior
The waypoint follow should not result in a crash

Additional context
Adding an additional option to set the line along which a respawn happens would fix this issue. This is inside masked_reset.py

Compile proto files at build time

Compile .proto files every time Dockerfile is built.

Add command in Dockerfile to run protoc and output protobuf generated files to correct paths instead of using cp in Dockerfile.

Individual lap time observation and lap count config

Currently, there is no option to change the number of laps that the agent drives before terminated and done are flagged as true. Additionally, the lap time observation is actually a total time observation for all (two) laps in this case.

The _check_done function would need to be rewritten to accomodate a config setting. The lap times calculation would need to be reworked to compute current lap time.

How to reset environment state?

Whenever I launch the demo now it is already collided. I may have clicked save by mistake but I redownloaded the gym_bridge.rviz here and uploaded it and it still did not work

Add random track generator

Add a random track generator and instructions on how to use it.

  • Need to fix behavior when fails to generate
  • Generator need to return the start/finish line also (need to explore options when creating starting positions for multiple agents)
  • Add documentation on what the hyperparameters are for the generator (e.g. # nodes and radius)

Vec env init takes a long time

Not sure why this is happening, but when initializing vec envs it takes way longer:

python3 -m timeit -n 1 -v "import gymnasium as gym; gym.make('f110_gym:f110-v0')" 
raw times: 4.96 sec, 4.5 sec, 4.98 sec, 4.93 sec, 4.89 sec

python3 -m timeit -n 1 -v "import gymnasium as gym; [gym.make('f110_gym:f110-v0') for _ in range(10)]" 
raw times: 48.2 sec, 44 sec, 45.1 sec, 44.9 sec, 46 sec

python3 -m timeit -n 1 -v "import gymnasium as gym; gym.make_vec('f110_gym:f110-v0', num_envs=10)" 
raw times: 378 sec, 384 sec, 376 sec, 409 sec, 417 sec

I think the expectation is that it should scale linearly with the number of envs.

bring the scan update outside the state update

As in the title, bring the update of the scan outside this method, so that update_poseis only responsible for updating the racecar state.

In the future, we could compute the scan only if required by the observation space, so it would be better to separate it.

Note: currently the collision check relies on the scan, so this issue depends on finding an alternative way to check for collisions.

Originally posted by @luigiberducci in #74 (comment)

Move edt as part of track asset

Move the Euclidean Distance Transform matrix to part of the track asset, together with the image file and the yaml file.
This speeds up gym.make and also streamlines the transition to JAX-based env.

In addition, provide script for users to create the matrix from image for custom maps.

Exploding angular velocity

Describe the bug
I've found that by taking certain actions, the simulator can be prompted to calculate impossibly large angular velocity values. Once the angular velocity starts exploding, it creates a runaway effect and can increase to millions or billions of radians/sec.

To Reproduce
The following code example produces an angular velocity of -82084.6562721812, which is obviously impossible.

from f110_gym.envs import F110Env
from f110_gym.envs.base_classes import Integrator
import numpy as np


env = F110Env(num_agents=1, integrator=Integrator.Euler)
env.reset(np.array([[0, 0, -0.5]]))

max_reverse = env.params["v_min"]
max_steer = env.params["s_min"]

for _ in range(5):
    _, _, done, _ = env.step(np.array([[0, max_reverse]]))
    assert not done

for _ in range(25):
    obs, _, done, _ = env.step(np.array([[max_steer, max_reverse]]))
    assert not done

print(obs) # notice that angular velocity is impossibly large

I'm currently training reinforcement learning algorithms with this environment, but runs keep failing because the agent may accidentally trigger this behavior. Is this a bug in the dynamics? This behavior appears for both euler integration as well as RK4, even after the bugfix introduced by #52.

Simplify gym env initialization

Currently, the environment needs to be initialized by several file paths and explicitly defined physical parameters of the car.

Proposed changes are to make these file paths and parameters default in the initialization, and include in the documentation how to use non-default parameters when initializing the environment.

Lap timing and finish line checking

Explore the option of using @ayoubraji 's method of finish line condition checking.
(Project agent's current position onto the centerline of the track and check the cumulated arc length)

Single finish line for all agents on the track.

Idea: add random obstacle to track

The ROS simulator has a great feature of being able to easily add and remove random obstacles on the track.
I think this feature would be very useful in this simulator too, namely to test benchmark 2 which is a track with random obstacles.

Error while setting up the project

Describe the bug
On running the command pip3 install -e . I get the following error:
image

To Reproduce
Steps to reproduce the behavior:

  1. Create a virtual env.
  2. run pip3 install -e .

Expected behavior
The dependencies should get installed and set up should be complete without errors.

Desktop (please complete the following information):

  • OS: macOS Ventura v13.3.1

Lap time accuracy

Bug description
As already privately signaled to the developers, it happens sometimes that the car goes really close to the boundaries and so it triggers the checkpoint used by the lap time system which is in reality in the opposite part of the track.

For example, sometimes it gives me 12s and other times 20s depending on how close the car goes to the boundaries.

To Reproduce
Watch the videos.

Expected behavior
As already have been told me correcting the starting lane width can fix the problem but I think it should be used a more accurate solution. At least for the future.

Suggested solution
Consider using the projection of the car position in a reference path, so using a spline and check whenever the car passes a certain s position on the spline. We use this system in our simulators and in the real f1tenth car, it seems accurate.

To do it in python:

  1. PythonRobotics cubic_spline_planner
  2. before starting, create the spline for a reference trajectory:
    path = Spline2D(xs, ys)
  3. at each iteration, update actual pose on the path:
 path.update_current_s(car_pose)

and then check if it passed a s_reference:
if path.cur_s > s_reference:

Of course this should be done for each car, so having two path variables but if you use the calc_s function maybe you can use a unique path variable and check the projection of each car using path.calc_s(x,y). In this way it should be faster.

For any further detail don't hesitate to contact me. If you want I can even create a fork of the sim and make the changes and then let you know how it goes.

refactoring of track ingestion

  1. restructure map dir with subfolders, e.g. maps/<racetrack_name>/
  2. create racetrack object containing occupancy, centerline and raceline (if available) to avoid the user to load cvs files for the planner
  3. simplify the env creation by passing only the map_name, without map_path and map_ext
  4. automatic download racetracks from f1tenth_racetracks

Decoupled Action Spaces

Description: CarAction currently specifies speed or acceleration control jointly for steering and vx/ax. To mix between the two CarAction types, we would need to create one class per combination.

Suggested Feature: Separate CarAction into SpeedAction and SteerAction to allow for separate types for speed and steer.

rendering in pygame

Steps to do:

  • Implement EnvRenderer with pygame
  • Add wheels to visualize the rotation
  • Implement zoom-in and follow a given vehicle (e.g., ego)
  • Implement a set of callbacks to visualize global/local plans

create configurable termination conditions

Each track has now a centerline, we can use the longitudinal progress to check lap completion.

Since everyone might have different termination conditions in mind, we want to implement a predefined set of termination conditions (e.g., event-based events, like "on crossing the finish line", "on ego collision", "on any collision").

Example agent Dockerfile

Add example files for setting up an agent using the gym environment.

  • Template Dockerfile, including comments on how to add dependencies
  • Build and run scripts
  • (tentative) native installation script

Installed docker container but libraries not installed

Hello,

This shouldn't be a bug from your end.
I followed the README documentation and ran the docker scripts. However, it seems that, inside the container environment, no libraries are installed including gym, numpy, and even Python.

I don't have much experience with Docker but it's not clear what I am missing. Would be happy to know if anyone else had the same issue

update documentation

Remove deprecated sections:

  • Usage/Customized Usage Example/Custom Map/Random Track Generator (Beta)
  • Signature reset/step in Example Usage/Customized Usage Example/Multiple Agents
  • Empty section on Reproducibility

Enhancements:

  • Add Example for choice of dynamics model in Usage/Customized Usage Example/Changing Parameters in Vehicle Dynamics
  • Add section on different observation spaces (e.g., kinematic, dynamic, custom features)
  • Update section API Referece/What’s In an Observation
  • Update README

See pull request #50

Dockerfile clean up

Remove unnecessary environment variables and clean up dependencies.

  • Remove ENV_IM_IN_DOCKER
  • Remove emacs and add vim
  • Pin protobuf version
  • Remove torch install

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.