-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from jerryz123/pedestrians
Added pedestrians
- Loading branch information
Showing
11 changed files
with
144 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
gym_urbandriving/agents/supervisor/pedestrian_supervisor.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
class PedestrianAgent(object): | ||
""" | ||
Supervisor Agent for controlling pedestrians | ||
Attributes | ||
---------- | ||
agent_num : int | ||
Index of this agent in the world | ||
""" | ||
def __init__(self, agent_num=0): | ||
self.agent_num = agent_num | ||
def eval_policy(self, state): | ||
""" | ||
Returns action based on state of world | ||
Parameters | ||
---------- | ||
state : PositionState | ||
State of the world | ||
Returns | ||
------- | ||
Turning angle, acceleration pair | ||
""" | ||
if (state.collides_any(self.agent_num, "pedestrians")): | ||
ped = state.dynamic_objects['pedestrians'][str(self.agent_num)] | ||
vel = -ped.vel | ||
return 0, vel | ||
return 0, 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import json | ||
import gym | ||
import gym_urbandriving as uds | ||
from gym_urbandriving import * | ||
from gym_urbandriving.agents import * | ||
from gym_urbandriving.assets import * | ||
from gym_urbandriving.planning import Trajectory | ||
import numpy as np | ||
import IPython | ||
|
||
with open('configs/default_config.json') as json_data_file: | ||
data = json.load(json_data_file) | ||
|
||
|
||
data['agents']['action_space'] = "velocity" | ||
data['recorded_data']['state_space'] = 'raw' | ||
data['use_pedestrians'] = True | ||
data['number_of_pedestrians'] = 4 | ||
sup = VelocitySupervisor(agent_num = 0) | ||
|
||
|
||
env = uds.UrbanDrivingEnv(data) | ||
state = env.current_state | ||
|
||
for i in range(3): | ||
action = sup.eval_policy(state) | ||
obs,reward,done,info_dict = env.step([action]) | ||
state = obs[0] | ||
|
||
|
||
|
||
sup = SteeringSupervisor(agent_num = 0) | ||
data['agents']['action_space'] = "steering" | ||
env = uds.UrbanDrivingEnv(data) | ||
state = env.current_state | ||
|
||
for i in range(3): | ||
action = sup.eval_policy(state) | ||
obs,reward,done,info_dict = env.step([action]) | ||
state = obs[0] | ||
|