Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
fyctime052 authored Jan 26, 2024
1 parent e62a67b commit 7de14c9
Show file tree
Hide file tree
Showing 37 changed files with 3,496 additions and 0 deletions.
64 changes: 64 additions & 0 deletions roach/config/config_agent.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
entry_point: roach.rl_birdview_agent:RlBirdviewAgent
wb_run_path: null
wb_ckpt_step: null
env_wrapper:
entry_point: roach.utils.rl_birdview_wrapper:RlBirdviewWrapper
kwargs:
input_states:
- control
- vel_xy
acc_as_action: true
policy:
entry_point: roach.models.ppo_policy:PpoPolicy
kwargs:
policy_head_arch:
- 256
- 256
value_head_arch:
- 256
- 256
features_extractor_entry_point: roach.models.torch_layers:XtMaCNN
features_extractor_kwargs:
states_neurons:
- 256
- 256
distribution_entry_point: roach.models.distributions:BetaDistribution
distribution_kwargs:
dist_init: null
training:
entry_point: roach.models.ppo:PPO
kwargs:
learning_rate: 1.0e-05
n_steps_total: 12288
batch_size: 256
n_epochs: 20
gamma: 0.99
gae_lambda: 0.9
clip_range: 0.2
clip_range_vf: null
ent_coef: 0.01
explore_coef: 0.05
vf_coef: 0.5
max_grad_norm: 0.5
target_kl: 0.01
update_adv: false
lr_schedule_step: 8
obs_configs:
birdview:
module: birdview.chauffeurnet
width_in_pixels: 192
pixels_ev_to_bottom: 0
pixels_per_meter: 5.0
history_idx:
- -1
- -1
- -1
- -1
scale_bbox: true
scale_mask_col: 1.0
speed:
module: actor_state.speed
control:
module: actor_state.control
velocity:
module: actor_state.velocity
64 changes: 64 additions & 0 deletions roach/config/config_agent_original.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
entry_point: roach.rl_birdview_agent:RlBirdviewAgent
wb_run_path: null
wb_ckpt_step: null
env_wrapper:
entry_point: roach.utils.rl_birdview_wrapper:RlBirdviewWrapper
kwargs:
input_states:
- control
- vel_xy
acc_as_action: true
policy:
entry_point: roach.models.ppo_policy:PpoPolicy
kwargs:
policy_head_arch:
- 256
- 256
value_head_arch:
- 256
- 256
features_extractor_entry_point: roach.models.torch_layers:XtMaCNN
features_extractor_kwargs:
states_neurons:
- 256
- 256
distribution_entry_point: roach.models.distributions:BetaDistribution
distribution_kwargs:
dist_init: null
training:
entry_point: roach.models.ppo:PPO
kwargs:
learning_rate: 1.0e-05
n_steps_total: 12288
batch_size: 256
n_epochs: 20
gamma: 0.99
gae_lambda: 0.9
clip_range: 0.2
clip_range_vf: null
ent_coef: 0.01
explore_coef: 0.05
vf_coef: 0.5
max_grad_norm: 0.5
target_kl: 0.01
update_adv: false
lr_schedule_step: 8
obs_configs:
birdview:
module: birdview.chauffeurnet
width_in_pixels: 192
pixels_ev_to_bottom: 40
pixels_per_meter: 5.0
history_idx:
- -16
- -11
- -6
- -1
scale_bbox: true
scale_mask_col: 1.0
speed:
module: actor_state.speed
control:
module: actor_state.control
velocity:
module: actor_state.velocity
30 changes: 30 additions & 0 deletions roach/criteria/blocked.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import numpy as np


class Blocked():

def __init__(self, speed_threshold=0.1, below_threshold_max_time=90.0):
self._speed_threshold = speed_threshold
self._below_threshold_max_time = below_threshold_max_time
self._time_last_valid_state = None

def tick(self, vehicle, timestamp):
info = None
linear_speed = self._calculate_speed(vehicle.get_velocity())

if linear_speed < self._speed_threshold and self._time_last_valid_state:
if (timestamp['relative_simulation_time'] - self._time_last_valid_state) > self._below_threshold_max_time:
# The actor has been "blocked" for too long
ev_loc = vehicle.get_location()
info = {
'step': timestamp['step'],
'simulation_time': timestamp['relative_simulation_time'],
'ev_loc': [ev_loc.x, ev_loc.y, ev_loc.z]
}
else:
self._time_last_valid_state = timestamp['relative_simulation_time']
return info

@staticmethod
def _calculate_speed(carla_velocity):
return np.linalg.norm([carla_velocity.x, carla_velocity.y])
117 changes: 117 additions & 0 deletions roach/criteria/collision.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import carla
import weakref
import numpy as np


class Collision():
def __init__(self, vehicle, carla_world, intensity_threshold=0.0,
min_area_of_collision=3, max_area_of_collision=5, max_id_time=5):
blueprint = carla_world.get_blueprint_library().find('sensor.other.collision')
self._collision_sensor = carla_world.spawn_actor(blueprint, carla.Transform(), attach_to=vehicle)
self._collision_sensor.listen(lambda event: self._on_collision(weakref.ref(self), event))
self._collision_info = None

