Skip to content

Commit 421ecff

Browse files
authored
Merge pull request #879 from JuliaRobotics/22Q3/enh/SAP3
better standz. ScatterAlign as PosePose residual (Pose3)
2 parents e4f29a1 + ebb79ed commit 421ecff

3 files changed

Lines changed: 66 additions & 41 deletions

File tree

Project.toml

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name = "Caesar"
22
uuid = "62eebf14-49bc-5f46-9df9-f7b7ef379406"
33
keywords = ["SLAM", "state-estimation", "MM-iSAM", "MM-iSAMv2", "inference", "robotics", "ROS"]
44
desc = "Non-Gaussian simultaneous localization and mapping"
5-
version = "0.13.1"
5+
version = "0.13.2"
66

77
[deps]
88
ApproxManifoldProducts = "9bbbb610-88a1-53cd-9763-118ce10c1f89"
@@ -44,35 +44,35 @@ Unmarshal = "cbff2730-442d-58d7-89d1-8e530c41eb02"
4444
YAML = "ddb6d928-2868-570f-bddf-ab3f9cf99eb6"
4545

4646
[compat]
47-
ApproxManifoldProducts = "0.4.21, 0.5, 0.6"
47+
ApproxManifoldProducts = "0.6"
4848
AprilTags = "0.8, 0.9"
49-
Combinatorics = "0.7, 0.8, 0.9, 1"
49+
Combinatorics = "1"
5050
CoordinateTransformations = "0.5, 0.6"
51-
DataStructures = "0.16, 0.17, 0.18"
52-
DistributedFactorGraphs = "0.17, 0.18"
53-
Distributions = "0.22, 0.23, 0.24, 0.25"
54-
DocStringExtensions = "0.7, 0.8, 0.9"
51+
DataStructures = "0.17, 0.18"
52+
DistributedFactorGraphs = "0.18"
53+
Distributions = "0.25"
54+
DocStringExtensions = "0.8, 0.9"
5555
FFTW = "1"
5656
FileIO = "1"
57-
ImageCore = "0.7, 0.8, 0.9"
58-
ImageMagick = "0.7, 1.0, 1.1"
59-
IncrementalInference = "0.26, 0.27, 0.28, 0.29, 0.30"
57+
ImageCore = "0.8, 0.9"
58+
ImageMagick = "1"
59+
IncrementalInference = "0.30"
6060
JLD2 = "0.3, 0.4"
61-
JSON = "0.19, 0.20, 0.21"
61+
JSON = "0.20, 0.21"
6262
JSON2 = "0.3, 0.4"
6363
KernelDensityEstimate = "0.5"
64-
Manifolds = "0.6.3, 0.7, 0.8"
65-
NLsolve = "3, 4"
64+
Manifolds = "0.8"
65+
NLsolve = "4"
6666
Optim = "1"
67-
ProgressMeter = "0.9, 1"
68-
Reexport = "0.2, 1"
69-
Requires = "0.5, 1"
70-
RoME = "0.17, 0.18, 0.19, 0.20"
67+
ProgressMeter = "1"
68+
Reexport = "1"
69+
Requires = "1"
70+
RoME = "0.20"
7171
Rotations = "1.1"
7272
StaticArrays = "1"
73-
TensorCast = "0.3, 0.4"
73+
TensorCast = "0.4"
7474
TimeZones = "1.3.1, 1.4"
75-
TransformUtils = "0.2.2"
75+
TransformUtils = "0.2.14"
7676
Unmarshal = "0.3, 0.4"
7777
YAML = "0.3, 0.4"
7878
julia = "1.6"

src/images/ScatterAlignPose2.jl

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ struct ScatterAlignPose3 <: IIF.AbstractManifoldMinimize
6464
align::ScatterAlign{Pose3,<:Any,<:Any}
6565
end
6666

67+
_getPoseType(::ScatterAlign{P}) where P = P
6768

