Skip to content

Commit 3d91fbb

Browse files
committed
further fixes cleanup DERelative for imu
1 parent e1d3af6 commit 3d91fbb

File tree

1 file changed

+42
-41
lines changed

1 file changed

+42
-41
lines changed

ext/IncrInfrDiffEqFactorExt.jl

Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,25 @@ import Manifolds: allocate, compose, hat, Identity, vee, log
2222

2323
getManifold(de::DERelative{T}) where {T} = getManifold(de.domain)
2424

25+
26+
function Base.show(
27+
io::IO,
28+
::Union{<:DERelative{T,O},Type{<:DERelative{T,O}}}
29+
) where {T,O}
30+
println(io, " DERelative{")
31+
println(io, " ", T)
32+
println(io, " ", O.name.name)
33+
println(io, " }")
34+
nothing
35+
end
36+
37+
Base.show(
38+
io::IO,
39+
::MIME"text/plain",
40+
der::DERelative
41+
) = show(io, der)
42+
43+
2544
"""
2645
$SIGNATURES
2746
@@ -31,7 +50,9 @@ DevNotes
3150
- TODO does not yet incorporate Xi.nanosecond field.
3251
- TODO does not handle timezone crossing properly yet.
3352
"""
34-
function _calcTimespan(Xi::AbstractVector{<:DFGVariable})
53+
function _calcTimespan(
54+
Xi::AbstractVector{<:DFGVariable}
55+
)
3556
#
3657
tsmps = getTimestamp.(Xi[1:2]) .|> DateTime .|> datetime2unix
3758
# toffs = (tsmps .- tsmps[1]) .|> x-> elemType(x.value*1e-3)
@@ -50,8 +71,8 @@ function DERelative(
5071
f::Function,
5172
data = () -> ();
5273
dt::Real = 1,
53-
state0::AbstractVector{<:Real} = zeros(getDimension(domain)),
54-
state1::AbstractVector{<:Real} = zeros(getDimension(domain)),
74+
state0::AbstractVector{<:Real} = allocate(getPointIdentity(domain)), # zeros(getDimension(domain)),
75+
state1::AbstractVector{<:Real} = allocate(getPointIdentity(domain)), # zeros(getDimension(domain)),
5576
tspan::Tuple{<:Real, <:Real} = _calcTimespan(Xi),
5677
problemType = DiscreteProblem,
5778
)
@@ -78,8 +99,8 @@ function DERelative(
7899
data = () -> ();
79100
Xi::AbstractArray{<:DFGVariable} = getVariable.(dfg, labels),
80101
dt::Real = 1,
81-
state0::AbstractVector{<:Real} = zeros(getDimension(domain)),
82-
state1::AbstractVector{<:Real} = zeros(getDimension(domain)),
102+
state1::AbstractVector{<:Real} = allocate(getPointIdentity(domain)), #zeros(getDimension(domain)),
103+
state0::AbstractVector{<:Real} = allocate(getPointIdentity(domain)), #zeros(getDimension(domain)),
83104
tspan::Tuple{<:Real, <:Real} = _calcTimespan(Xi),
84105
problemType = DiscreteProblem,
85106
)
@@ -99,7 +120,12 @@ end
99120
#
100121

101122
# n-ary factor: Xtra splat are variable points (X3::Matrix, X4::Matrix,...)
102-
function _solveFactorODE!(measArr, prob, u0pts, Xtra...)
123+
function _solveFactorODE!(
124+
measArr,
125+
prob,
126+
u0pts,
127+
Xtra...
128+
)
103129
# happens when more variables (n-ary) must be included in DE solve
104130
for (xid, xtra) in enumerate(Xtra)
105131
# update the data register before ODE solver calls the function
@@ -159,22 +185,21 @@ end
159185

160186

161187
# NOTE see #1025, CalcFactor should fix `multihypo=` in `cf.__` fields; OBSOLETE
162-
function (cf::CalcFactor{<:DERelative})(measurement, X...)
188+
function (cf::CalcFactor{<:DERelative})(
189+
measurement,
190+
X...
191+
)
163192
#
193+
# numerical measurement values
164194
meas1 = measurement[1]
195+
# work on-manifold via sampleFactor piggy back of particular manifold definition
165196
M = measurement[2]
166-
# diffOp = measurement[2]
167-
197+
# lazy factor pointer
168198
oderel = cf.factor
169-
170-
# work on-manifold
171-
# diffOp = meas[2]
172-
# if backwardSolve else forward
173-
174199
# check direction
175-
176200
solveforIdx = cf.solvefor
177-
201+
202+
# if backwardSolve else forward
178203
if solveforIdx > 2
179204
# need to recalculate new ODE (forward) for change in parameters (solving for 3rd or higher variable)
180205
solveforIdx = 2
@@ -190,19 +215,10 @@ function (cf::CalcFactor{<:DERelative})(measurement, X...)
190215
end
191216

192217
# find the difference between measured and predicted.
193-
## assuming the ODE integrated from current X1 through to predicted X2 (ie `meas1[:,idx]`)
194-
## FIXME, obviously this is not going to work for more compilcated groups/manifolds -- must fix this soon!
195-
# @show cf._sampleIdx, solveforIdx, meas1
196-
218+
# assuming the ODE integrated from current X1 through to predicted X2 (ie `meas1[:,idx]`)
197219
res_ = compose(M, inv(M, X[solveforIdx]), meas1)
198220
res = vee(M, Identity(M), log(M, Identity(M), res_))
199221

200-
# #FIXME 0
201-
# res = zeros(size(X[2], 1))
202-
# for i = 1:size(X[2], 1)
203-
# # diffop( reference?, test? ) <===> ΔX = test \ reference
204-
# res[i] = diffOp[i](X[solveforIdx][i], meas1[i])
205-
# end
206222
return res
207223
end
208224

@@ -300,19 +316,4 @@ end
300316

301317

302318

303-
function Base.show(io::IO, ::Union{<:DERelative{T,O},Type{<:DERelative{T,O}}}) where {T,O}
304-
println(io, " DERelative{")
305-
println(io, " ", T)
306-
println(io, " ", O.name.name)
307-
println(io, " }")
308-
nothing
309-
end
310-
311-
Base.show(io::IO, ::MIME"text/plain", der::DERelative) = show(io, der)
312-
313-
## the function
314-
# ode.problem.f.f
315-
316-
#
317-
318319
end # module

0 commit comments

Comments
 (0)