Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mdlaskey committed Apr 1, 2018
2 parents 4451ce0 + e984069 commit f033750
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 14 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[![Documentation Status](https://readthedocs.org/projects/urban-driving-simulator/badge/?version=latest)](http://urban-driving-simulator.readthedocs.io/en/latest/?badge=latest)

[![Build Status](https://travis-ci.org/jerryz123/Urban_Driving_Simulator.svg?branch=master)](https://travis-ci.org/jerryz123/Urban_Driving_Simulator)

[**Documentation**](urban-driving-simulator.rtfd.io)

# Urban Driving Simulator
This repository contains a first order driving simulator for autonomous driving in urban environments. The package implements a OpenAI Gym environment describing a city scene with cars and pedestrians.


We are currently under heavy development.

18 changes: 18 additions & 0 deletions docs/source/observations.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Observations
============
Observations are generated for each controlled car in the scene. The type of observation can be specified in the config file as 'raw', 'Q-LIDAR', or 'bitmap'. The step function in the environment returns an observation for each controlled car in the scene as a list.

Raw
^^^
A pointer to the raw environment, giving agents full access to the scene, and all other objects in the scene.

Q-LIDAR
^^^^^^^
A representation based on features a autonomus vehicle might extract from LIDAR sensors, which is the relative distance to collideable objects in the scene. This is a numpy array of distances produced by a Featurizer. The density and range of the Q-LIDAR beams can be configured in the featurizer.

.. autoclass:: gym_urbandriving.utils.featurizer.Featurizer
:members: featurize

Bitmap
^^^^^^
Returns a Numpy image array as generated by the visualizer, for vision-based control agents. Image is a top-down view of the intersection.
29 changes: 20 additions & 9 deletions gym_urbandriving/utils/featurizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,29 @@
import os


N_ARCS = 9
ARC_DELTAS = [-1, -0.5, -0.25, -0.20, -0.15, -0.1, -0.05, 0, 0.05, 0.1, 0.15, 0.20, 0.25, 0.5, 1]
ARC_DELTAS = [i*np.pi/2 for i in ARC_DELTAS]
BEAM_DISTANCE = 300

LIGHT_ARC = np.pi / 16
LIGHT_DISTANCE = 300

def distance(p1, p2):
return ((p1[0] - p2[0])**2 + (p1[1] - p2[1])**2)**0.5

class Featurizer(object):
def __init__(self):
"""
Object to convert a state observation into a Q-LIDAR observation.
Attributes
----------
beam_distance : int
How far each "LIDAR" beam will project into the scene
n_arcs :
How many "LIDAR" beams to project around the car
"""
def __init__(self, beam_distance=300, n_arcs=9):

self.arc_deltas = np.arange(n_arcs + 1) / (float(n_arcs) / 2) - 1
self.arc_deltas = [i*np.pi/2 for i in self.arc_deltas]
self.beam_distance = beam_distance
pass


Expand Down Expand Up @@ -59,12 +70,12 @@ def featurize(self, current_state, controlled_key):
features = [vel]
#print(goalx, goaly)

for arc_delta in ARC_DELTAS:
for arc_delta in self.arc_deltas:
arc_angle = angle + arc_delta
xd = x + np.cos(arc_angle)*BEAM_DISTANCE
yd = y - np.sin(arc_angle)*BEAM_DISTANCE
xd = x + np.cos(arc_angle)*self.beam_distance
yd = y - np.sin(arc_angle)*self.beam_distance
linestring = shapely.geometry.LineString([(x, y), (xd, yd)])
min_coll_d = BEAM_DISTANCE
min_coll_d = self.beam_distance
min_coll_type = None
min_coll_vel = 0
min_coll_angle = 0
Expand Down
6 changes: 3 additions & 3 deletions gym_urbandriving/visualizer/pygame_vis.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ def render_collisions(self, state, valid_area):
pygame.SRCALPHA)


for obj1id, obj2id, k in dynamic_collisions:
obj1 = state.dynamic_objects[k][str(obj1id)]
obj2 = state.dynamic_objects[k][str(obj2id)]
for obj1id, obj2id, k1, k2 in dynamic_collisions:
obj1 = state.dynamic_objects[k1][str(obj1id)]
obj2 = state.dynamic_objects[k2][str(obj2id)]
pygame.draw.circle(new_surface, (255, 0, 255), obj1.get_pos().astype(int), 5)
pygame.draw.circle(new_surface, (255, 0, 255), obj2.get_pos().astype(int), 5)
for obj1id, obj2id, k, _ in static_collisions:
Expand Down

0 comments on commit f033750

Please sign in to comment.