-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·32 lines (25 loc) · 763 Bytes
/
main.py
File metadata and controls
executable file
·32 lines (25 loc) · 763 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env python3
"""
Example script demonstrating plant setup, control synthesis,
and simulation using controltoolbox.
"""
from control_toolbox import (
InvertedPendulum,
add_delay,
build_controller,
compute_metrics,
discretize,
plot_response,
simulate,
)
def main() -> None:
"""Demo script: create plant, design controller, simulate and save plot."""
plant = InvertedPendulum()
plant = add_delay(plant, T_input=0.5, T_output=0.5)
plant = discretize(plant, dt=0.01)
ctrl = build_controller(plant, track={"x": 0.5, "phi": 0.0}, p=200)
resp = simulate(ctrl, t_end=5.0)
fig = plot_response(resp, metrics=compute_metrics(resp))
fig.savefig("response.png")
if __name__ == "__main__":
main()