Esempio n. 1
0
 def _store_verification_cycle(sid: SimulationID, started: datetime,
                               finished: datetime) -> Void:
     vehicles = _get_data(sid).scenario.vehicles.keys()
     void = Void()
     if _is_simulation_running(sid):
         for vehicle in vehicles:
             vid = VehicleID()
             vid.vid = vehicle.vid
             request = DataRequest()
             request.request_ids.extend(vehicle.requests)
             data = _request_data(sid, vid, request)
             args = {
                 "sid": sid.sid,
                 "vid": vid.vid,
                 "tick": _get_data(sid).scenario.bng.current_tick,
                 "data": data.SerializeToString(),
                 "started": _time_to_string(started),
                 "finished": _time_to_string(finished)
             }
             _DB_CONNECTION.run_query(
                 """
             INSERT INTO verificationcycles VALUES
             (:sid, :vid, :tick, :data, :started, :finished);
             """, args)
         void.message = "Stored data of the current runtime verification cycle of simulation " + sid.sid + "."
     else:
         void.message = "Skipped storing the data of the current runtime verification cycle since simulation " \
                        + sid.sid + " does not run anymore."
     return void
Esempio n. 2
0
 def _request_control_avs(self, vids: List[str]) -> None:
     from drivebuildclient.aiExchangeMessages_pb2 import VehicleID
     import dill as pickle
     for v in vids:
         # print(self.sid.sid + ": Request control for " + v)
         mode = self.get_current_movement_mode(v)
         if not mode:  # If there is no movement mode file assume participant is still in mode of initial state
             test_case = pickle.loads(self.pickled_test_case)
             mode = [
                 p.initial_state.mode
                 for p in test_case.scenario.participants if p.id == v
             ][0]
         if mode in [
                 MovementMode.AUTONOMOUS, MovementMode.TRAINING,
                 MovementMode._BEAMNG
         ]:
             vid = VehicleID()
             vid.vid = v
             message = self.send_message_to_sim_node(
                 b"requestAiFor",
                 [self.serialized_sid,
                  vid.SerializeToString()])
             _logger.debug(message)
         elif mode == MovementMode.MANUAL:
             pass  # No AI to request
         else:
             _logger.warning(self.sid.sid + ":" + v +
                             ": Can not handle movement mode " +
                             (mode.name if mode else "None"))
Esempio n. 3
0
def _start_moose_test():
    from drivebuildclient.aiExchangeMessages_pb2 import VehicleID
    from drivebuildclient.AIExchangeService import AIExchangeService
    from dummy_ai import DummyAI
    from os.path import dirname, join
    from pathlib import Path
    service = AIExchangeService("localhost", 8383)
    upload_result = service.run_tests("test", "test", Path(join(dirname(__file__), "scenario")))
    if upload_result and upload_result.submissions:
        for test_name, sid in upload_result.submissions.items():
            vid = VehicleID()
            vid.vid = "ego"
            DummyAI(service).start(sid, vid)
Esempio n. 4
0
def main() -> None:
    from drivebuildclient.AIExchangeService import AIExchangeService
    from drivebuildclient.aiExchangeMessages_pb2 import VehicleID
    from common.dummy_ai import DummyAI
    from pathlib import Path
    from os.path import dirname, join
    service = AIExchangeService("localhost", 5000)
    upload_result = service.run_tests(
        "test", "test", Path(join(dirname(__file__), "providedFiles")))
    if upload_result and upload_result.submissions:
        for test_name, sid in upload_result.submissions.items():
            vid = VehicleID()
            vid.vid = "ego"
            DummyAI(service).start(sid, vid)
Esempio n. 5
0
def _handle_vehicle(sid: SimulationID, vid: str, requests: List[str]) -> None:
    vid_obj = VehicleID()
    vid_obj.vid = vid

    while True:
        print(sid.sid + ": Test status: " + service.get_status(sid))
        print(vid + ": Wait")
        sim_state = service.wait_for_simulator_request(sid, vid_obj)  # wait()
        if sim_state is SimStateResponse.SimState.RUNNING:
            print(vid + ": Request data")
            request = DataRequest()
            request.request_ids.extend(requests)
            data = service.request_data(sid, vid_obj, request)  # request()
            # print(data)
            print(vid + ": Wait for control")
            control = Control()
            while not is_pressed("space"):  # Wait for the user to trigger manual drive
                pass
            print(vid + ": Control")
            if is_pressed("s"):
                control.simCommand.command = Control.SimCommand.Command.SUCCEED
            elif is_pressed("f"):
                control.simCommand.command = Control.SimCommand.Command.FAIL
            elif is_pressed("c"):
                control.simCommand.command = Control.SimCommand.Command.CANCEL
            else:
                accelerate = 0
                steer = 0
                brake = 0
                if is_pressed("up"):
                    accelerate = 1
                if is_pressed("down"):
                    brake = 1
                if is_pressed("right"):
                    steer = steer + 1
                if is_pressed("left"):
                    steer = steer - 1
                control.avCommand.accelerate = accelerate
                control.avCommand.steer = steer
                control.avCommand.brake = brake
            service.control(sid, vid_obj, control)  # control()
        else:
            print(sid.sid + ": The simulation is not running anymore (State: "
                  + SimStateResponse.SimState.Name(sim_state) + ").")
            print(sid.sid + ": Final result: " + service.get_result(sid))
            break
