Skip to content

Add CBF-CLF-SOCP safety filters for the execution layer - #86

Open
Optimax14 wants to merge 5 commits into
mainfrom
itay/safety-filters
Open

Add CBF-CLF-SOCP safety filters for the execution layer#86
Optimax14 wants to merge 5 commits into
mainfrom
itay/safety-filters

Conversation

@Optimax14

Copy link
Copy Markdown
Contributor

Adds a local CBF-CLF-SOCP safety filter (ControlSheaves.SafetyFilters).

  • CLF row, barrier rows, actuator cone are independent and compose into one conic QP
  • solved with the existing IPM, no new deps
  • worked example + gifs: docs/literate/layered/escort_cbf_clf.jl
  • had to move the IPM include above network_sheaves in CellularSheaves.jl so ControlSheaves can see it, load-order only

@codecov

codecov Bot commented Aug 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 56.72783% with 283 lines in your changes missing coverage. Please review.
✅ Project coverage is 62.47%. Comparing base (d738981) to head (230e562).

Files with missing lines Patch % Lines
ext/CellularSheavesPlots/src/SafetyFilterPlots.jl 0.00% 235 Missing ⚠️
src/ControlSheaves/SafetyFilters/rollout.jl 0.00% 18 Missing ⚠️
ext/CellularSheavesPlots.jl 0.00% 16 Missing ⚠️
src/ControlSheaves/SafetyFilters/barriers.jl 72.41% 8 Missing ⚠️
src/ControlSheaves/SafetyFilters/model.jl 95.08% 3 Missing ⚠️
src/ControlSheaves/SafetyFilters/filter.jl 96.77% 2 Missing ⚠️
src/ControlSheaves/SafetyFilters/program.jl 98.79% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main      #86       +/-   ##
===========================================
+ Coverage   52.17%   62.47%   +10.29%     
===========================================
  Files          76       86       +10     
  Lines        8475     9114      +639     
===========================================
+ Hits         4422     5694     +1272     
+ Misses       4053     3420      -633     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jpfairbanks jpfairbanks left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is almost there. Just a few follow up questions and some type hierarchy redesign in the inline comments.

