Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
driving-simulation/input_for_experiment.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
82 lines (66 sloc)
4.95 KB
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
import replicate_Kountouriotis_et_al_2016 | |
import calculate_parallel_curves | |
import numpy as np | |
import initialize_simulation | |
import wayPoint_functions | |
import matplotlib.pyplot as plt | |
def mode_selection(mode): | |
if mode == "standard": | |
center_x,center_y = calculate_parallel_curves.x, calculate_parallel_curves.final_sine | |
init_phi = np.radians(45) # Standard | |
velocity = 16.9 # Standard | |
number_of_frames = 130 # Standard | |
total_simulation_time = 6 # in seconds | |
agent_size = 2 | |
ax1 = plt.axes(xlim=(0,100), ylim=(-50,50)) | |
elif mode == "replication": | |
center_x,center_y = replicate_Kountouriotis_et_al_2016.center_x_array, replicate_Kountouriotis_et_al_2016.center_y_array | |
init_phi = np.radians(90) | |
velocity = 13.8 | |
number_of_frames = 120 # Standard | |
total_simulation_time = 6 # in seconds | |
agent_size = 1 | |
ax1 = plt.axes(xlim=(-30,70), ylim=(-70,30)) | |
return(center_x,center_y,init_phi,velocity,number_of_frames,total_simulation_time,agent_size,ax1) | |
# Mutable variables ======================================================================================================================================= | |
mode = "replication" # "replication" or "standard" | |
wayPoint_mode_choice = "yes" # "yes" or "no" | |
wayPoint_time_increment = 0.9 | |
# wayPoint time increment options: 0.06 to 0.9 | |
look_ahead_distance = 1.5 | |
# distance options: 1, 1.5 | |
phi_gain,derivative_farPoint_gain,derivative_nearPoint_gain,proportional_nearPoint_gain = 1,30,13.5,36 # Salvucci & Gray's gain values for the steering model | |
center_x,center_y,init_phi,velocity,number_of_frames,total_simulation_time,agent_size,ax1 = mode_selection(mode) | |
# Immutable variables ======================================================================================================================================= | |
# Agent, nearPoint and farPoint initial positions | |
color ='red' | |
start_position = 0 | |
start_position_x,start_position_y = center_x[start_position],center_y[start_position] # start at the front center of the road | |
# Simulation parameters/variables | |
frames_per_second = number_of_frames/total_simulation_time | |
simulation_resolution = 1/frames_per_second | |
farpoint_distance = velocity*look_ahead_distance | |
waypoint_set,delta_alpha_set= wayPoint_functions.wayPoint_mode(wayPoint_mode_choice,simulation_resolution,number_of_frames,wayPoint_time_increment,1) # ignore the 1 | |
# Values specified in literature | |
nearpoint_distance = 6.2 # Standard Salvucci & Gray value | |
delta_time = 0.05 # Based on literature (p 1237 of Salvucci & Gray,2004) | |
init_delta_alpha,init_alpha = 0,0 | |
# ======================================================================================================================================= | |
simulation1, agent1, road1 = initialize_simulation.init_simulation_objects(start_position_x,start_position_y,agent_size,color,velocity, | |
phi_gain,derivative_nearPoint_gain,derivative_farPoint_gain,proportional_nearPoint_gain, | |
delta_time,number_of_frames,init_delta_alpha,init_alpha,init_phi,simulation_resolution, | |
center_x,center_y,nearpoint_distance,farpoint_distance,delta_alpha_set, waypoint_set) | |
def batch_of_experimental_conditions(number_of_conditions, time_array, manipulatable_vars,mode_vars,simulation_loop): | |
velocity,number_of_frames,init_phi,center_x,center_y = mode_vars[0], mode_vars[1],mode_vars[2], mode_vars[3], mode_vars[4] | |
phi_gain,derivative_nearPoint_gain,derivative_farPoint_gain,proportional_nearPoint_gain,farpoint_distance = manipulatable_vars[0],manipulatable_vars[1],manipulatable_vars[2],manipulatable_vars[3],manipulatable_vars[4] | |
dictionary_array = [] | |
for i in range(0,number_of_conditions): | |
current_phi_gain, current_derivative_np_gain, current_derivative_fp_gain,current_proportional_np_gain,current_fp_distance = phi_gain[i],derivative_nearPoint_gain[i],derivative_farPoint_gain[i],proportional_nearPoint_gain[i],farpoint_distance[i] | |
# generate simulation objects for one single trial | |
simulation1, agent1, road1 = initialize_simulation.init_simulation_objects(start_position_x,start_position_y,agent_size,color, | |
velocity,current_phi_gain,current_derivative_np_gain,current_derivative_fp_gain,current_proportional_np_gain, | |
delta_time,number_of_frames,init_delta_alpha,init_alpha,init_phi,simulation_resolution, | |
center_x,center_y,nearpoint_distance,current_fp_distance,delta_alpha_set, waypoint_set) | |
magical_dictionary = simulation_loop(time_array, agent1, simulation1, road1) | |
dictionary_array.append(magical_dictionary) | |
return(dictionary_array) | |