-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding CBF and bump a new version (#19)
* Adding CBF and bump a new version * Fix a minor bug * wip
- Loading branch information
Showing
7 changed files
with
78 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,21 @@ | ||
name = "FSimZoo" | ||
uuid = "e2d5807d-1594-43f7-91a6-54c6eef5a9d2" | ||
authors = ["JinraeKim <[email protected]> and contributors"] | ||
version = "0.5.1" | ||
version = "0.6.0" | ||
|
||
[deps] | ||
ComponentArrays = "b0b7db55-cfe3-40fc-9ded-d10e2dbeff66" | ||
Convex = "f65535da-76fb-5f13-bab9-19810c17039a" | ||
ECOS = "e2685f51-7e38-5353-a97d-a921fd2c8199" | ||
FSimBase = "731e945d-f3ed-49a1-bee2-3998705ef155" | ||
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210" | ||
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" | ||
MatrixEquations = "99c1a7ee-ab34-5fd5-8076-27c950a045f4" | ||
|
||
[compat] | ||
ComponentArrays = "0.13" | ||
Convex = "0.15" | ||
ECOS = "1.1" | ||
FSimBase = "0.2" | ||
ForwardDiff = "0.10" | ||
MatrixEquations = "2.1" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
struct InputAffinePositionCBF <: AbstractEnv | ||
f | ||
g | ||
h | ||
α1 | ||
α2 | ||
end | ||
|
||
|
||
""" | ||
p in R^3 | ||
v in R^3 | ||
u: Convex.Variable(m) | ||
""" | ||
function generate_constraint(cbf::InputAffinePositionCBF, p, v, u) | ||
(; f, g, h, α1, α2) = cbf | ||
∇h = p -> ForwardDiff.gradient(h, p) | ||
h1 = (p, v) -> ∇h(p)' * v + α1(h(p)) | ||
∇h1_p = (p, v) -> ForwardDiff.gradient(p -> h1(p, v), p) | ||
∇h1_v = (p, v) -> ForwardDiff.gradient(v -> h1(p, v), v) | ||
h2 = (p, v) -> ∇h1_p(p, v)' * v + ∇h1_v(p, v)' * (f(p, v)+g(p, v)*u) + α2(h1(p, v)) | ||
constraint = h2(p, v) >= 0.0 | ||
end | ||
|
||
|
||
""" | ||
p in R^3 | ||
v in R^3 | ||
u_nom: nominal control input, in R^m | ||
""" | ||
function Command( | ||
cbf::InputAffinePositionCBF, u, p, v, u_nom, constraints; | ||
solver=ECOS.Optimizer, silent_solver=true, | ||
) | ||
cbf_constraint = generate_constraint(cbf, p, v, u) | ||
constraints = [constraints..., cbf_constraint] | ||
problem = minimize(sumsquares(u - u_nom), constraints) | ||
solve!(problem, solver; silent_solver=silent_solver) | ||
return reshape(u.value, size(u_nom)...) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using Test | ||
using FSimZoo | ||
using FSimBase | ||
using LinearAlgebra | ||
using Convex | ||
|
||
|
||
function test_InputAffinePositionCBF() | ||
f = (p, v) -> zeros(3) + [0, 0, 9.81] | ||
g = (p, v) -> I(3) | ||
h = p -> -p[3] - (-0.1) # >= 0 | ||
α1 = x -> 5*x | ||
α2 = x -> 5*x | ||
cbf = InputAffinePositionCBF(f, g, h, α1, α2) | ||
# filter | ||
p = zeros(3) | ||
v = zeros(3) | ||
u_nom = zeros(3) | ||
u = Convex.Variable(length(u_nom)) | ||
u = Command(cbf, u, p, v, u_nom, []) | ||
end | ||
|
||
|
||
@testset "cbf" begin | ||
test_InputAffinePositionCBF() | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9c33e00
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register()
9c33e00
There was a problem hiding this comment.
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/82682
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: