Skip to content
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

More LQG updates #467

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open

More LQG updates #467

wants to merge 11 commits into from

Conversation

baggepinnen
Copy link
Member

This PR adds tests for LQG and makes sure it conforms to Glad Ljung

@codecov
Copy link

codecov bot commented Apr 5, 2021

Codecov Report

Merging #467 (65db880) into master (0919c03) will decrease coverage by 0.03%.
The diff coverage is 86.71%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #467      +/-   ##
==========================================
- Coverage   85.28%   85.25%   -0.04%     
==========================================
  Files          31       32       +1     
  Lines        3092     3180      +88     
==========================================
+ Hits         2637     2711      +74     
- Misses        455      469      +14     
Impacted Files Coverage Δ
src/ControlSystems.jl 100.00% <ø> (ø)
src/model_augmentation.jl 64.10% <64.10%> (ø)
src/types/lqg.jl 90.90% <96.62%> (+7.09%) ⬆️
src/synthesis.jl 65.11% <0.00%> (-6.68%) ⬇️
src/types/DelayLtiSystem.jl 73.68% <0.00%> (-0.28%) ⬇️
src/utilities.jl 83.67% <0.00%> (-0.17%) ⬇️
src/connections.jl 94.28% <0.00%> (-0.04%) ⬇️
src/types/conversion.jl 96.92% <0.00%> (-0.03%) ⬇️
... and 5 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0919c03...65db880. Read the comment docs.

"""
add_disturbance(sys::AbstractStateSpace{Continuous}, Ad::AbstractMatrix, Cd::AbstractMatrix)

See CCS pp. 144
Copy link
Member

@mfalt mfalt Apr 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the description should be a bit better here, I could not figure out what the function was doing without reading the code. Maybe the expression for the new system matrix is enough.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that you probably use this to introduce disturbances, but it seems that it could be called something more general, like 'augment_system'.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, all augmentation functions require better docstrings

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, your first comment probably got eaten up by autocorrect ;)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, that was tough to read, fixed now.

ss(Ae,Be,Ce,De)
end

function add_measurement_disturbance(sys::AbstractStateSpace{Continuous}, Ad::AbstractMatrix, Cd::AbstractMatrix)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have a docstring if we export. Same for the rest

src/types/lqg.jl Show resolved Hide resolved

# Extract interesting values
if G.integrator # Augment with disturbance model
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this removed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is no longer stored in the struct, instead the extended statespace object syse is stored. adding an integrator is just a special case of adding disturbance models, corresponding to a low-frequency input disturbance

# Arguments:
- `sys`: System to augment
- `Ad`: The dynamics of the disturbance
- `Cd`: How the disturbance states affect the states of `sys`. This matrix as the shape (sys.nx, size(Ad, 1))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This matrix has the shape...

@olof3
Copy link
Contributor

olof3 commented Apr 7, 2021

We have been lacking a simple way of augmenting systems with disturbance/noise models, so it is good that something is finally happening!

  • How is the intensity of the noise/disturbances handled? would perhaps be convenient to specify these just for the disturbances rather than some noise intensity for the whole A matrix.
  • I guess for, e.g., a resonant disturbance, 1/(s^2 + 2zetaw0 + w0^2) one would also like to keep track of the B matrix of its state-space realization?
  • I think it should be possible to add arbitrary dynamics in the form of a linear system as disturbance models. Then I think that we should export some of the methods for creating systems from DemoSystems, at least lag and resonant. (Looking over their names and arguments, making sure that they are acceptable). E.g., I.e., we no need for add_low_frequency_disturbance, etc.
  • If possible I think it would be desirable to separate how a disturbances affect the system dynamics from various disturbance models that one would like to investigate. Perhaps using some kind of partitioned state space.
  • The LQG struct seems a bit monolithic/inflexible. Some sort of problem data struct, containing the problem specification would seem useful though, e.g., in order to evaluate other linear controllers. We should fix the feedback function to accept UniformScaling, then all the sensitivity functions would just be one-liners, and perhaps wouldn't be needed to be included as getproperty. Or do we feel a need for defining these generally?

Perhaps you have some examples/use cases? Would be easier to discuss around something a bit more concrete. If I have the time, I will try to put something together as well. And I guess there should be plenty of examples in the literature, any suggestions?

@baggepinnen
Copy link
Member Author

  • How is the intensity of the noise/disturbances handled? would perhaps be convenient to specify these just for the disturbances rather than some noise intensity for the whole A matrix.

It's not handled yet, maybe allowing the user to pass another parameter that is taking the place of the 1 in the C-matrix?

  • I guess for, e.g., a resonant disturbance, 1/(s^2 + 2_zeta_w0 + w0^2) one would also like to keep track of the B matrix of its state-space realization?

Yes, if it's a known disturbance. The augmentation so far only handles unknown disturbances for which the B-matrix is only extended with zeros.

  • I think it should be possible to add arbitrary dynamics in the form of a linear system as disturbance models. Then I think that we should export some of the methods for creating systems from DemoSystems, at least lag and resonant. (Looking over their names and arguments, making sure that they are acceptable). E.g., I.e., we no need for add_low_frequency_disturbance, etc.

The add_low_frequency_disturbance really aims to achieve integral action in the LQG controller by modeling a constant input disturbance. It is a good idea to have a way to create typical disturbance models and add those, e.g., add_input_disturbance(sys, step_model()) or something like that.

  • If possible I think it would be desirable to separate how a disturbances affect the system dynamics from various disturbance models that one would like to investigate. Perhaps using some kind of partitioned state space.

I've been thinking a bit about this and I don't think we need to implement a new system type. It could probably be solved by making the matrices have named components, e.g., through ComponentArrays.jl. I've used this strategy elsewhere and it works quite nicely. The HeteroStateSpace already accepts this kind of matrices.

  • The LQG struct seems a bit monolithic/inflexible. Some sort of problem data struct, containing the problem specification would seem useful though, e.g., in order to evaluate other linear controllers. We should fix the feedback function to accept UniformScaling, then all the sensitivity functions would just be one-liners, and perhaps wouldn't be needed to be included as getproperty. Or do we feel a need for defining these generally?

I agree, I don't like the design all that much. Maybe it would be better to just break it completely and redesign it so that the structure only contains computed results that are generally useful, and all other results (that are now properties) are just implemented as regular functions instead. The purpose of defining functions is that it might be hard to remember the exact formulations for input/output sensitivity for MIMO systems if you don't have a reference book or pen and paper nearby. Having them as functions prevent you from making simple errors. Getting exactly the same realisation out as matlab also required some gymnastics, at least for output_sensitivity

Perhaps you have some examples/use cases? Would be easier to discuss around something a bit more concrete. If I have the time, I will try to put something together as well. And I guess there should be plenty of examples in the literature, any suggestions?

Double-mass model (4 states) augmented with constant input disturbance (1 state) and resonant measurement disturbance (2 states) to reduce sensitivity at select frequencies. Motor-side states are measured, while references are provided for load-side states (C and M matrices are different) while noise acts on the two velocity states as well as the input-disturbance state. I'll put together some code soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants