Skip to content

max1408/Car_Intersection

Repository files navigation

Car Movement on a road intersection

This is a compatible with OpenAI gym enviroment which models movements of a car on a road intersection.

To run an agent please see folder gym-car-intersect.

To train discrete environment:

cd gym-car-intersect
python run_agent.py

Description

The environment is a road intersection. Your agent (red car) started along with some number (default is 4) of bot cars (blue cars) which move along random predefined trajectories, i.e. left, straight, right.

Your agent receives reward 10 after reaching a red rectangle and then the environment is reset. Along the way some penalties would be appointed for moving in the wrong way. Driving on sidewalks or colliding with another car in addition to penalty resets environment.

An agent is controlled by four actions (steer angle, gas, break).

The goal is to reach a destination in the fastest and safest way possible.

Getting Started

To make this environment integral part of your gym please follow instructions in OpenAI custom gym.

Prerequisites

Run:

pip install -r requirements.txt

Obviously you need also your favorite deeplearning framework to train an agent. (Make sure you did install box2d). If you are still in trouble try:

pip install gym['box2d']

Running the environment

If you want simply to check how the environment works just run:

python main.py

You can control an agent (red car) by arrow keys.

Some modifications is also available. See some flags below.

To set the number of bot cars:

python main.py --bots_number=2

To remove an agent completely from the picture:

python main.py --no_agent

To define your own start positions make changes in start_file.csv. For further instructions see the file.

Command to get data from file:

python main.py --using_start_file

To write positions of the cars while running environment run:

python main.py --write

The default file the data is written to is car_racing_positions.csv. To change it:

python main.py --dir DIR

It keeps numbers for cars' positions after each tick in environment. First three numbers is car_angle, car_pos_x, car_pos_y; Then the same three numbers (angle, position x, position y) go for each bot car.

(FYI: Entire Playfield is from -60 to 60 units. Road width is 16 units. Center of crossroad is (0,0))

Example

If everything is ok you will see the following picture:

initial state

About

compatible with OpenAI gym environment which model car movements in road intersection.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published