conf_mass_add=kona_param_est[0, 3], conf_jw_wheel=kona_param_est[0, 2], conf_jw_trns_out=kona_param_est[0, 0], conf_jw_diff_in=0, conf_jw_diff_out=0, conf_jw_trns_in=0) kona_drivetrain.conf_eff_eq_pos = kona_param_est[0, 1] kona_drivetrain.conf_eff_eq_neg = (2 - 1 / kona_drivetrain.conf_eff_eq_pos) # Vehicle set kona_vehicle = Mod_Veh(kona_power, kona_drivetrain) kona_vehicle.Veh_config(conf_drag_air_coef=kona_param_est[0, 4], conf_drag_ca=kona_param_est[0, 5], conf_drag_cc=kona_param_est[0, 6]) # Driver model drv_kyunghan = Mod_Driver() drv_kyunghan.I_gain_lat = 0.001 drv_kyunghan.P_gain_lat = 0.002 drv_kyunghan.I_gain_yaw = 0.3 drv_kyunghan.P_gain_yaw = 0.5 # Behavior model beh_driving = Mod_Behavior(drv_kyunghan) #%% 2. Simulation config # 2. brake torque data_driver = get_config.load_mat('Data_Kyunghan.mat') data_result = get_config.load_mat('SimResult_Kyunghan.mat') u_trq_mot_set = data_driver['Trq_Mot'] u_trq_brk_set = data_driver['Trq_BrkMec'] sim_time_range = data_driver['Veh_Time'] result_veh_vel = data_driver['Veh_Vel']
# Set logging data veh_data = type_DataLog(['Veh_Vel','Pos_X','Pos_Y','Acc_Set','Brk_Set','t_brk']) motor_data = type_DataLog(['t_mot','t_mot_reg','t_mot_des','w_mot']) power_data = type_DataLog(['p_mot','p_loss','p_elec','soc','v_mot','i_mot']) shaft_data = type_DataLog(['w_shaft','w_wheel','w_veh','w_dot_mot','w_dot_veh','w_dot_shaft']) # Powertrain import and configuration kona_power = Mod_Power() # Bodymodel import and configuration kona_body = Mod_Body() # Vehicle set kona_vehicle = Mod_Veh(kona_power, kona_body) drv_kyunghan = Mod_Driver() # Behavior model beh_speed = Mod_Behavior(drv_kyunghan) veh_vel = kona_vehicle.vel_veh kona_vehicle.swtRegCtl = test_case for sim_step in range(len(sim_time_range)): # Arrange vehicle input veh_vel_set = u_veh_vel_set[sim_step] u_acc_in, u_brk_in = beh_speed.Lon_control(veh_vel_set, veh_vel) # Vehicle model sim [veh_vel, the_wheel] = kona_vehicle.Veh_driven(u_acc = u_acc_in, u_brake = u_brk_in) [pos_x, pos_y, pos_s, pos_n, psi_veh] = kona_vehicle.Veh_position_update(veh_vel, the_wheel) # Vehicle state
# print('============================= validation =================================') # else: # agent_dqn.conf_egreedy = e_greedy_config - egreedy_dis_fac/50 # 3. Import model - set the initial value # Powertrain import and configuration kona_power = Mod_PowerTrain() # ~~~~~ # Bodymodel import and configuration kona_body = Mod_Body() kona_body.swtRegCtl = 2 # ~~~~ # Vehicle set kona_vehicle = Mod_Veh(kona_power, kona_body) # ~~~~ # Driver model import drv_kyunghan = Mod_Driver() drv_kyunghan.I_gain_lon = 10 drv_kyunghan.P_gain_lon = 5 # ~~~~ # Behavior set beh_driving = Mod_Behavior(drv_kyunghan) idm_brake = IDM_brake(mod_param) # Set the drv config # cruise speed beh_driving.conf_cruise_speed_set = random.uniform(18, 22) # fore casting distance drv_set_coast_sl = drv_conf['coast_sl'] * random.uniform(0.8, 1.2) drv_set_coast_off = drv_conf['coast_off'] * random.uniform(0.8, 1.2) drv_set_coast_dis = beh_driving.conf_cruise_speed_set * drv_set_coast_sl + drv_set_coast_off beh_driving.conf_cruise_speed_set = 20