Git Product home page Git Product logo

intersection-carla-gym's Introduction

Intersection Environment for Training Reinforcement Learning Algorithms

Push to Docker Hub

OpenAI gym and Gymnasium environment for CARLA Simulator, particularly for a 4-way unsignalized intersection environment.

Getting Started

System Requirements

The following are the requirements for running this repository using the provided docker files:

  • Operating System: Linux (tested on Ubuntu 20.04)
  • NVIDIA GPU with CUDA support (tested on NVIDIA GeForce RTX 3060/3080/3090)

Prerequisites

Setup

  1. Clone the repository

    git clone https://github.com/faizansana/intersection-carla-gym.git
    
  2. (Optional) If you want to use the gymnasium environment, then use the main branch. To use gym v0.21, checkout the following branch.

    git checkout gym-v0.21
    
  3. From within the working directory, open the dev_config.sh file to change any specific requirements such as CARLA version, CUDA version etc.

  4. Run the dev_config.sh file to set the environment variables for docker.

    bash dev_config.sh
    
  5. Pull the already built containers from docker hub if they are available.

    docker compose pull
    
  6. After the containers have been pulled, start them using the following command.

    docker compose up -d
    
  7. (Optional) Open the main_container, and attach it to VS Code using the Remote Explorer extension

Usage (from within main container)

  1. Setup a configuration file based on your requirements:

    exp_name: "first_test" # Name of experiment
    output_dir: "output" # Name of output directory for logs
    env:
        obs_space: "dict" # Choose from "dict" or "normal"
        continuous: True # If False then discrete mode is used
        target_speeds: [0, 3, 6, 9, 12] # For discrete speed control
        desired_speed: 12 # For continuous speed control
        dt: 0.05 
        render: false
        ego_vehicle_filter: "vehicle.lincoln*" # Vehicle to use for ego vehicle
        num_veh: 1 # Number of vehicles in each intersection except ego vehicle
        num_ped: 1 # Number of pedestrians at each crosswalk
        max_steps: 500 # Maximum number of steps per episode
        CAM_RES: 1024 # Camera resolution for rendering
        max_waypt: 200 # Maximum number of waypoints
        pedestrian_proximity_threshold: 2.0 # Threshold to give negative reward when vehicle distance to pedestrian is less than this value
        vehicle_proximity_threshold: 2.5 # Threshold to give negative reward when vehicle distance to other vehicle is less than this value
        reward_weights:
            # Route completion reward
            c_completion: 100.0
            # Collision penalty with vehicle
            c_terminal_collision: -100.0
            # Collision penalty with pedestrian
            c_terminal_pedestrian_collision: -200.0
            # Timeout penalty
            c_terminal_timeout: -10.0
            # Velocity reward constants
            c_v_eff_under_limit: 1.0
            c_v_eff_over_limit: -2.0
            # Penalty for needing another step
            r_step: -0.0
            # Penalty for non-smooth actions
            c_action_reg: -0.0
            # Penalty for yaw delta w.r.t. road heading
            c_yaw_delta: -0.0
            # Penalty for lateral deviation
            c_lat_dev: -0.0
            # Distance from goal penalty
            c_dist_from_goal: 3.5
            # Progress reward
            c_progress: 0.0
            # Penalty for being close to pedestrians
            c_pedestrian_proximity: -10.0
            # Penalty for being close to vehicles
            c_vehicle_proximity: -5.0
  2. Save the config file as config_name.yaml.

  3. Setup the environment using the following code snippet. This is also found in test_env.py.

    import yaml
    
    import carla_env_custom
    
    if __name__ == "__main__":
        cfg = yaml.safe_load(open("config_name.yaml", "r"))
        env = carla_env_custom.CarlaEnv(cfg=cfg, host="HOST", tm_port=9000)
    
        obs, info = env.reset()
    
        while True:
                obs, reward, done, _, info = env.step(np.array([1.0], dtype=np.float32))
                if done:
                    obs, info = env.reset()

A demo video of the environment with num_veh set to 1 and num_ped set to 2 is shown below.

2024-02-22_20-43-29.mp4

The following video shows interfacing with PlotJuggler. 26 values are available to be viewed within PlotJuggler.

2024-02-23_15-52-03.mp4

intersection-carla-gym's People

Contributors

deepsource-io[bot] avatar dependabot[bot] avatar faizansana avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

marinbao

intersection-carla-gym's Issues

Enhance logging system

Currently the logs are created using the experiment name and output dir params in the config file. This doesn't seem too useful so think of a better way of enhancing the logging and reduce the tree structure of config yaml file.

Look into setting no render mode for CARLA

In this case, since we are not depending on sensor states (LiDAR, camera etc.) and only care about other vehicle states, pedestrians etc. using no render mode makes sense. This would also reduce resource consumption and increase FPS. Documentation is here

Upgrade reward function to incorporate pedestrian penalty

At the moment, the model, even after learning for 1.5 million steps, still crashes into pedestrians.

  • Incorporating penalties for getting close to pedestrians in dense rewards might help.
  • Larger negative reward for crashing into pedestrian.

Segmentation fault occurring after n random timesteps

The environment exits with a segmentation fault that occurs after n timesteps. This is an indeterministic number failing within even 2000 timesteps and as late as never as seen.

The following has been observed.

  • It is seen to fail faster in python 3.8.16 (environment.yml) as compared to 3.7
  • It was thought that this might be due to the collision sensor. However, the collision sensor was completely removed from the script and it stil continued to fail.
  • This seg fault might be occurring due to failure of destroying the actor. It seems that the seg fault is occurring due to the carla library. However since the carla python library is a wrapper for C code, it is hard to debug exactly what is going wrong.
  • After the traffic manager instantiation was moved to after setting it to synchronous mode, it seems these seg faults occur less. However, this could be unrelated.

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.