Ejemplo n.º 1
0
class TestDrive(object):
    def __init__(self):
        self.map_data = None
        self.simulator = None
        self.restart_event = None
        self.gui = None
        self.ego_vehicle = None
        self.client = None

    def start_ego(self):
        self.ego_vehicle.start()

    def get_simulator(self):
        return self.simulator

    def step(self, control):
        self.ego_vehicle.step(self.client, {
            'forward': control[0],
            'right': control[1]
        })
        return control

    def run_setup(self):
        from monodrive import SimulatorConfiguration, VehicleConfiguration, Simulator
        from monodrive.ui import GUI
        from monodrive.networking.client import Client

        # Simulator configuration defines network addresses for connecting to the simulator and material properties
        simulator_config = SimulatorConfiguration('simulator.json')
        self.client = Client((simulator_config.configuration["server_ip"],
                              simulator_config.configuration["server_port"]))

        if not self.client.isconnected():
            self.client.connect()
        # Vehicle configuration defines ego vehicle configuration and the individual sensors configurations
        vehicle_config = VehicleConfiguration('demo.json')

        self.simulator = Simulator(self.client, simulator_config)
        self.simulator.send_configuration()
        self.map_data = self.simulator.request_map()

        from monodrive import VehicleConfiguration
        from monodrive.vehicles import LV_Vehicle
        # Setup Ego Vehicle
        vehicle_config = VehicleConfiguration('demo.json')
        self.ego_vehicle = LV_Vehicle(simulator_config, vehicle_config,
                                      self.restart_event, self.map_data)

        # Send Radar Waveform
        self.ego_vehicle.update_fmcw_in_config()

        #helper = InterruptHelper()

        self.simulator.restart_event.clear()
        self.simulator.send_vehicle_configuration(vehicle_config)
        time.sleep(1)
        return True

    def start_sensor_streams(self):
        if not self.client.isconnected():
            self.client.connect()
        self.ego_vehicle.start_sensor_streaming(self.client)

    def stop_sensor_streams(self):
        if not self.client.isconnected():
            self.client.connect()
        self.ego_vehicle.stop_sensor_streaming(self.client)

    def close_connection(self):
        if self.client.isconnected():
            self.client.disconnect()
            self.client.stop()

    def start_sensor_listening(self):
        self.ego_vehicle.start_sensor_listening()

    def start_gui(self):
        #self.gui = GUI(self.simulator)
        pass

    def stop_all(self):
        self.simulator.stop()
Ejemplo n.º 2
0
    # Setup Ego Vehicle
    if ManualDriveMode == True:
        ego_vehicle = TeleportVehicle(simulator_config, vehicle_config,
                                      map_data)
    else:
        ego_vehicle = SimpleVehicle(simulator_config, vehicle_config, map_data)

    # prctl.set_proctitle("monoDrive")
    #
    gui = None

    while episodes > 0:
        helper = InterruptHelper()

        simulator.restart_event.clear()
        simulator.send_vehicle_configuration(vehicle_config)
        logging.getLogger("simulator").info('Starting vehicle')
        ego_vehicle.update_fmcw_in_config()
        ego_vehicle.start_sensor_streaming(client)
        ego_vehicle.start_sensor_listening()

        gui = GUI(ego_vehicle, simulator)

        ego_vehicle.init_vehicle_loop(client)

        # Waits for the restart event to be set in the control process
        # time.sleep(100)
        helper.wait(simulator.restart_event)
        simulator.restart_event.wait()

        gui.stop()