Skip to content

Commit

Permalink
Merge pull request #124 from NavAbility/main
Browse files Browse the repository at this point in the history
v 0.4.5-rc1
  • Loading branch information
dehann authored May 11, 2022
2 parents 5bc9a73 + 418e153 commit c09e92a
Show file tree
Hide file tree
Showing 12 changed files with 602 additions and 33 deletions.
6 changes: 5 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ 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"
Diana = "070d9d8b-17a7-5814-83fa-42438ba5c6e0"
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Expand All @@ -17,6 +19,8 @@ UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
[compat]
Diana = "0.2"
DocStringExtensions = "0.8"
Downloads = "1"
HTTP = "0.9"
JSON = "0.21"
julia = "1.6"

Expand Down
9 changes: 9 additions & 0 deletions src/NavAbilitySDK.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
module NavAbilitySDK

const NVA = NavAbilitySDK
export NVA

# Global imports
using DocStringExtensions
using LinearAlgebra
using JSON
using UUIDs
using Downloads
using HTTP

# for overloading with visualization helpers
import Base: show
Expand All @@ -18,6 +23,7 @@ export uuid4
include("./navability/graphql/Factor.jl")
include("./navability/graphql/Status.jl")
include("./navability/graphql/Variable.jl")
include("./navability/graphql/DataBlobs.jl")

include("./navability/graphql/QueriesDeprecated.jl")
export QUERY_VARIABLE_LABELS
Expand Down Expand Up @@ -53,6 +59,8 @@ include("./navability/services/Factor.jl")
include("./navability/services/Solve.jl")
include("./navability/services/Status.jl")
include("./navability/services/Utils.jl")
include("./navability/services/StandardAPI.jl")
include("./navability/services/DataBlobs.jl")
export getVariable, getVariables, listVariables, ls
export addVariable, addPackedVariable
export getFactor, getFactors, listFactors, lsf
Expand All @@ -62,4 +70,5 @@ export getStatusMessages, getStatusLatest, getStatusesLatest
export waitForCompletion
export GraphVizApp, MapVizApp


end
52 changes: 29 additions & 23 deletions src/navability/entities/Factor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ Create a prior factor for a ContinuousScalar (a.k.a. Pose1) with a distribution
Default value of Z = `Normal(0.0, 0.1)`.
"""
function PriorData(;Z::Distribution = Normal(0.0, 0.1))::FactorData
data = FactorData(fnc = ZInferenceType(Z), certainhypo = [1])
function PriorData(;Z::Distribution = Normal(0.0, 0.1), kwargs...)::FactorData
data = FactorData(;fnc = ZInferenceType(Z), certainhypo = [1], kwargs...)
return data
end

Expand All @@ -52,8 +52,8 @@ Create a prior factor for a Pose2 with a distribution Z representing (x,y,theta)
Default value of Z = `FullNormal([0.0, 0.0, 0.0], diagm([0.01, 0.01, 0.01]))`.
"""
function PriorPose2Data(;Z::Distribution = FullNormal([0.0, 0.0, 0.0], diagm([0.01, 0.01, 0.01])))::FactorData
data = FactorData(fnc = ZInferenceType(Z), certainhypo = [1])
function PriorPose2Data(;Z::Distribution = FullNormal([0.0, 0.0, 0.0], diagm([0.01, 0.01, 0.01])), kwargs...)::FactorData
data = FactorData(;fnc = ZInferenceType(Z), certainhypo = [1], kwargs...)
return data
end

Expand All @@ -64,8 +64,8 @@ Create a prior factor for a Point2 with a distribution Z representing (x,y) prio
Default value of Z = `FullNormal([0.0, 0.0], diagm([0.01, 0.01]))`.
"""
function PriorPoint2Data(;Z::Distribution = FullNormal([0.0, 0.0], diagm([0.01, 0.01])))::FactorData
data = FactorData(fnc = ZInferenceType(Z), certainhypo = [1])
function PriorPoint2Data(;Z::Distribution = FullNormal([0.0, 0.0], diagm([0.01, 0.01])), kwargs...)::FactorData
data = FactorData(;fnc = ZInferenceType(Z), certainhypo = [1], kwargs...)
return data
end

Expand All @@ -76,8 +76,8 @@ between the variables, e.g. `Normal(1.0, 0.1)`.
Default value of Z = `Normal(1.0, 0.1)`.
"""
function LinearRelativeData(;Z::Distribution = Normal(1.0, 0.1))::FactorData
data = FactorData(fnc = ZInferenceType(Z), certainhypo = [1, 2])
function LinearRelativeData(;Z::Distribution = Normal(1.0, 0.1), kwargs...)::FactorData
data = FactorData(;fnc = ZInferenceType(Z), certainhypo = [1, 2], kwargs...)
return data
end

