Skip to content

Commit

Permalink
Fix minor bugs with linear models
Browse files Browse the repository at this point in the history
  • Loading branch information
bjack205 committed Jul 10, 2021
1 parent 7c36117 commit dab497e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "RobotDynamics"
uuid = "38ceca67-d8d3-44e8-9852-78a5596522e1"
authors = ["Brian Jackson <bjack205@gmail.com>"]
version = "0.3.3"
version = "0.3.4"

[deps]
FiniteDiff = "6a86dc24-6348-571c-b903-95158fe2bd41"
Expand Down
3 changes: 2 additions & 1 deletion src/linearmodel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ function discrete_jacobian!(::Type{PassThrough}, ∇f, model::LinearModel, z::Ab
∇f[ix,ix] .= model.A[k]
∇f[ix,iu] .= model.B[k]

nothing
true
end


Expand Down Expand Up @@ -185,6 +185,7 @@ function discrete_jacobian!(::Type{Exponential}, F, model::LinearModel{n,m},
matrix_exponential!(model, z)

F .= model.E[1:n, 1:n+m]
return true
end

function matrix_exponential!(E::SizedMatrix, A, B, dt,
Expand Down
7 changes: 5 additions & 2 deletions src/model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,14 @@ Create a sparse matrix representing the nonzero elements of the discrete dynamic
Jacobian. Uses ForwardDiff to compute the Jacobian on `samples` randomly-sampled
states and controls.
"""
function detect_sparsity(::Type{Q}, model::AbstractModel, samples=10) where Q
function detect_sparsity(::Type{Q}, model::AbstractModel; dt=0.1, samples=10) where Q
n,m = size(model)
∇f = spzeros(n,n+m)
if (model isa RobotDynamics.AbstractLinearModel)
return ∇f .== 0
end
x,u = rand(model)
z = StaticKnotPoint(x,u,0.1)
z = StaticKnotPoint(x,u,dt)
for i = 1:samples # try several inputs to get the sparsity pattern
_discrete_jacobian!(ForwardAD(), Q, ∇f, model, z, nothing)
end
Expand Down

2 comments on commit dab497e

@bjack205
Copy link
Member Author

Choose a reason for hiding this comment

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

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/40655

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.3.4 -m "<description of version>" dab497eb6f596ee1beb8a7ac36a07d1b3b8da208
git push origin v0.3.4

Please sign in to comment.