Mr8bit commited on
Commit
7fc4c75
·
verified ·
1 Parent(s): 5781cae

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +378 -0
README.md ADDED
@@ -0,0 +1,378 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ language:
4
+ - en
5
+ tags:
6
+ - model-predictive-control
7
+ - mpc
8
+ - pytorch
9
+ - aerospace
10
+ - flight-control
11
+ - boeing-747
12
+ - learned-dynamics
13
+ - neural-network
14
+ - continuous-control
15
+ - gymnasium
16
+ library_name: tensoraerospace
17
+ pipeline_tag: reinforcement-learning
18
+ model-index:
19
+ - name: MPC-OneStepMLP-B747-PitchControl
20
+ results:
21
+ - task:
22
+ type: model-predictive-control
23
+ name: Pitch Angle Tracking Control
24
+ dataset:
25
+ type: custom
26
+ name: Boeing 747 Longitudinal Dynamics Simulation
27
+ metrics:
28
+ - type: overshoot
29
+ value: 0.27
30
+ name: Overshoot (%)
31
+ - type: settling_time
32
+ value: 1.40
33
+ name: Settling Time (s)
34
+ - type: rise_time
35
+ value: 0.80
36
+ name: Rise Time (s)
37
+ - type: peak_time
38
+ value: 1.70
39
+ name: Peak Time (s)
40
+ - type: static_error
41
+ value: 0.038
42
+ name: Static Error
43
+ - type: oscillation_count
44
+ value: 5
45
+ name: Oscillation Count
46
+ - type: performance_index
47
+ value: 72.62
48
+ name: Performance Index
49
+ - type: iae
50
+ value: 41.25
51
+ name: IAE
52
+ - type: ise
53
+ value: 147.43
54
+ name: ISE
55
+ - type: itae
56
+ value: 33.99
57
+ name: ITAE
58
+ - type: dynamics_loss
59
+ value: 8.69e-6
60
+ name: Dynamics Model MSE Loss
61
+ ---
62
+
63
+ # TorchMPC with Learned Dynamics (OneStepMLP) for Boeing 747 Pitch Angle Control
64
+
65
+ <div align="center">
66
+
67
+ ![TensorAeroSpace](https://raw.githubusercontent.com/TensorAeroSpace/TensorAeroSpace/main/img/logo-no-background.png)
68
+
69
+ **Model Predictive Control with Neural Network Dynamics for Longitudinal Aircraft Control**
70
+
71
+ [![TensorAeroSpace](https://img.shields.io/badge/%F0%9F%9A%80-TensorAeroSpace-blue)](https://github.com/TensorAeroSpace/TensorAeroSpace)
72
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
73
+ [![PyTorch](https://img.shields.io/badge/PyTorch-2.0+-red.svg)](https://pytorch.org/)
74
+
75
+ </div>
76
+
77
+ ## Model Description
78
+
79
+ This model combines **Model Predictive Control (MPC)** with a **learned neural network dynamics model (OneStepMLP)** to control the pitch angle (θ) of a **Boeing 747** aircraft in a longitudinal flight dynamics simulation. The approach first learns the aircraft dynamics from exploration data, then uses gradient-based MPC optimization to compute optimal control actions for reference tracking.
80
+
81
+ ![image](https://cdn-uploads.huggingface.co/production/uploads/602bf7c9c4f8038e9a1e0a65/yZYzPcK_PU7uFh_j6pZii.png)
82
+
83
+ ### Key Features
84
+
85
+ - **Data-driven dynamics**: Learns one-step transition model f(x, u) → Δx from exploration data
86
+ - **Gradient-based MPC**: Differentiable optimization through learned dynamics
87
+ - **Step response optimization**: Custom cost function for overshoot/settling time minimization
88
+ - **Warm-starting**: Efficient action sequence initialization across timesteps
89
+
90
+ ### Intended Uses
91
+
92
+ - **Primary Use**: Automatic pitch angle tracking and stabilization for Boeing 747 aircraft simulation
93
+ - **Research Applications**: Benchmarking learning-based MPC algorithms for aerospace control systems
94
+ - **Educational**: Learning MPC concepts with neural network dynamics in aerospace applications
95
+ - **Hybrid Control**: Can be combined with analytical models for robust flight control
96
+
97
+ ## Model Architecture
98
+
99
+ ### Dynamics Model (OneStepMLP)
100
+
101
+ The dynamics model predicts state transitions using a multi-layer perceptron:
102
+
103
+ | Layer | Configuration |
104
+ |-------|---------------|
105
+ | Input | 5 (state_dim=4 + action_dim=1) |
106
+ | Hidden 1 | Linear(5, 256) + ReLU |
107
+ | Hidden 2 | Linear(256, 256) + ReLU |
108
+ | Output | Linear(256, 4) |
109
+ | Mode | Predict Δx (delta dynamics) |
110
+
111
+ **Total Parameters**: ~70K
112
+
113
+ ### MPC Controller
114
+
115
+ | Parameter | Value |
116
+ |-----------|-------|
117
+ | Horizon | 20 steps |
118
+ | Iterations per step | 60 |
119
+ | Optimizer | Adam |
120
+ | MPC Learning Rate | 0.02 |
121
+ | Warm Start | Enabled |
122
+ | Track Best | Enabled |
123
+
124
+ ### State Space
125
+
126
+ The observation vector consists of 4 states representing the longitudinal dynamics:
127
+
128
+ | Index | State | Description | Units |
129
+ |-------|-------|-------------|-------|
130
+ | 0 | u | Forward velocity perturbation | m/s (rad internally) |
131
+ | 1 | w | Vertical velocity perturbation | m/s (rad internally) |
132
+ | 2 | q | Pitch rate | rad/s |
133
+ | 3 | θ | Pitch angle (tracking target) | rad |
134
+
135
+ ### Action Space
136
+
137
+ | Dimension | Description | Range | Rate Limit |
138
+ |-----------|-------------|-------|------------|
139
+ | 1 | Elevator deflection | [-25°, 25°] | ±10°/step |
140
+
141
+ ## Training Details
142
+
143
+ ### Data Collection
144
+
145
+ | Parameter | Value |
146
+ |-----------|-------|
147
+ | Collection Episodes | 1500 |
148
+ | Transitions Collected | 297,000 |
149
+ | Exploration Strategy | Multi-signal exploration |
150
+ | Signal Types | random_steps, unit_step, multi_step, ramp, sinusoid, multisine, chirp, square_wave, triangular_wave, sawtooth, doublet, pulse, gaussian_pulse, exponential, damped_sinusoid |
151
+ | Action Amplitude | 100% of action space |
152
+
153
+ ### Dynamics Training
154
+
155
+ | Parameter | Value |
156
+ |-----------|-------|
157
+ | Epochs | 120 |
158
+ | Batch Size | 2048 |
159
+ | Learning Rate | 1e-4 |
160
+ | Loss Function | MSE |
161
+ | Final Loss | 8.69e-6 |
162
+ | Normalization | Enabled |
163
+
164
+ ### MPC Cost Weights
165
+
166
+ | Weight | Value | Description |
167
+ |--------|-------|-------------|
168
+ | W_θ | 2000.0 | Pitch tracking weight |
169
+ | W_q | 0.2 | Pitch rate weight |
170
+ | W_action | 0.01 | Control effort weight |
171
+ | W_Δu | 5.0 | Control rate weight |
172
+ | Terminal | 10.0 | Terminal cost multiplier |
173
+
174
+ ### Step Response Cost Configuration
175
+
176
+ | Parameter | Value |
177
+ |-----------|-------|
178
+ | W_overshoot | 8,000 |
179
+ | W_settle | 8,000 |
180
+ | W_sse_steady | 40,000 |
181
+ | W_time | 800 |
182
+ | W_osc | 500 |
183
+ | W_jerk | 50 |
184
+ | Overshoot limit | 0.05° |
185
+ | Settle band | 0.10° |
186
+ | Settle time target | 1.0 s |
187
+
188
+ ### Environment Configuration
189
+
190
+ | Parameter | Value |
191
+ |-----------|-------|
192
+ | Environment | `LinearLongitudinalB747-v0` |
193
+ | Time Step (dt) | 0.1 s |
194
+ | Episode Duration | 20 s |
195
+ | Initial State | [0, 0, 0, 0] |
196
+ | Reference Signal | Step function |
197
+ | Step Amplitude | 1.0° |
198
+ | Step Time | 5.0 s |
199
+
200
+ ### Training Infrastructure
201
+
202
+ - **Hardware**: CUDA GPU (recommended) / CPU
203
+ - **Framework**: PyTorch 2.0+
204
+ - **Compile Mode**: reduce-overhead (CUDA only)
205
+
206
+ ## Evaluation Results
207
+
208
+ ### Performance Metrics
209
+
210
+ | Metric | Value |
211
+ |--------|-------|
212
+ | **Overshoot** | 0.27% |
213
+ | **Settling Time (±5%)** | 1.40 s |
214
+ | **Rise Time** | 0.80 s |
215
+ | **Peak Time** | 1.70 s |
216
+ | **Static Error** | 0.038 |
217
+ | **Oscillation Count** | 5 |
218
+ | **Performance Index** | 72.62 |
219
+ | **Damping Degree** | -0.002 |
220
+
221
+ ### Integral Criteria
222
+
223
+ | Criterion | Value |
224
+ |-----------|-------|
225
+ | IAE (Integral Absolute Error) | 41.25 |
226
+ | ISE (Integral Squared Error) | 147.43 |
227
+ | ITAE (Integral Time-weighted Absolute Error) | 33.99 |
228
+
229
+ ### Step Response Characteristics
230
+
231
+ The MPC controller demonstrates good step tracking performance with:
232
+ - ✅ Very low overshoot (~0.27%)
233
+ - ✅ Fast settling time (1.4s)
234
+ - ✅ Quick rise time (0.8s)
235
+ - ⚠️ Some oscillations (5 cycles)
236
+ - ⚠️ Small static error (0.038)
237
+
238
+ ## Usage
239
+
240
+ ### Installation
241
+
242
+ ```bash
243
+ pip install tensoraerospace
244
+ ```
245
+
246
+ ### Quick Start
247
+
248
+ ```python
249
+ import numpy as np
250
+ import gymnasium as gym
251
+ import torch
252
+ from tensoraerospace.signals.standart import unit_step
253
+ from tensoraerospace.agent.mpc import MPCAgent
254
+
255
+ def pick_device() -> str:
256
+ if torch.cuda.is_available():
257
+ return "cuda"
258
+ if hasattr(torch.backends, "mps") and torch.backends.mps.is_available():
259
+ return "mps"
260
+ return "cpu"
261
+
262
+ # Setup environment
263
+ DT = 0.1
264
+ TN = 20.0
265
+ N_STEPS = int(TN / DT) + 1
266
+ T = np.arange(N_STEPS, dtype=np.float32) * DT
267
+
268
+ # Create step reference signal (1 degree step at t=5s)
269
+ reference_signal = unit_step(
270
+ tp=T,
271
+ degree=1.0,
272
+ time_step=5.0,
273
+ output_rad=True,
274
+ ).reshape(1, -1)
275
+
276
+ env = gym.make(
277
+ "LinearLongitudinalB747-v0",
278
+ number_time_steps=N_STEPS,
279
+ initial_state=np.array([[0.0], [0.0], [0.0], [0.0]], dtype=np.float32),
280
+ reference_signal=reference_signal,
281
+ dt=DT,
282
+ )
283
+
284
+ # Load pretrained agent
285
+ agent = MPCAgent.from_pretrained("TensorAeroSpace/torchmpc-mlp-b747-step-response")
286
+ agent.env = env
287
+ agent.to_device(pick_device())
288
+
289
+ # Run evaluation
290
+ _ = env.reset()
291
+ agent.reset()
292
+
293
+ ref_theta_rad = reference_signal[0]
294
+ x_ref = np.zeros((21, 4), dtype=np.float32) # horizon + 1
295
+
296
+ for step in range(N_STEPS - 2):
297
+ k = int(env.unwrapped.current_step)
298
+ x0 = np.asarray(env.unwrapped.model.xt, dtype=np.float32).reshape(-1)
299
+
300
+ # Set reference for horizon
301
+ ref_k = float(ref_theta_rad[min(k, len(ref_theta_rad) - 1)])
302
+ x_ref[:, 3] = ref_k
303
+
304
+ action = agent.select_action(x0, x_ref=x_ref)
305
+ obs, reward, terminated, truncated, info = env.step(action)
306
+
307
+ if terminated or truncated:
308
+ break
309
+ ```
310
+
311
+ ### Custom Dynamics Training
312
+
313
+ ```python
314
+ # Collect exploration data
315
+ agent.collect_data(
316
+ num_episodes=1500,
317
+ max_steps=199,
318
+ exploration="signals",
319
+ signal_kinds=["random_steps", "sinusoid", "chirp", ...],
320
+ dt=0.1,
321
+ action_amplitude_frac=1.0,
322
+ )
323
+
324
+ # Train dynamics model
325
+ metrics = agent.train_dynamics(
326
+ epochs=120,
327
+ batch_size=2048,
328
+ loss="mse",
329
+ )
330
+ print(f"Final dynamics loss: {metrics['loss']:.2e}")
331
+ ```
332
+
333
+ ## Comparison with Other Methods
334
+
335
+ | Method | Overshoot | Settling Time | Rise Time | Static Error |
336
+ |--------|-----------|---------------|-----------|--------------|
337
+ | **TorchMPC-MLP** | 0.27% | 1.40 s | 0.80 s | 0.038 |
338
+ | DSAC | 0.99% | 0.40 s | 0.40 s | 0.0002 |
339
+ | PID (tuned) | ~5% | ~2.0 s | ~1.0 s | ~0 |
340
+
341
+ ## Limitations
342
+
343
+ - **Fixed Aircraft Model**: Trained specifically on Boeing 747 longitudinal dynamics; may not generalize to other aircraft
344
+ - **Step Reference Focus**: Optimized for step reference tracking; performance on other signal types may vary
345
+ - **Simulation Gap**: Trained in simulation; real-world deployment would require additional validation
346
+ - **Computational Cost**: MPC optimization at each step requires more computation than pure RL policies
347
+ - **Linear Dynamics**: Based on linearized aircraft model around trim conditions
348
+ - **Some Oscillations**: The controller exhibits 5 oscillation cycles during settling
349
+
350
+ ## Ethical Considerations
351
+
352
+ - **Not for Real Flight Control**: This model is for research and educational purposes only. It should NOT be used for actual aircraft control systems without extensive testing, certification, and regulatory approval.
353
+ - **Simulation Only**: All training and evaluation performed in simulation environments.
354
+
355
+ ## Citation
356
+
357
+ If you use this model in your research, please cite:
358
+
359
+ ```bibtex
360
+ @software{tensoraerospace2024,
361
+ title = {TensorAeroSpace: Advanced Aerospace Control Systems \& Reinforcement Learning Framework},
362
+ author = {TensorAeroSpace Team},
363
+ year = {2024},
364
+ url = {https://github.com/TensorAeroSpace/TensorAeroSpace},
365
+ license = {MIT}
366
+ }
367
+ ```
368
+
369
+ ## Model Card Authors
370
+
371
+ TensorAeroSpace Team
372
+
373
+ ## Model Card Contact
374
+
375
+ - **GitHub**: [TensorAeroSpace/TensorAeroSpace](https://github.com/TensorAeroSpace/TensorAeroSpace)
376
+ - **Documentation**: [tensoraerospace.readthedocs.io](https://tensoraerospace.readthedocs.io/)
377
+ - **Hugging Face**: [TensorAeroSpace](https://huggingface.co/TensorAeroSpace)
378
+ ```