Check emergency braking in available actions

This commit is contained in:
ebuehrle
2021-10-28 17:54:58 +02:00
parent f9e058a7d9
commit 8d7409c914
2 changed files with 21 additions and 11 deletions

View File

@@ -2,16 +2,14 @@ import torch
import numpy as np
from intersim.collisions import state_to_polygon
def feasible(env, plan, ch, method='exact'):
"""Check if input profile is feasible given current `env` state. Action `ch=0` is safe fallback."""
def feasible(env, plan, method='exact'):
"""Check if input profile is feasible given current `env` state."""
# zero pad plan - Take (B, T) or (T,) np plan and convert it to (B, T, nv, 1) torch.Tensor
plan = torch.tensor(plan)
plan = plan.reshape(-1, plan.shape[-1])
full_plan = torch.zeros(*plan.shape, env._env._nv, 1)
full_plan[:, :, env._agent, 0] = plan
ch = torch.tensor(ch)
# check_future_collisions_fast takes in B-list and outputs (B,) bool tensor
if method=='circle':
valid = check_future_collisions_fast(env, full_plan)
@@ -22,7 +20,7 @@ def feasible(env, plan, ch, method='exact'):
else:
raise NotImplementedError('Invalid collision-checking method')
return valid | (ch == 0)
return valid
def check_future_collisions_ncircles(env, actions, n_circles:int=2):
"""Checks whether `env._agent` would collide with other agents assuming `actions` as input.