The observation vector consists of 5 normalized states representing the longitudinal dynamics (with include_reference_in_obs=True):
The normalized action is scaled to physical elevator deflection in degrees by the environment.
1import numpy as np
2import torch
3from tensoraerospace.agent import DSAC
4from tensoraerospace.envs.b747 import ImprovedB747Env
5from tensoraerospace.signals.standart import unit_step
6
7def pick_device() -> str:
8 if torch.cuda.is_available():
9 return "cuda"
10 if getattr(torch.backends, "mps", None) is not None and torch.backends.mps.is_available():
11 return "mps"
12 return "cpu"
13
14# Setup environment
15dt = 0.1
16tn = 20.0
17step_deg = 1.0
18step_time_sec = 5.0
19t = np.arange(0.0, tn + dt, dt, dtype=np.float32)
20
21# Create step reference signal (1 degree step at t=5s)
22ref = unit_step(t, degree=step_deg, time_step=step_time_sec, output_rad=True).reshape(1, -1)
23
24env = ImprovedB747Env(
25 initial_state=np.array([0.0, 0.0, 0.0, 0.0], dtype=float),
26 reference_signal=ref,
27 number_time_steps=ref.shape[1],
28 dt=dt,
29 include_reference_in_obs=True,
30 reward_mode="step_response",
31)
32
33# Load pretrained agent
34agent = DSAC.from_pretrained("TensorAeroSpace/dsac-b747-step-response")
35agent.env = env
36agent.to_device(pick_device())
37agent.eval()
38
39# Run evaluation
40obs, _ = env.reset()
41done = False
42total_reward = 0.0
43
44while not done:
45 action = agent.select_action(obs, evaluate=True)
46 obs, reward, terminated, truncated, info = env.step(action)
47 done = bool(terminated or truncated)
48 total_reward += float(reward)
49
50print(f"Episode reward: {total_reward}")
1from tensoraerospace.agent import DSAC
2
3# Load from local directory
4agent = DSAC.from_pretrained("./path/to/checkpoint")
1@software{tensoraerospace2024,
2 title = {TensorAeroSpace: Advanced Aerospace Control Systems \& Reinforcement Learning Framework},
3 author = {TensorAeroSpace Team},
4 year = {2024},
5 url = {https://github.com/TensorAeroSpace/TensorAeroSpace},
6 license = {MIT}
7}