Ejemplo n.º 1
0
    def start_torcs_process(self):
        if self.torcs_proc is not None:
            os.killpg(os.getpgid(self.torcs_proc.pid), signal.SIGKILL)
            time.sleep(0.5)
            self.torcs_proc = None

        self.test_torcs_server_port()

        if self._config.traffic:
            self.traffic_manager = traffic.MadrasTrafficManager(
                self.torcs_server_port, 1, self._config.traffic)

        TorcsEnv.__init__(self,
                          vision=self._config.vision,
                          throttle=self._config.throttle,
                          gear_change=self._config.gear_change,
                          visualise=self._config.visualise,
                          no_of_visualisations=self._config.no_of_visualisations,
                          torcs_server_port=self.torcs_server_port)

        command = None
        rank = MPI.COMM_WORLD.Get_rank()
        self.torcs_server_config.generate_torcs_server_config()
        self.madras_agent_port = self.torcs_server_port + self.torcs_server_config.num_traffic_cars
        if rank < self._config.no_of_visualisations and self._config.visualise:
            command = 'export TORCS_PORT={} && vglrun torcs -t 10000000 -nolaptime'.format(self.torcs_server_port)
        else:
            command = 'export TORCS_PORT={} && torcs -t 10000000 -r ~/.torcs/config/raceman/quickrace.xml -nolaptime'.format(self.torcs_server_port)
        if self._config.vision is True:
            command += ' -vision'
        if self._config.noisy_observations:
            command += ' -noisy'

        self.torcs_proc = subprocess.Popen([command], shell=True, preexec_fn=os.setsid)
        time.sleep(1)
Ejemplo n.º 2
0
    def __init__(self,
                 vision=False,
                 throttle=True,
                 gear_change=False,
                 port=60934,
                 pid_assist=False,
                 CLIENT_MAX_STEPS=np.inf,
                 visualise=True,
                 no_of_visualisations=1):
        # If `visualise` is set to False torcs simulator will run in headless mode
        """Init Method."""
        self.torcs_proc = None
        self.pid_assist = pid_assist
        if self.pid_assist:
            self.action_dim = 2  # LanePos, Velocity
        else:
            self.action_dim = 3  # Accel, Steer, Brake
        TorcsEnv.__init__(self,
                          vision=False,
                          throttle=True,
                          gear_change=False,
                          visualise=visualise,
                          no_of_visualisations=no_of_visualisations)
        self.state_dim = 29  # No. of sensors input
        self.env_name = 'Madras_Env'
        self.port = port
        self.visualise = visualise
        self.no_of_visualisations = no_of_visualisations
        self.CLIENT_MAX_STEPS = CLIENT_MAX_STEPS
        self.client_type = 0  # Snakeoil client type
        self.initial_reset = True
        self.early_stop = True
        if self.pid_assist:
            self.PID_latency = 10
        else:
            self.PID_latency = 1
        self.accel_PID = PID(np.array([10.5, 0.05, 2.8]))  # accel PID
        self.steer_PID = PID(np.array([5.1, 0.001, 0.000001]))  # steer PID

        self.prev_lane = 0
        self.prev_angle = 0
        self.prev_vel = 0
        self.prev_dist = 0
        self.ob = None
        self.track_len = 7014.6
        self.seed()
        self.start_torcs_process()