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/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.
111 lines (86 sloc)
6.7 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 matplotlib.pyplot as plt | |
import numpy as np | |
from matplotlib import animation | |
import matplotlib as mpl | |
import simulation_loop | |
import input_for_experiment | |
import initialize_simulation | |
import plot_road_and_patches | |
import batch_functions | |
import replicate_Kountouriotis_et_al_2016 | |
import calculate_parallel_curves | |
# Mutable variables ============================================================================================================================== | |
num_of_conditions = 5 | |
mode = "replication" | |
center_x,center_y,init_phi,velocity,number_of_frames,total_simulation_time,agent_size,ax1 = input_for_experiment.mode_selection(mode) | |
time_array = np.arange(0,number_of_frames,1) | |
wayPoint_time_increment = 0.5 | |
look_ahead_distance = 1.5 # determines farPoint distance in terms of time | |
phi_gain =1 | |
derivative_farPoint_gain = 30 | |
derivative_nearPoint_gain = 13.5 | |
proportional_nearPoint_gain = 36 | |
farpoint_distance = velocity*look_ahead_distance | |
#look_ahead_distance_array = batch_functions.assign_arrays_to_manipulated_vars("consistent",look_ahead_distance,num_of_conditions) | |
look_ahead_distance_array = batch_functions.assign_arrays_to_manipulated_vars("changes",look_ahead_distance,num_of_conditions,min=0.5,max=2.5) | |
farpoint_distance_array = batch_functions.get_farpoint_distance_array(velocity,look_ahead_distance_array) | |
phi_gain_array = batch_functions.assign_arrays_to_manipulated_vars("consistent",phi_gain,num_of_conditions) | |
derivative_farPoint_gain_array = batch_functions.assign_arrays_to_manipulated_vars("consistent",derivative_farPoint_gain,num_of_conditions) | |
#derivative_farPoint_gain_array = batch_functions.assign_arrays_to_manipulated_vars("changes",derivative_farPoint_gain,num_of_conditions,min=derivative_farPoint_gain,max=50) | |
derivative_nearPoint_gain_array = batch_functions.assign_arrays_to_manipulated_vars("consistent",derivative_nearPoint_gain,num_of_conditions) | |
proportional_nearPoint_gain_array = batch_functions.assign_arrays_to_manipulated_vars("consistent",proportional_nearPoint_gain,num_of_conditions) | |
# Seperate manipulated variables vs mode variables | |
manipulatable_vars = [phi_gain_array,derivative_nearPoint_gain_array,derivative_farPoint_gain_array,proportional_nearPoint_gain_array,farpoint_distance_array] | |
mode_vars = [velocity,number_of_frames,init_phi,center_x,center_y] | |
# # simulation1, agent1, road1 = initialize_simulation.init_simulation_objects(input_for_experiment.start_position_x,input_for_experiment.start_position_y,input_for_experiment.agent_size,input_for_experiment.color,velocity, | |
# # phi_gain,derivative_nearPoint_gain,derivative_farPoint_gain,proportional_nearPoint_gain, | |
# # input_for_experiment.delta_time,number_of_frames,input_for_experiment.init_delta_alpha,input_for_experiment.init_alpha,init_phi,input_for_experiment.simulation_resolution, | |
# # center_x,center_y,input_for_experiment.nearpoint_distance,farpoint_distance,input_for_experiment.delta_alpha_set, input_for_experiment.waypoint_set) | |
# #magical_dictoinary = simulation_loop.simulation(time_array, agent1, simulation1, road1) | |
dictionary_array = input_for_experiment.batch_of_experimental_conditions(num_of_conditions,time_array,manipulatable_vars,mode_vars,simulation_loop.simulation) | |
# Plot figure from dictionary information ========================================================================================================= | |
# Standard Road vs Kountouriotus replication | |
# Window to observe agent on to entire road | |
#ax1 = plt.axes(xlim=(0,100), ylim=(-50,50)) # Standard road | |
ax1 = plt.axes(xlim=(-30,70), ylim=(-70,30)) # Kountouriotus replication | |
# initialize road | |
#center_line,center_X,center_Y,left,right = plot_road_and_patches.instantiate_standard_road(ax1) | |
center_X,center_Y,first_road_segment,middle_road_segment,last_road_segment,full_road = plot_road_and_patches.instantiate_Kountouriotis2016_rep_road(ax1) | |
# Define figure, patches (Agent, nearPoint, farPoint), and vectors (headingVector,nearPointAngle_Vector,farPointAngle_Vector) | |
fig = plt.figure(1,figsize=(7,6), constrained_layout=True) | |
agent_x_array_trial1,agent_y_array_trial1 = batch_functions.get_agent_trace(dictionary_array[0],time_array) | |
agent_x_array_trial2,agent_y_array_trial2 = batch_functions.get_agent_trace(dictionary_array[1],time_array) | |
agent_x_array_trial3,agent_y_array_trial3 = batch_functions.get_agent_trace(dictionary_array[2],time_array) | |
agent_x_array_trial4,agent_y_array_trial4 = batch_functions.get_agent_trace(dictionary_array[3],time_array) | |
agent_x_array_trial5,agent_y_array_trial5 = batch_functions.get_agent_trace(dictionary_array[4],time_array) | |
#agent_x_array_trial6,agent_y_array_trial6 = batch_functions.get_agent_trace(dictionary_array[5],time_array) | |
trial1_color = "lightsteelblue" | |
trial2_color = "cornflowerblue" | |
trial3_color = "royalblue" | |
trial4_color = "blue" | |
trial5_color = "black" | |
plt.plot(agent_x_array_trial1,agent_y_array_trial1,c = trial1_color) | |
plt.plot(agent_x_array_trial2,agent_y_array_trial2,c= trial2_color) | |
plt.plot(agent_x_array_trial3,agent_y_array_trial3,c = trial3_color) | |
plt.plot(agent_x_array_trial4,agent_y_array_trial4,c= trial4_color) | |
plt.plot(agent_x_array_trial5,agent_y_array_trial3,c = trial5_color) | |
# Plot RMSE over Time across Three Conditions ========================================================================================================= | |
trial_time_in_seconds = 6 | |
time_ploted = 3 # similar to Kountouriotis | |
fig2 = plt.figure(2,figsize=(4.5,7), constrained_layout=True) | |
ax2 = plt.axes(xlim=(-1,1), ylim=(0,time_ploted)) | |
# Function in Batch mode | |
error_over_time_t1 = batch_functions.get_error_across_trials(agent_x_array_trial1,agent_y_array_trial1) | |
error_over_time_t2 = batch_functions.get_error_across_trials(agent_x_array_trial2,agent_y_array_trial2) | |
error_over_time_t3 = batch_functions.get_error_across_trials(agent_x_array_trial3,agent_y_array_trial3) | |
error_over_time_t4 = batch_functions.get_error_across_trials(agent_x_array_trial4,agent_y_array_trial4) | |
error_over_time_t5 = batch_functions.get_error_across_trials(agent_x_array_trial5,agent_y_array_trial5) | |
time_array = np.linspace(0,trial_time_in_seconds,len(error_over_time_t1)) | |
trajectory_1 = ax2.plot(error_over_time_t1,time_array,c=trial1_color) | |
trajectory_2 = ax2.plot(error_over_time_t2,time_array,c=trial2_color) | |
trajectory_3 = ax2.plot(error_over_time_t3,time_array,c=trial3_color) | |
trajectory_4 = ax2.plot(error_over_time_t4,time_array,c=trial4_color) | |
trajectory_5 = ax2.plot(error_over_time_t5,time_array,c=trial5_color) | |
#trajectory = ax2.plot(error_over_time_test,time_array,c='green') | |
center_line = plt.axvline(x = 0, color = 'black', linestyle = '--') | |
plt.show() |