6869
# replace inner constructor with transform on image
6970
function ScatterAlignPose2(im1::AbstractMatrix{T},
@@ -156,9 +157,8 @@ getManifold(::IIF.InstanceType{<:ScatterAlignPose3}) = getManifold(Pose3Pose3)
156157
# runs once upon addFactor! and returns object later used as `cache`
157158
function preambleCache(dfg::AbstractDFG, vars::AbstractVector{<:DFGVariable}, fnc::Union{<:ScatterAlignPose2,<:ScatterAlignPose3})
158159
#
159-
_getPoseType(sa::ScatterAlign{P}) where P = P
160160
M = getManifold(_getPoseType(fnc.align))
161-
e0 = getPointIdentity(M) # ArrayPartition(SVector(0.0,0.0), SMatrix{2,2}(1.0, 0.0, 0.0, 1.0))
161+
e0 = getPointIdentity(M)
162162

163163
# reconstitute cloud belief from dataEntry
164164
for (va,de,cl) in zip(vars,[fnc.align.dataEntry_cloud1,fnc.align.dataEntry_cloud2],[fnc.align.cloud1,fnc.align.cloud2])
@@ -182,10 +182,12 @@ function preambleCache(dfg::AbstractDFG, vars::AbstractVector{<:DFGVariable}, fn
182182
end
183183

184184

185-
function getSample( cf::CalcFactor{<:ScatterAlignPose2} )
185+
function getSample( cf::CalcFactor{S} ) where {S <: Union{<:ScatterAlignPose2,<:ScatterAlignPose3}}
186186
#
187187
M = cf.cache.M
188188
e0 = cf.cache.e0
189+
ntr = length(Manifolds.submanifold_component(e0,1))
190+
nrt = Manifolds.manifold_dimension(M)-ntr
189191
# R0 = submanifold_component(e0,2)
190192

191193
pVi = cf.cache.smps1
@@ -203,7 +205,7 @@ function getSample( cf::CalcFactor{<:ScatterAlignPose2} )
203205
cost(xyr) = mmd(M.manifold[1], pVi, pVj(xyr), length(pVi), length(qVj), cf._allowThreads; cf.cache.bw)
204206

205207
# return mmd as residual for minimization
206-
res = Optim.optimize(cost, [5*randn(2); 0.1*randn()], Optim.BFGS() )
208+
res = Optim.optimize(cost, [5*randn(ntr); 0.1*randn(nrt)], Optim.BFGS() )
207209

208210
cf.cache.score[] = res.minimum
209211

@@ -213,20 +215,29 @@ function getSample( cf::CalcFactor{<:ScatterAlignPose2} )
213215
end
214216

215217

216-
function (cf::CalcFactor{<:ScatterAlignPose2})(pXq, wPp, wPq)
218+
function (cf::CalcFactor{S})(X, p, q
219+
) where {S <: Union{<:ScatterAlignPose2,<:ScatterAlignPose3}}
217220
#
218221

219222
M = cf.cache.M
220-
e0 = cf.cache.e0
221-
222-
# get the current relative transform estimate
223-
wPq_ = Manifolds.compose(M, wPp, exp(M, e0, pXq))
224-
225-
#TODO allocalte for vee! see Manifolds #412, fix for AD
226-
Xc = zeros(3)
227-
vee!(M, Xc, wPq, log(M, wPq, wPq_))
223+
ϵ0 = cf.cache.e0
228224

225+
# copied from Pose2Pose2
226+
= allocate(q)
227+
exp!(M, q̂, ϵ0, X)
228+
Manifolds.compose!(M, q̂, p, q̂)
229+
Xc = vee(M, q, log!(M, q̂, q, q̂))
229230
return Xc
231+
232+
# pXq,
233+
# wPp,
234+
# wPq
235+
# # get the current relative transform estimate
236+
# wPq_ = Manifolds.compose(M, wPp, exp(M, e0, pXq))
237+
# #TODO allocalte for vee! see Manifolds #412, fix for AD
238+
# Xc = zeros(3)
239+
# vee!(M, Xc, wPq, log(M, wPq, wPq_))
240+
# return Xc
230241
end
231242

232243

test/testScatterAlignPose2.jl

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ println("Starting ScatterAlignPose2 tests...")
1818
@testset "Test ScatterAlignPose2" begin
1919
##
2020

21-
x = -10:0.1:10;
22-
y = -10:0.1:10;
21+
x = -15:0.1:15;
22+
y = -15:0.1:15;
2323

2424
σ = 0.1
2525

@@ -29,7 +29,7 @@ g = (x,y)->pdf(MvNormal([3.;0],Σ),[x;y]) + pdf(MvNormal([8.;0.0],4*Σ),[x;y]) +
2929
bIM1 = zeros(length(x),length(y))
3030
bIM2 = zeros(length(x),length(y))
3131

32-
oT = [2.; 0]
32+
oT = [5.; 0]
3333
= pi/8
3434

3535
M = SpecialEuclidean(2)
@@ -162,9 +162,6 @@ end
162162

163163

164164

165-
166-
167-
168165
@testset "test ScatterAlignPose2 with MKD direct" begin
169166
##
170167

@@ -265,13 +262,13 @@ end
265262

266263

267264

268-
@testset "test ScatterAlignPose2 with MKD direct" begin
265+
@testset "test ScatterAlignPose3 with MKD direct" begin
269266
##
270267

271268
# setup
272269

273-
oT = [2.; 0;0]
274-
= [0;0;pi/6]
270+
oT = [2.; 0;2]
271+
= [0;0;pi/10]
275272

276273
M = SpecialEuclidean(3)
277274
e0 = getPointIdentity(M)
@@ -300,8 +297,25 @@ P2 = manikde!(Point3, p2)
300297

301298
sap = ScatterAlignPose3(;cloud1=P1, cloud2=P2, sample_count=100, bw=1.0)
302299

300+
## sample from ScatterAlignPose3
301+
302+
fg = initfg()
303+
getSolverParams(fg).inflateCycles=1
304+
305+
addVariable!(fg, :x0, Pose3)
306+
addVariable!(fg, :x1, Pose3)
307+
308+
addFactor!(fg, [:x0], PriorPose3( MvNormal(Diagonal(map(abs2,0.1*ones(6)))) ))
309+
addFactor!(fg, [:x0;:x1], sap, inflation=0.0)
310+
303311
##
304312

313+
Xsmpl = sampleFactor(fg, :x0x1f1)
314+
315+
@test Xsmpl[1] isa ArrayPartition
316+
@test length(Xsmpl[1]) === 12
317+
318+
##
305319
end
306320

307321

0 commit comments

Comments
 (0)