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/simulation_loop.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
49 lines (40 sloc)
2.92 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 initialize_simulation | |
import calculate_nearpoint_farpoint | |
import two_point_steering_model | |
import calculate_visual_angles | |
def simulation(time_array,agent_object,simulation_object,road_object): | |
# instantiate dictionary | |
magical_dictionary = {} | |
for i in range(0,len(time_array)): | |
# for first and second frame (0 & 1) | |
if i <= 1: | |
# Set delta_alpha, alpha, and phi for dictionary | |
delta_alpha = simulation_object.init_delta_alpha | |
alpha = simulation_object.init_alpha | |
phi = simulation_object.init_phi | |
# Calculate position of agent, nearPoint, and farPoint for ith frame | |
agent_x,agent_y = initialize_simulation.initial_calculate_x_y(agent_object,simulation_object,phi) | |
nearPoint_x,nearPoint_y = calculate_nearpoint_farpoint.get_point(agent_x,agent_y,road_object,"nearpoint") | |
farPoint_x,farPoint_y = calculate_nearpoint_farpoint.get_point(agent_x,agent_y,road_object,"farpoint") | |
# Calculate visual angles for ith frame | |
nearPoint_angle = initialize_simulation.init_visual_angle(simulation_object,agent_object,agent_x,agent_y,nearPoint_x,nearPoint_y) | |
farPoint_angle = initialize_simulation.init_visual_angle(simulation_object,agent_object,agent_x,agent_y,farPoint_x,farPoint_y) | |
# for rest of the simulation | |
else: | |
# Calculate delta_alpha, alpha, and phi | |
delta_alpha = two_point_steering_model.control_law(i,magical_dictionary,agent_object,simulation_object) | |
alpha = two_point_steering_model.calculate_alpha(i,magical_dictionary,simulation_object,delta_alpha) | |
phi = two_point_steering_model.calculate_phi(i,magical_dictionary,agent_object,simulation_object,alpha) | |
# Calculate position of agent, nearPoint, and farPoint for ith frame | |
agent_x, agent_y = two_point_steering_model.calculate_x_y(i,magical_dictionary,simulation_object,agent_object,phi) | |
nearPoint_x,nearPoint_y = calculate_nearpoint_farpoint.get_point(agent_x,agent_y,road_object,"nearpoint") | |
farPoint_x,farPoint_y = calculate_nearpoint_farpoint.get_point(agent_x,agent_y,road_object,"farpoint") | |
# Calculate visual angles for ith frame | |
nearPoint_angle = calculate_visual_angles.calculate_visual_angle(i,magical_dictionary,agent_x,agent_y,nearPoint_x, nearPoint_y) | |
farPoint_angle = calculate_visual_angles.calculate_visual_angle(i,magical_dictionary,agent_x,agent_y,farPoint_x, farPoint_y) | |
# Add dictionary for f = i | |
magical_dictionary[i] = {"agent_x_loc":agent_x,"agent_y_loc":agent_y, | |
"delta_alpha":delta_alpha,"alpha":alpha,"phi":phi, | |
"nearPoint_angle":nearPoint_angle,"farPoint_angle":farPoint_angle, | |
"nearPoint_x":nearPoint_x,"nearPoint_y":nearPoint_y,"farPoint_x":farPoint_x,"farPoint_y":farPoint_y} | |
return(magical_dictionary) |