class JsbsimGymEnvironmentWrapper(gym.Env):
    """Custom Environment that follows gym interface"""
    metadata = {'render.modes': ['human']}

    def __init__(self,
                 configuration_file: str = config.DEFAULT_CONFIGURATION_FILE):
        super(JsbsimGymEnvironmentWrapper, self).__init__()
        self.configuration = toml.load(os.path.expanduser(configuration_file))
        self.sim = Simulation(configuration_file=configuration_file)
        self._dimensions = 1
        self.action_space = spaces.Box(low=-0,
                                       high=1,
                                       shape=(self._dimensions, ),
                                       dtype=np.float32)
        self.observation_space = spaces.Box(
            low=np.inf,
            high=np.inf,
            shape=self._getObs().
            shape,  # Passt sich damit automatisch an die Beobachtung an
            dtype=np.float32)
        self.sim_steps = self.configuration['simulation'][
            'agent_interaction_freq']

    def reset(self):
        self.sim.reset_with_initial_condition()
        observation = self._getObs()
        reward = self._calcRewards(observation)
        return observation, reward, self._calcDones(), {}

    def step(
        self, actions: List[np.ndarray]
    ) -> Tuple[np.ndarray, np.ndarray, np.ndarray, Dict]:
        self.sim.set_properties('fcs/throttle-cmd-norm', actions[0])
        for _ in range(self.sim_steps):
            self.sim.run()
        observation = self._getObs()
        reward = self._calcRewards(observation)
        return observation, reward, self._calcDones(), {}

    def _getObs(self) -> np.ndarray:
        state = self.sim.get_state()
        return np.array(list(state.values()))

    def _calcRewards(self, observation) -> np.ndarray:
        rewAgent0 = 0
        return np.array([rewAgent0], dtype=np.float32)

    def _calcDones(self) -> np.ndarray:
        dones = np.zeros(1)
        return dones

    def render(self, mode='human'):
        pass

    def close(self):
        pass

    def seed(self, seed=None) -> None:
        pass
Пример #2
0
            ("Wert", "$y")]

        p = figure(title="simple line example", x_axis_label='Datapoints', y_axis_label='Data', tooltips=TOOLTIPS)
        p.line(df['phi'].index.values, df['phi'], line_width=2,
               legend_label='phi', name='phi', color="red")
        p.line(df['theta'].index.values, df['theta'], line_width=2,
               legend_label='theta', name='theta', color="green")
        p.line(df['u'].index.values, df['u'], line_width=2,
               legend_label='u', name='u', color="blue")
        output_file("plot.html")
        save(p)


    sim = Simulation()
    result = sim.run()
    sim.set_properties('propulsion/engine/set-running', 1)
    sim.set_properties('fcs/throttle-cmd-norm', 1.0)
    i = 0
    state = ""
    before = datetime.now()
    while result and sim.jsbsim.get_sim_time() <= 50:
        #print(i)
        state = sim.get_state()
        if i%5==0:
            sim.set_properties('fcs/aileron-cmd-norm', pid.innerLoopAileron(np.deg2rad(5), state['phi'], state['p'],
                                                                            sim.jsbsim.get_property_value(
                                                                           'fcs/aileron-cmd-norm')))
            sim.set_properties('fcs/elevator-cmd-norm', pid.innerLoopElevator(np.deg2rad(-10), state['theta'], state['q'],
                                                                              sim.jsbsim.get_property_value(
                                                                             'fcs/elevator-cmd-norm')))
        sim.run()
Пример #3
0
               line_width=2,
               legend_label='u',
               name='u',
               color="blue")
        p.line(df['rpm'].index.values,
               df['rpm'],
               line_width=2,
               legend_label='rpm',
               name='rpm',
               color="black")
        output_file("plot.html")
        save(p)

    sim = Simulation()
    result = sim.run()
    sim.set_properties('propulsion/starter_cmd', 1)
    sim.set_properties('propulsion/engine/set-running', 1)
    sim.set_properties('propulsion/magneto_cmd', 2.0)
    sim.set_properties('fcs/mixture-cmd-norm', 0.87)
    sim.set_properties('fcs/throttle-cmd-norm', 1.0)
    i = 0
    state = ""
    before = datetime.now()
    while result and sim.jsbsim.get_sim_time() <= 50:
        #print(i)
        state = sim.get_state()
        sim.set_properties('fcs/throttle-cmd-norm', 0.99)
        sim.set_properties('fcs/mixture-cmd-norm', 0.87)
        if i % 5 == 0:
            sim.set_properties(
                'fcs/aileron-cmd-norm',