From dab497eb6f596ee1beb8a7ac36a07d1b3b8da208 Mon Sep 17 00:00:00 2001 From: Brian Jackson Date: Sat, 10 Jul 2021 13:50:19 -0400 Subject: [PATCH] Fix minor bugs with linear models --- Project.toml | 2 +- src/linearmodel.jl | 3 ++- src/model.jl | 7 +++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Project.toml b/Project.toml index d43ef52..754a2c8 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "RobotDynamics" uuid = "38ceca67-d8d3-44e8-9852-78a5596522e1" authors = ["Brian Jackson "] -version = "0.3.3" +version = "0.3.4" [deps] FiniteDiff = "6a86dc24-6348-571c-b903-95158fe2bd41" diff --git a/src/linearmodel.jl b/src/linearmodel.jl index 0377109..f09638f 100644 --- a/src/linearmodel.jl +++ b/src/linearmodel.jl @@ -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 @@ -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, diff --git a/src/model.jl b/src/model.jl index 8ce9d31..51020f7 100644 --- a/src/model.jl +++ b/src/model.jl @@ -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