コード例 #1
0
    def reset(self, initial_distance, initial_speed):
        if self.gui and self.display:
            self.display.stop()

        # Clean all vehicles before reset the environment
        for i, _ in enumerate(self.actor):
            if self.actor[i] is not None:
                self.actor[i].destroy()
                self.actor[i] = None
        self.actor = []

        self.spawn_vehicles()
        self.dist_calc = DistanceCalculation(self.ego_vehicle, self.leading_vehicle, self.perception)
        self.pid_controller = PID(P=3.0, I=0.0003, D=0.0)

        if self.gui:
            self.display = pygameViewer()
        
        if self.collect["option"] != 0:
            self.collect_data = collectData(os.path.join(self.collect["path"], "episode_" + str(self.episode)), self.perception)
        
        self.step_count = 0
        self.weather = DynamicPrecipitation(initial_precipitation=round(np.random.uniform(0.0,20.0), 2))
        self.world.set_weather(self.weather.get_weather_parameters())
        
        S0 = self.reset_episode(initial_distance, initial_speed)
        self.episode_count += 1
        return S0
コード例 #2
0
    def reset(self, initial_distance, initial_speed, patch_location,
              friction_value, current_actor):
        #def reset(self, initial_distance, initial_speed):
        self.kickspd = initial_speed
        if self.gui and self.display:
            self.display.stop()

        # Clean all vehicles before reset the environment
        for i, _ in enumerate(self.actor):
            if self.actor[i] is not None:
                self.actor[i].destroy()
                self.actor[i] = None
        self.actor = []

        self.spawn_vehicles(initial_speed)
        self.spawn_friction(patch_location, friction_value)
        self.dist_calc = DistanceCalculation(self.ego_vehicle,
                                             self.leading_vehicle,
                                             self.perception)
        self.rewards = reward_calc(a=1.0, d=1.0, base=1.9)
        self.pid_controller = PID(P=1, I=0.0003, D=0.0)

        if self.gui:
            self.display = pygameViewer()

        if self.collect["option"] != 0 and self.flag != current_actor:
            self.episode = 0
            self.flag = current_actor
            self.collect_data = collectData(self.collect["path"],
                                            self.perception, current_actor)

        self.step_count = 0
        self.weather = DynamicPrecipitation(
            initial_precipitation=round(np.random.uniform(0.0, 20.0), 2))
        self.world.set_weather(self.weather.get_weather_parameters())

        S0 = self.reset_episode(initial_distance, initial_speed)
        return S0