Exemplo n.º 1
0
def run_sim(street_1: DecalRoad, ai_aggression):
    waypoint_goal = BeamNGWaypoint('waypoint_goal', get_node_coords(street_1.nodes[-1]))

    maps.beamng_map.generated().write_items(street_1.to_json() + '\n' + waypoint_goal.to_json())

    beamng = BeamNGpy('localhost', 64256)
    scenario = Scenario('tig', 'tigscenario')

    vehicle = Vehicle('ego_vehicle', model='etk800', licence='TIG', color='Red')

    sim_data_collector = TrainingDataCollectorAndWriter(vehicle, beamng, street_1)

    scenario.add_vehicle(vehicle, pos=get_node_coords(street_1.nodes[0]), rot=get_rotation(street_1))

    scenario.make(beamng)

    beamng.open()
    beamng.set_deterministic()
    beamng.load_scenario(scenario)
    beamng.pause()
    beamng.start_scenario()

    vehicle.ai_set_aggression(ai_aggression)
    vehicle.ai_drive_in_lane(False)
    vehicle.ai_set_speed(25)
    vehicle.ai_set_waypoint(waypoint_goal.name)
    #vehicle.ai_set_mode("manual")

    steps = 5

    def start():
        for idx in range(1000):

            if (idx * 0.05 * steps) > 3.:
                sim_data_collector.collect_and_write_current_data()

                if sim_data_collector.oob_monitor.is_oob(wrt="center"):
                    raise ValueError("OOB detected during training")

                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()
Exemplo n.º 2
0
def run_sim(street_1: DecalRoad):
    waypoints = []
    for node in street_1.nodes:
        waypoint = BeamNGWaypoint("waypoint_" + str(node),
                                  get_node_coords(node))
        waypoints.append(waypoint)

    print(len(waypoints))
    maps.beamng_map.generated().write_items(
        street_1.to_json() + '\n' +
        "\n".join([waypoint.to_json() for waypoint in waypoints]))

    beamng = BeamNGpy('localhost', 64256)
    scenario = Scenario('tig', 'tigscenario')

    vehicle = Vehicle('ego_vehicle',
                      model='etk800',
                      licence='TIG',
                      color='Red')

    sim_data_collector = TrainingDataCollectorAndWriter(
        vehicle, beamng, street_1)

    scenario.add_vehicle(vehicle,
                         pos=get_node_coords(street_1.nodes[0]),
                         rot=get_rotation(street_1))

    scenario.make(beamng)

    beamng.open()
    beamng.set_deterministic()
    beamng.load_scenario(scenario)
    beamng.pause()
    beamng.start_scenario()

    vehicle.ai_drive_in_lane(True)
    vehicle.ai_set_mode("disabled")
    vehicle.ai_set_speed(10 / 4)

    steps = 5

    def start():
        for waypoint in waypoints[10:-1:20]:
            vehicle.ai_set_waypoint(waypoint.name)

            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.position)

                    if dist < 15.0:
                        beamng.resume()
                        break

                # one step is 0.05 seconds (5/100)
                beamng.step(steps)

    try:
        start()
    finally:
        beamng.close()