-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #114 from NavAbility/22Q2/api/iif_api
Standard addVariable and addFactor API POC
- Loading branch information
Showing
8 changed files
with
204 additions
and
29 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 |
---|---|---|
|
@@ -3,7 +3,7 @@ uuid = "f3e6a059-199c-4ada-8143-fcefb97e6165" | |
keywords = ["navability", "navigation", "slam", "sdk", "robotics", "robots"] | ||
desc = "NavAbility SDK: Access NavAbility Cloud factor graph features. Note that this SDK and the related API are still in development. Please let us know if you have any issues at [email protected]." | ||
authors = ["NavAbility <[email protected]>"] | ||
version = "0.4.4" | ||
version = "0.4.5" | ||
|
||
[deps] | ||
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" | ||
|
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
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,103 @@ | ||
## Wrap to standard API spec | ||
|
||
# Leaving as comment for future plans, see https://github.com/NavAbility/nva-sdk/issues/21 | ||
# TODO What to use: | ||
# - NavAbilityPlatform | ||
# - NavAbilityConnection | ||
# - NavAbilityClientContext | ||
# - | ||
# mutable struct NavAbilityPlatform{T} | ||
# client | ||
# context::T | ||
# end | ||
|
||
# function NavAbilityPlatform(; | ||
# apiUrl::AbstractString="https://api.navability.io", | ||
# UserId::AbstractString="[email protected]", | ||
# RobotId::AbstractString=ENV["USER"], | ||
# SessionId::AbstractString="Session_" * string(uuid4())[1:8]) | ||
# # | ||
# client = NavAbilityHttpsClient(apiUrl) | ||
# context = Client(UserId, RobotId, SessionId) | ||
# return NavAbilityPlatform(client, context) | ||
# end | ||
|
||
""" | ||
addVariable | ||
Add a variable to the NavAbility Platform service | ||
Example | ||
```julia | ||
addVariable(client, context, "x0", NVA.Pose2) | ||
``` | ||
""" | ||
function addVariable(client, | ||
context, | ||
label::Union{<:AbstractString,Symbol}, | ||
varType::Union{<:AbstractString,Symbol}; | ||
tags::Vector{String}=String[], | ||
timestamp::String = string(now(Dates.UTC))*"Z") | ||
# TODO | ||
# solvable::Int=1 | ||
# nanosecondtime, | ||
# smalldata, | ||
# | ||
union!(tags, ["VARIABLE"]) | ||
v = Variable(string(label), Symbol(varType), tags, timestamp) | ||
return addVariable(client, context, v) | ||
end | ||
|
||
|
||
function assembleFactorName(xisyms::Union{Vector{String},Vector{Symbol}}) | ||
return string(xisyms...,"f_",string(uuid4())[1:4]) | ||
end | ||
|
||
function getFncTypeName(fnc::InferenceType) | ||
return split(string(typeof(fnc)),".")[end] | ||
end | ||
|
||
|
||
#TODO solverParams | ||
|
||
function addFactor(client, | ||
context, | ||
xisyms::Union{Vector{String},Vector{Symbol}}, | ||
fnc::InferenceType; | ||
multihypo::Vector{Float64}=Float64[], | ||
nullhypo::Float64=0.0, | ||
solvable::Int=1, | ||
tags::Vector{String}=String[], | ||
# timestamp::Union{DateTime,ZonedDateTime}=now(localzone()), #TODO why timestamp difference from IIF | ||
timestamp::String = string(now(Dates.UTC))*"Z", | ||
inflation::Real=3.0, | ||
namestring::String = assembleFactorName(xisyms), | ||
nstime::String="0" | ||
) | ||
# TODO maybe | ||
# graphinit::Bool=true, | ||
# threadmodel=SingleThreaded, | ||
# suppressChecks::Bool=false, | ||
# _blockRecursion::Bool=!getSolverParams(dfg).attemptGradients | ||
# | ||
# create factor data | ||
factordata = FactorData(;fnc, multihypo, nullhypo, inflation) | ||
|
||
fncType = getFncTypeName(fnc) | ||
|
||
union!(tags, ["FACTOR"]) | ||
# create factor | ||
factor = Factor( | ||
namestring, | ||
nstime, | ||
fncType, | ||
string.(xisyms), | ||
factordata, | ||
solvable, | ||
tags, | ||
timestamp, | ||
DFG_VERSION | ||
) | ||
# add factor | ||
resultId = addFactor(client, context, factor) | ||
|
||
return resultId | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
apiUrl = get(ENV,"API_URL","https://api.navability.io") | ||
userId = get(ENV,"USER_ID","[email protected]") | ||
robotId = get(ENV,"ROBOT_ID","IntegrationRobot") | ||
sessionId = get(ENV,"SESSION_ID","TestSession_"*string(uuid4())[1:8]) | ||
|
||
@testset "nva-sdk-standard-api-testset" begin | ||
|
||
client = NavAbilityHttpsClient(apiUrl) | ||
context = Client(userId,robotId,sessionId) | ||
|
||
addVariable(client, context, "x0", :Pose2) | ||
addFactor(client, context, ["x0"], NVA.PriorPose2(Z=FullNormal([0.,1.,0], diagm([1.,1,1])))) | ||
|
||
addVariable(client, context, :x1, :Pose2) | ||
addFactor(client, context, [:x0,:x1], NVA.Pose2Pose2(Z=FullNormal([1.,0.,0], diagm([1.,1,1])))) | ||
|
||
addFactor(client, context, [:x1], NVA.PriorPose2(Z=FullNormal([1.,0.,0], diagm([1.,1,1]))); nullhypo=0.1) | ||
|
||
addFactor(client, context, ["x0"], NVA.PriorPose2(Z=FullNormal([0.5,0.5,0], diagm([1.,1,1])))) | ||
|
||
addVariable(client, context, :x2_a, :Pose2) | ||
addVariable(client, context, :x2_b, :Pose2) | ||
addFactor(client, context, ["x1", "x2_a", "x2_b"], NVA.PriorPose2(Z=FullNormal([0.5,0.5,0], diagm([1.,1,1]))); multihypo=[1,0.1,0.9]) | ||
|
||
addVariable(client, context, "y0", :Position1) | ||
addFactor(client, context, ["y0"], NVA.Prior(Z=Normal(0.0, 1.0))) | ||
|
||
|
||
addVariable(client, context, "z0", :Point2) | ||
addFactor(client, context, ["z0"], NVA.PriorPoint2(Z=FullNormal([1.,0.], diagm([1.,1])))) | ||
|
||
addVariable(client, context, "z1", :Point2) | ||
addFactor(client, context, ["z0", "z1"], NVA.Point2Point2(Z=FullNormal([1.,0.], diagm([1.,1])))) | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
include("./unit/runtests.jl") | ||
include("./integration/runtests.jl") | ||
include("./integration/runtests.jl") | ||
|
||
#TODO I'm not familiar with the tests yet, so just dumping it here to get us started. | ||
include("./integration/testStandardAPI.jl") |