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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/ControlSystems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@ export LTISystem,
numpoly,
denpoly,
iscontinuous,
isdiscrete
isdiscrete,
# model augmentation
add_disturbance,
add_low_frequency_disturbance,
add_resonant_disturbance


# QUESTION: are these used? LaTeXStrings, Requires, IterTools
Expand Down Expand Up @@ -159,6 +163,7 @@ include("simulators.jl")
include("pid_design.jl")

include("demo_systems.jl")
include("model_augmentation.jl")

include("delay_systems.jl")

Expand Down
64 changes: 64 additions & 0 deletions src/model_augmentation.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
"""
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.


# 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...


See also `add_low_frequency_disturbance, add_resonant_disturbance`
"""
function add_disturbance(sys::AbstractStateSpace{Continuous}, Ad::AbstractMatrix, Cd::AbstractMatrix)
A,B,C,D = ControlSystems.ssdata(sys)
T = eltype(A)
nx,nu,ny = sys.nx,sys.nu,sys.ny
Ae = [A Cd; zeros(T, size(Ad, 1), nx) Ad]
Be = [B; zeros(T, size(Ad, 1), nu)]
Ce = [C zeros(T, ny, size(Ad, 1))]
De = D
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

A,B,C,D = ControlSystems.ssdata(sys)
T = eltype(A)
nx,nu,ny = sys.nx,sys.nu,sys.ny
Ae = [A zeros(T, nx, size(Ad, 1)); zeros(T, size(Ad, 1), nx) Ad]
Be = [B; zeros(T, size(Ad, 1), nu)]
Ce = [C Cd]
De = D
ss(Ae,Be,Ce,De)
end

function add_low_frequency_disturbance(sys::AbstractStateSpace{Continuous}, Ai::Integer; ϵ=0)
nx,nu,ny = sys.nx,sys.nu,sys.ny
Cd = zeros(nx, 1)
Cd[Ai] = 1
add_disturbance(sys, fill(-ϵ, 1, 1), Cd)
end

function add_low_frequency_disturbance(sys::AbstractStateSpace{Continuous}; ϵ=0, measurement=false)
nx,nu,ny = sys.nx,sys.nu,sys.ny
if measurement
Cd = I(nu)
add_measurement_disturbance(sys, -ϵ*I(nu), Cd)
else
Cd = sys.B
add_disturbance(sys, -ϵ*I(nu), Cd)
end
end

function add_resonant_disturbance(sys::AbstractStateSpace{Continuous}, ω, ζ, Ai::Integer; measurement=false)
nx,nu,ny = sys.nx,sys.nu,sys.ny
if measurement
Cd = zeros(ny, 2)
Cd[Ai, 1] = 1
else
Cd = zeros(nx, 2)
Cd[Ai, 1] = 1
end
Ad = [-ζ -ω; ω -ζ]
measurement ? add_measurement_disturbance(sys, Ad, Cd) : add_disturbance(sys, Ad, Cd)
end
Loading