self.registered_collisions = []
self.last_id = None
self.collision_time = None

# If closer than this distance, the collision is ignored
self._min_area_of_collision = min_area_of_collision
# If further than this distance, the area is forgotten
self._max_area_of_collision = max_area_of_collision
# Amount of time the last collision if is remembered
self._max_id_time = max_id_time
# intensity_threshold, LBC uses 400, leaderboard does not use it (set to 0)
self._intensity_threshold = intensity_threshold

def tick(self, vehicle, timestamp):
ev_loc = vehicle.get_location()
new_registered_collisions = []
# Loops through all the previous registered collisions
for collision_location in self.registered_collisions:
distance = ev_loc.distance(collision_location)
# If far away from a previous collision, forget it
if distance <= self._max_area_of_collision:
new_registered_collisions.append(collision_location)

self.registered_collisions = new_registered_collisions

if self.last_id and timestamp['relative_simulation_time'] - self.collision_time > self._max_id_time:
self.last_id = None

info = self._collision_info
self._collision_info = None
if info is not None:
info['step'] -= timestamp['start_frame']
info['simulation_time'] -= timestamp['start_simulation_time']
return info

@staticmethod
def _on_collision(weakself, event):
self = weakself()
if not self:
return
# Ignore the current one if it's' the same id as before
if self.last_id == event.other_actor.id:
return
# Ignore if it's too close to a previous collision (avoid micro collisions)
ev_loc = event.actor.get_transform().location
for collision_location in self.registered_collisions:
if ev_loc.distance(collision_location) <= self._min_area_of_collision:
return
# Ignore if its intensity is smaller than self._intensity_threshold
impulse = event.normal_impulse
intensity = np.linalg.norm([impulse.x, impulse.y, impulse.z])
if intensity < self._intensity_threshold:
return

# collision_type
if ('static' in event.other_actor.type_id or 'traffic' in event.other_actor.type_id) \
and 'sidewalk' not in event.other_actor.type_id:
collision_type = 0 # TrafficEventType.COLLISION_STATIC
elif 'vehicle' in event.other_actor.type_id:
collision_type = 1 # TrafficEventType.COLLISION_VEHICLE
elif 'walker' in event.other_actor.type_id:
collision_type = 2 # TrafficEventType.COLLISION_PEDESTRIAN
else:
collision_type = -1

# write to info, all quantities in in world coordinate
event_loc = event.transform.location
event_rot = event.transform.rotation
oa_loc = event.other_actor.get_transform().location
oa_rot = event.other_actor.get_transform().rotation
oa_vel = event.other_actor.get_velocity()
ev_rot = event.actor.get_transform().rotation
ev_vel = event.actor.get_velocity()

self._collision_info = {
'step': event.frame,
'simulation_time': event.timestamp,
'collision_type': collision_type,
'other_actor_id': event.other_actor.id,
'other_actor_type_id': event.other_actor.type_id,
'intensity': intensity,
'normal_impulse': [impulse.x, impulse.y, impulse.z],
'event_loc': [event_loc.x, event_loc.y, event_loc.z],
'event_rot': [event_rot.roll, event_rot.pitch, event_rot.yaw],
'ev_loc': [ev_loc.x, ev_loc.y, ev_loc.z],
'ev_rot': [ev_rot.roll, ev_rot.pitch, ev_rot.yaw],
'ev_vel': [ev_vel.x, ev_vel.y, ev_vel.z],
'oa_loc': [oa_loc.x, oa_loc.y, oa_loc.z],
'oa_rot': [oa_rot.roll, oa_rot.pitch, oa_rot.yaw],
'oa_vel': [oa_vel.x, oa_vel.y, oa_vel.z]
}

self.collision_time = event.timestamp

self.registered_collisions.append(ev_loc)

# Number 0: static objects -> ignore it
if event.other_actor.id != 0:
self.last_id = event.other_actor.id

def clean(self):
self._collision_sensor.stop()
self._collision_sensor.destroy()
self._collision_sensor = None
26 changes: 26 additions & 0 deletions roach/criteria/encounter_light.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from carla_gym.utils.traffic_light import TrafficLightHandler


class EncounterLight():

def __init__(self, dist_threshold=7.5):
self._last_light_id = None
self._dist_threshold = dist_threshold

def tick(self, vehicle, timestamp):
info = None

light_state, light_loc, light_id = TrafficLightHandler.get_light_state(
vehicle, dist_threshold=self._dist_threshold)

if light_id is not None:
if light_id != self._last_light_id:
self._last_light_id = light_id
info = {
'step': timestamp['step'],
'simulation_time': timestamp['relative_simulation_time'],
'id': light_id,
'tl_loc': light_loc.tolist()
}

return info
Loading

0 comments on commit 7de14c9

Please sign in to comment.