Esempio n. 6
0
def _main() -> None:
    from pathlib import Path
    _configure_asfault()
    test = _generate_asfault_test()
    lanes = _get_lanes(test)

    dbe_content = _generate_dbe(lanes)
    temp_dbe_file = NamedTemporaryFile(mode="w",
                                       delete=False,
                                       suffix=".dbe.xml")
    temp_dbe_file.write(dbe_content)
    temp_dbe_file.close()

    # FIXME Choose lane based on some ranking?
    dbc_content = _generate_dbc(lanes[0], basename(temp_dbe_file.name))
    temp_dbc_file = NamedTemporaryFile(mode="w",
                                       delete=False,
                                       suffix=".dbc.xml")
    temp_dbc_file.write(dbc_content)
    temp_dbc_file.close()

    service = AIExchangeService("defender.fim.uni-passau.de", 8383)
    submission_result = service.run_tests("test", "test",
                                          Path(temp_dbe_file.name),
                                          Path(temp_dbc_file.name))
    if submission_result and submission_result.submissions:
        for test_name, sid in submission_result.submissions.items():
            vid = VehicleID()
            vid.vid = "ego"
            while True:
                sim_state = service.wait_for_simulator_request(sid, vid)
                if sim_state != SimStateResponse.SimState.RUNNING:
                    break
            print("Result of \"" + test_name + "\": " +
                  service.get_result(sid))
            break  # NOTE Assume only one test was uploaded
    else:
        _LOGGER.warning("DriveBuild denied running the given test.")

    remove(temp_dbe_file.name)
    remove(temp_dbc_file.name)
def main():
    print("parameters: ")
    for i in range(1, len(sys.argv)):
        print(sys.argv[i])
    data_request_path = sys.argv[1]
    ai_path = sys.argv[2]
    working_directory = sys.argv[3]
    """
    data_request_path = "C:\\sbse4tac-ws-2019-self-driving-car-e2edriving\\ai\\data_requests.py"
    ai_path = "C:\\sbse4tac-ws-2019-self-driving-car-e2edriving\\run_db.py"
    working_directory = "C:\\sbse4tac-ws-2019-self-driving-car-e2edriving"
    """

    service = AIExchangeService("localhost", 8383)

    vid = VehicleID()
    vid.vid = "ego"

    tg = TestGenerator()
    tg.set_difficulty("easy")
    while True:
        for paths in tg.getTest():
            criteria = paths[1]
            environment = paths[0]

            # edit the xml
            spec = importlib.util.spec_from_file_location(
                "AI", data_request_path)
            foo = importlib.util.module_from_spec(spec)
            # Actually run the import
            spec.loader.exec_module(foo)

            # get ai element
            double_backslash_dbc_path = str(criteria).replace(
                "\\", "\\" + "\\")
            tree = parse(double_backslash_dbc_path)
            root = tree.getroot()
            for i in range(0, len(root.getchildren())):
                if root.getchildren(
                )[i].tag == "{http://drivebuild.com}participants":
                    participant_block = root.getchildren()[i].getchildren()[0]
                    for j in range(0, len(participant_block)):
                        part_child = participant_block.getchildren()[j]
                        if part_child.tag == "{http://drivebuild.com}ai":
                            pass
                            part_child.clear()
                            foo.add_data_requests(part_child, "ego")
                            pass
            # write the changed xml
            # TODO pretty print
            f = open(double_backslash_dbc_path, "w")
            f.write(tostring(root, pretty_print=True).decode("utf-8"))
            f.close()

            # ai: _Element = ai_tag.makeelement(_tag="speed")

            submission_result = service.run_tests("test", "test", environment,
                                                  criteria)
            # Interact with a simulation
            if submission_result and submission_result.submissions:
                for test_name, sid in submission_result.submissions.items():
                    ai_process = subprocess.Popen([env_path, ai_path, sid.sid],
                                                  cwd=working_directory)

                    sim_state = service.wait_for_simulator_request(sid, vid)
                    while sim_state is SimStateResponse.SimState.RUNNING:
                        sleep(5)
                        sim_state = service.wait_for_simulator_request(
                            sid, vid)

                    # TODO Use a trap or try except to ensure we kill the process
                    kill_process(ai_process)
                    sleep(5)
                    tg.onTestFinished(sid, vid)