def run_sim(street_1: DecalRoad): brewer = BeamNGBrewer(street_1.nodes) waypoint_goal = BeamNGWaypoint('waypoint_goal', get_node_coords(street_1.nodes[-1])) vehicle = brewer.setup_vehicle() camera = brewer.setup_scenario_camera() beamng = brewer.beamng brewer.setup_road_nodes(street_1.nodes) maps.beamng_map.generated().write_items(brewer.decal_road.to_json() + '\n' + waypoint_goal.to_json()) cameras = BeamNGCarCameras() brewer.vehicle_start_pose = brewer.road_points.vehicle_start_pose() #brewer.vehicle_start_pose = BeamNGPose() sim_data_collector = TrainingDataCollectorAndWriter(vehicle, beamng, street_1, cameras) brewer.bring_up() print('bring up ok') script = calculate_script(brewer.road_points.middle) # Trick: we start from the road center vehicle.ai_set_script(script[4:]) #vehicle.ai_drive_in_lane(True) beamng.pause() beamng.step(1) def start(): for idx in range(1000): if (idx * 0.05 * STEPS) > 3.: sim_data_collector.collect_and_write_current_data() dist = distance(sim_data_collector.last_state.pos, waypoint_goal.position) if dist < 15.0: beamng.resume() break # one step is 0.05 seconds (5/100) beamng.step(STEPS) try: start() finally: beamng.close()
def run_sim(nodes): print(nodes) brewer = BeamNGBrewer(road_nodes=nodes) beamng = brewer.beamng waypoint_goal = BeamNGWaypoint('waypoint_goal', get_node_coords(nodes[-1])) maps.install_map_if_needed() maps.beamng_map.generated().write_items(brewer.decal_road.to_json() + '\n' + waypoint_goal.to_json()) vehicle = brewer.setup_vehicle() brewer.vehicle_start_pose = brewer.road_points.vehicle_start_pose() #camera = brewer.setup_scenario_camera() street_1 = brewer.decal_road sim_data_collector = TrainingDataCollectorAndWriter( vehicle, beamng, street_1) brewer.bring_up() steps = 5 def start(): for idx in range(1000): if (idx * 0.05 * steps) > 3.: sim_data_collector.collect_and_write_current_data() dist = points_distance(sim_data_collector.last_state.pos, waypoint_goal.position) if dist < 15.0: beamng.resume() break # one step is 0.05 seconds (5/100) beamng.step(steps) try: start() finally: beamng.close()