Expand All @@ -88,8 +88,8 @@ between the variables, e.g. `FullNormal([1,0,0.3333*π], diagm([0.01,0.01,0.01])
Default value of Z = `FullNormal([1,0,0.3333*π], diagm([0.01,0.01,0.01]))`.
"""
function Pose2Pose2Data(;Z::Distribution = FullNormal([1,0,0.3333*π], diagm([0.01, 0.01, 0.01])))::FactorData
data = FactorData(fnc = ZInferenceType(Z), certainhypo = [1, 2])
function Pose2Pose2Data(;Z::Distribution = FullNormal([1,0,0.3333*π], diagm([0.01, 0.01, 0.01])), kwargs...)::FactorData
data = FactorData(;fnc = ZInferenceType(Z), certainhypo = [1, 2], kwargs...)
return data
end

Expand All @@ -99,8 +99,8 @@ Create a Pose2->Point2 bearing+range factor with 1D distributions:
- bearing: The bearing from the pose to the point, default `Normal(0, 1)`.
- range: The range from the pose to the point, default `Normal(1, 1)`.
"""
function Pose2Point2BearingRangeData(;bearing::Distribution = Normal(0, 1), range::Distribution = Normal(1, 1))::FactorData
data = FactorData(fnc = Pose2Point2BearingRangeInferenceType(bearing, range), certainhypo = [1, 2])
function Pose2Point2BearingRangeData(;bearing::Distribution = Normal(0, 1), range::Distribution = Normal(1, 1), kwargs...)::FactorData
data = FactorData(;fnc = Pose2Point2BearingRangeInferenceType(bearing, range), certainhypo = [1, 2], kwargs...)
return data
end

Expand All @@ -109,8 +109,8 @@ $(SIGNATURES)
Create a Point2->Point2 range factor with a 1D distribution:
- range: The range from the pose to the point, default `Normal(1, 1)`.
"""
function Point2Point2RangeData(;range::Distribution = Normal(1, 1))::FactorData
data = FactorData(fnc = ZInferenceType(range), certainhypo = [1, 2])
function Point2Point2RangeData(;range::Distribution = Normal(1, 1), kwargs...)::FactorData
data = FactorData(;fnc = ZInferenceType(range), certainhypo = [1, 2], kwargs...)
return data
end

Expand All @@ -119,9 +119,9 @@ $(SIGNATURES)
Create a AprilTags factor that directly relates a Pose2 to the information from an AprilTag reading.
Corners need to be provided, homography and tag length are defaulted and can be overwritten.
"""
function Pose2AprilTag4CornersData(id, corners::Vector{Float64}, homography::Vector{Float64}; K::Vector{Float64}=[300.0,0.0,0.0,0.0,300.0,0.0,180.0,120.0,1.0], taglength::Float64=0.25)::FactorData
function Pose2AprilTag4CornersData(id, corners::Vector{Float64}, homography::Vector{Float64}; K::Vector{Float64}=[300.0,0.0,0.0,0.0,300.0,0.0,180.0,120.0,1.0], taglength::Float64=0.25, kwargs...)::FactorData
fnc = Pose2AprilTag4CornersInferenceType(;corners,homography,K,taglength,id)
data = FactorData(fnc = fnc, certainhypo = [1, 2])
data = FactorData(; fnc, certainhypo = [1, 2], kwargs...)
return data
end

Expand All @@ -138,12 +138,13 @@ function ScatterAlignPose2Data(
bw2::AbstractVector{<:Real}=Float64[];
mkd1 = ManifoldKernelDensity(; varType, pts=cloud1, bw=bw1 ),
mkd2 = ManifoldKernelDensity(; varType, pts=cloud2, bw=bw2 ),
kw_sap...
kw_sap::NamedTuple=(;),
kwargs...
)
#

fnc = ScatterAlignPose2InferenceType(; cloud1=mkd1, cloud2=mkd2, kw_sap...)
data = FactorData(fnc = fnc, certainhypo = [1, 2])
data = FactorData(; fnc, certainhypo = [1, 2], kwargs...)
return data
end

Expand All @@ -170,7 +171,7 @@ function MixtureData(
probabilities::Vector{Float64},
dims::Integer # TODO: Confirming we can remove.
)::FactorData #where T<:FactorData
data = FactorData(
data = FactorData(;
fnc = MixtureInferenceType(
N = length(components),
# @jim-hill-r this is why I don't like the Data suffix.
Expand All @@ -183,21 +184,26 @@ function MixtureData(
return data
end


function Factor(
label::String,
fncType::String,
variableOrderSymbols::Vector{String},
data::FactorData;
tags::Vector{String}=["FACTOR"],
timestamp::String = string(now(Dates.UTC))*"Z",
multihypo=Float64[],
nullhypo::Real=0
multihypo=nothing,
nullhypo=nothing
)::Factor
#
# TODO: Remove independent updates of this and set certainhypo here.
data.certainhypo = Vector{Int}(1:size(variableOrderSymbols)[1])
data.multihypo = multihypo
data.nullhypo = float(nullhypo)
if multihypo !== nothing
data.multihypo = multihypo
end
if nullhypo !== nothing
data.nullhypo = float(nullhypo)
end

result = Factor(
label,
Expand Down
28 changes: 25 additions & 3 deletions src/navability/entities/InferenceTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,23 @@ functions inside of factors.
"""
abstract type InferenceType end

macro nvaZInferenceType(inferencetype)
return esc(quote
Base.@__doc__ struct $inferencetype <: NVA.InferenceType
Z::Distribution
end
$inferencetype(;Z) = $inferencetype(Z)
end)
end

@nvaZInferenceType Prior
@nvaZInferenceType LinearRelative
@nvaZInferenceType PriorPose2
@nvaZInferenceType Pose2Pose2
@nvaZInferenceType PriorPoint2
@nvaZInferenceType Point2Point2
@nvaZInferenceType Point2Point2Range

"""
$(TYPEDEF)
ZInferenceType is used by many factors as a common inference
Expand All @@ -25,16 +42,18 @@ $(TYPEDEF)
Pose2Point2BearingRangeInferenceType is used to represent a bearing
+ range measurement.
"""
Base.@kwdef struct Pose2Point2BearingRangeInferenceType <: InferenceType
Base.@kwdef struct Pose2Point2BearingRange <: InferenceType
bearstr::Distribution
rangstr::Distribution
end

const Pose2Point2BearingRangeInferenceType = Pose2Point2BearingRange

"""
$(TYPEDEF)
InferenceType for Pose2AprilTag4CornersData.
"""
Base.@kwdef struct Pose2AprilTag4CornersInferenceType <: InferenceType
Base.@kwdef struct Pose2AprilTag4Corners <: InferenceType
corners::Vector{Float64}
homography::Vector{Float64}
K::Vector{Float64}
Expand All @@ -43,8 +62,9 @@ Base.@kwdef struct Pose2AprilTag4CornersInferenceType <: InferenceType
_type::String = "/application/JuliaLang/PackedPose2AprilTag4Corners"
end

const Pose2AprilTag4CornersInferenceType = Pose2AprilTag4Corners

Base.@kwdef struct ScatterAlignPose2InferenceType <: InferenceType
Base.@kwdef struct ScatterAlignPose2 <: InferenceType
""" This SDK only supports MKD clouds at this time. Note CJL also supports HeatmapGridDensity, TODO """
cloud1::ManifoldKernelDensity
cloud2::ManifoldKernelDensity
Expand All @@ -67,6 +87,8 @@ Base.@kwdef struct ScatterAlignPose2InferenceType <: InferenceType
_type::String = "Caesar.PackedScatterAlignPose2"
end

const ScatterAlignPose2InferenceType = ScatterAlignPose2

"""
$(TYPEDEF)
InferenceType for MixtureData.
Expand Down
23 changes: 21 additions & 2 deletions src/navability/entities/NavAbilityClient.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,31 @@ struct NavAbilityClient
mutate::Function
end

function NavAbilityWebsocketClient(apiUrl::String="wss://api.navability.io/graphql")::NavAbilityClient
function NavAbilityWebsocketClient( apiUrl::String="wss://api.navability.io/graphql")::NavAbilityClient
throw("Not implemented")
end

function NavAbilityHttpsClient(apiUrl::String="https://api.navability.io")::NavAbilityClient
function NavAbilityHttpsClient(
apiUrl::String="https://api.navability.io";
authorize::Bool=false
)::NavAbilityClient
#
dianaClient = GraphQLClient(apiUrl)

# auth
if authorize
# FIXME, use Base.getpass instead of readline once VSCode supports getpass.
# st = Base.getpass("Copy-paste auth token")
# seekstart(st)
# tok = read(st, String)
# Base.shred!(st)
println(" > VSCode ONLY WORKAROUND, input issue, see https://github.com/julia-vscode/julia-vscode/issues/785")
println(" > Workaround: first press 0 then enter, and then paste the token and hit enter a second time.")
println("Copy-paste auth token: ")
tok = readline(stdin)
dianaClient.serverAuth("Bearer "*tok)
end

function query(options::QueryOptions)
# NOTE, the query client library used is synchronous, locally converted to async for package consistency
@async dianaClient.Query(options.query, operationName=options.name, vars=options.variables)
Expand Down
4 changes: 3 additions & 1 deletion src/navability/entities/Variable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ _variableTypeConvert = Dict{Symbol, String}(
:Point2 => "RoME.Point2",
:Pose2 => "RoME.Pose2",
:ContinuousScalar => "IncrementalInference.ContinuousScalar",
# TBD - https://github.com/JuliaRobotics/Caesar.jl/discussions/810
# TBD - https://github.com/JuliaRobotics/Caesar.jl/discussions/807
:Position1 => "IncrementalInference.ContinuousScalar",
#TODO deprecate
:Pose1 => "IncrementalInference.ContinuousScalar"
)

Expand Down
Loading

0 comments on commit c09e92a

Please sign in to comment.