-
Notifications
You must be signed in to change notification settings - Fork 0
11 refactor model analysis #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
d33e463
Add a module to create controllers
rdesarz b3e95fe
Fix implementation errors and refactor the code
rdesarz 4f163fd
Add comments to describe examples and remove simulate_with_noise method
rdesarz 9489852
Add documentation to the controller module
rdesarz ff87d86
Add a method to provide an analysis report of an LTI system
rdesarz bace3f3
Remove controllers implementation as they will be integrated in anoth…
rdesarz 77bd26b
Remove LQR example
rdesarz 4282fdb
Remove LQR example from Cargo
rdesarz 0c73323
Add comments to the unit tests
rdesarz 8a17d56
Remove controllers
rdesarz b46c35c
Fix CI by installing required dependencies
rdesarz d4780c8
Remove controller module
rdesarz b0af7af
Simplify type declaration to avoid Clippy warning
rdesarz 2fd2853
Fix Clippy warnings
rdesarz 3af0fde
Break the API to avoid exposing unsafe methods
rdesarz 57368e9
Remove forward and backward euler discretization constructors
rdesarz 1a6e706
Remove Tustin discretization
rdesarz d212a5a
Add comments to the matrix exponential computation
rdesarz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| // LTI analysis-first example: | ||
| // Build a model and run a single consolidated analysis pass | ||
| // (poles, stability, controllability, observability). | ||
| use control_sys::{analysis, model}; | ||
| use nalgebra as na; | ||
|
|
||
| fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
| let system = model::DiscreteStateSpaceModel::try_from_matrices( | ||
| &na::dmatrix![0.9, 0.1; 0.0, 0.8], | ||
| &na::dmatrix![1.0; 0.5], | ||
| &na::dmatrix![1.0, 0.0], | ||
| &na::dmatrix![0.0], | ||
| 0.1, | ||
| )?; | ||
|
|
||
| let report = analysis::analyze_lti(&system, analysis::TimeDomain::Discrete, 1e-6)?; | ||
|
|
||
| println!("stable: {}", report.is_stable); | ||
| println!("spectral radius: {}", report.spectral_radius); | ||
| println!( | ||
| "controllable: {} (rank {}/{})", | ||
| report.controllability.is_full_rank, | ||
| report.controllability.rank, | ||
| report.controllability.expected_rank | ||
| ); | ||
| println!( | ||
| "observable: {} (rank {}/{})", | ||
| report.observability.is_full_rank, | ||
| report.observability.rank, | ||
| report.observability.expected_rank | ||
| ); | ||
|
|
||
| Ok(()) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| // End-to-end workflow: | ||
| // 1) Build a continuous model. | ||
| // 2) Discretize with ZOH. | ||
| // 3) Run a step simulation. | ||
| // 4) Check controllability. | ||
| use control_sys::{analysis, model, simulator}; | ||
| use nalgebra as na; | ||
|
|
||
| fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
| let a = na::dmatrix![0.0, 1.0; -2.0, -3.0]; | ||
| let b = na::dmatrix![0.0; 1.0]; | ||
| let c = na::dmatrix![1.0, 0.0]; | ||
| let d = na::dmatrix![0.0]; | ||
|
|
||
| let continuous = model::ContinuousStateSpaceModel::try_from_matrices(&a, &b, &c, &d)?; | ||
| let discrete = model::DiscreteStateSpaceModel::from_continuous_zoh(&continuous, 0.05)?; | ||
|
|
||
| let (y, _u, _x) = simulator::step_for_discrete_ss(&discrete, 5.0)?; | ||
| let (is_controllable, _ctrb) = analysis::is_ss_controllable(&discrete); | ||
|
|
||
| println!("step samples: {}", y.ncols()); | ||
| println!("controllable: {}", is_controllable); | ||
|
|
||
| Ok(()) | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The README now advertises controller helpers (pole placement/LQR/closed-loop assembly), but this commit’s public API only exposes
analysis,model,simulator, andtrajectorymodules (src/lib.rs), so users relying on these bullets will look for APIs that are not present and hit compile-time failures when trying to adopt the library from documentation alone. Please align the highlights with what this revision actually ships.Useful? React with 👍 / 👎.