Comment thread docs/make.jl
@info "Building Documenter.jl docs"
makedocs(
modules=[CellularSheaves, CellularSheaves.ControlSheaves, CellularSheaves.ControlSheaves.Tikhonov, CellularSheaves.ControlSheaves.AgentControllers, CellularSheaves.ControlSheaves.DistributedLayeredControl, CellularSheaves.ControlSheaves.Layered, CellularSheaves.ControlSheaves.NestedSystems, CellularSheaves.ControlSheaves.NestedDSL, CellularSheaves.ControlSheaves.NestedDSL.NestedDSLTerm, CellularSheaves.ControlSheaves.NestedDSL.NestedDSLParser, CellularSheaves.ControlSheaves.NestedDSL.NestedDSLValidator, CellularSheaves.ControlSheaves.NestedDSL.NestedDSLLowering, CellularSheaves.ControlSheaves.MultiAgentTracking, CellularSheaves.ControlSheaves.MultiAgentTracking.QuadraticCosts, CellularSheaves.ControlSheaves.CoordinationBenchmarks, CellularSheaves.AsynchSheaves, CellularSheaves.SheafInterface, CellularSheaves.NetworkSheaves.EuclideanSheaves, CellularSheaves.NetworkSheaves.GraphHomomorphisms, CellularSheaves.NetworkSheaves.SheafMorphisms, CellularSheaves.NetworkSheaves.Pushforwards, CellularSheaves.NetworkSheaves.Pushouts, CellularSheaves.NetworkSheaves.CellularSheafParser, CellularSheaves.BlockSparseArrays, CellularSheaves.NetworkSheaves.PotentialSheaves, CellularSheaves.NetworkSheaves.TrajectorySheaves, CellularSheaves.NetworkSheaves.DistributedSolve, CellularSheaves.NetworkSheaves.Formations, CellularSheaves.ControlSheaves.TrackingDSL, CellularSheaves.ControlSheaves.TrackingDSL.TrackingDSLTerm, CellularSheaves.ControlSheaves.TrackingDSL.TrackingDSLParser, CellularSheaves.ControlSheaves.TrackingDSL.TrackingDSLValidator, CellularSheaves.ControlSheaves.TrackingDSL.TrackingDSLResolver, CellularSheaves.ControlSheaves.TrackingDSL.TrackingDSLLowering, CellularSheaves.IPM],
modules=[CellularSheaves, CellularSheaves.ControlSheaves, CellularSheaves.ControlSheaves.Tikhonov, CellularSheaves.ControlSheaves.AgentControllers, CellularSheaves.ControlSheaves.SafetyFilters, CellularSheaves.ControlSheaves.DistributedLayeredControl, CellularSheaves.ControlSheaves.Layered, CellularSheaves.ControlSheaves.NestedSystems, CellularSheaves.ControlSheaves.NestedDSL, CellularSheaves.ControlSheaves.NestedDSL.NestedDSLTerm, CellularSheaves.ControlSheaves.NestedDSL.NestedDSLParser, CellularSheaves.ControlSheaves.NestedDSL.NestedDSLValidator, CellularSheaves.ControlSheaves.NestedDSL.NestedDSLLowering, CellularSheaves.ControlSheaves.MultiAgentTracking, CellularSheaves.ControlSheaves.MultiAgentTracking.QuadraticCosts, CellularSheaves.ControlSheaves.CoordinationBenchmarks, CellularSheaves.AsynchSheaves, CellularSheaves.SheafInterface, CellularSheaves.NetworkSheaves.EuclideanSheaves, CellularSheaves.NetworkSheaves.GraphHomomorphisms, CellularSheaves.NetworkSheaves.SheafMorphisms, CellularSheaves.NetworkSheaves.Pushforwards, CellularSheaves.NetworkSheaves.Pushouts, CellularSheaves.NetworkSheaves.CellularSheafParser, CellularSheaves.BlockSparseArrays, CellularSheaves.NetworkSheaves.PotentialSheaves, CellularSheaves.NetworkSheaves.TrajectorySheaves, CellularSheaves.NetworkSheaves.DistributedSolve, CellularSheaves.NetworkSheaves.Formations, CellularSheaves.ControlSheaves.TrackingDSL, CellularSheaves.ControlSheaves.TrackingDSL.TrackingDSLTerm, CellularSheaves.ControlSheaves.TrackingDSL.TrackingDSLParser, CellularSheaves.ControlSheaves.TrackingDSL.TrackingDSLValidator, CellularSheaves.ControlSheaves.TrackingDSL.TrackingDSLResolver, CellularSheaves.ControlSheaves.TrackingDSL.TrackingDSLLowering, CellularSheaves.IPM],

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

let's break this list into separate lines to make diffs easier to review.

"""
CBFCLFParams(; kwargs...)

Tuning for the usual composition of one [`StabilityTerm`](@ref), one [`SafetyTerm`](@ref),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What happens for multiple agent formations where each agent needs to have multiple safety filters, one for each near-agent?

`result.certified` is `false`, so a caller can count uncertified steps rather than silently
treating them as safe. Applications that must never apply an uncertified command should
inspect `result` and take their own fallback action.
"""

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this is good design

err isa InterruptException && rethrow()
nothing
end
end

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think the logic of the comment doesn't match the code. You are swallowing up all errors except for interrupt exceptions (which is how julia handles ^C and pkill)

particular — but not for the horizontal axes of a quadrotor, where this error is still
raised. The remaining remedies are a reference governor, filtering the commanded
acceleration of a differentially flat parameterization, or a higher-order barrier.
"""

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we have a solution for this that allows quadrotors? or can we do quadrotors with the braking barrier as long as we don't try to impose constraints on the angular components?

B = vcat(zeros(n, n), Matrix{Float64}(I, n, n))
eye = Matrix{Float64}(I, 2n, 2n)
return ControlAffineModel(x -> A * x, x -> B, eye[1:n, :], eye[(n + 1):(2n), :])
end

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This definitely needs another method where you specify the nonzero blocks of A and B. and the symplectic structure gets padded on there for you. This is the free double integrator on n position variables. There are no constraints on the motion, except that they be written in Darboux coordinates for R^2n.

It should create another subtype of AbstractControlAffine <: AbstractAgentDynamics.

We should have SingleIntegrator <: AbstractControlAffine and DoubleIntegrator <: AbstractControlAffine and AbstractControlAffine <: AbstractAgentDynamics

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.

2 participants