-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update factors to return residual #397
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,16 +32,9 @@ function IIF.getParametricMeasurement(s::Pose2Point2BearingRange{<:Normal, <:Nor | |
end | ||
|
||
# TODO consolidate with parametric constraint, follow at #467 | ||
function (cfo::CalcFactor{<:Pose2Point2BearingRange})(res::AbstractVector{<:Real}, | ||
meas, | ||
xi, | ||
lm ) | ||
# | ||
# FIXME, consolidate with parametric IIF #467 | ||
|
||
function (cfo::CalcFactor{<:Pose2Point2BearingRange})(meas, xi, lm) | ||
# 1-bearing | ||
# 2-range | ||
|
||
# world frame | ||
θ = meas[1] + xi[3] | ||
mx = meas[2]*cos(θ) | ||
|
@@ -51,57 +44,27 @@ function (cfo::CalcFactor{<:Pose2Point2BearingRange})(res::AbstractVector{<:Real | |
ey = lm[2] - (my + xi[2]) | ||
|
||
# res = [eθ, er] | ||
res[1] = atan((my + xi[2]), (mx + xi[1])) - atan(lm[2], lm[1]) # eθ | ||
res[2] = sqrt(ex^2 + ey^2) # some wasted computation here # er | ||
|
||
# rot = meas[1]+xi[3] | ||
|
||
# res[1] = ( lm[1] - (meas[2]*cos( rot ) + xi[1]) )^2 | ||
# res[2] = ( lm[2] - (meas[2]*sin( rot ) + xi[2]) )^2 | ||
|
||
# res[1] += res[2] | ||
# res[2] = 0.0 | ||
|
||
# return res[1] | ||
|
||
# IIF v0.21+ | ||
nothing | ||
eθ = atan((my + xi[2]), (mx + xi[1])) - atan(lm[2], lm[1]) # eθ | ||
er= sqrt(ex^2 + ey^2) # some wasted computation here # er | ||
|
||
#Old way | ||
# rot = meas[1]+xi[3] | ||
# res[1] = ( lm[1] - (meas[2]*cos( rot ) + xi[1]) )^2 | ||
# res[2] = ( lm[2] - (meas[2]*sin( rot ) + xi[2]) )^2 | ||
# res[1] += res[2] | ||
# res[2] = 0.0 | ||
# return res[1] | ||
|
||
# IIF v0.21+ | ||
return [eθ, er] | ||
end | ||
|
||
# quick check | ||
# pose = (0,0,0), bear = 0.0, range = 10.0 ==> lm = (10,0) | ||
# pose = (0,0,0), bear = pi/2, range = 10.0 ==> lm = (0,10) | ||
# pose = (0,0,pi/2), bear = 0.0, range = 10.0 ==> lm = (0,10) | ||
# pose = (0,0,pi/2), bear = pi/2, range = 10.0 ==> lm = (-10,0) | ||
|
||
#TODO wrapper, consolidate with CalcFactor version, see #467 | ||
function (s::Pose2Point2BearingRange{<:Normal})(xi::AbstractVector{T}, lm::AbstractVector{T}; kwargs...) where T <: Real | ||
|
||
|
||
meas = [mean(s.bearing), mean(s.range)] | ||
iΣ = [1/var(s.bearing) 0; | ||
0 1/var(s.range)] | ||
|
||
# 1-bearing | ||
# 2-range | ||
|
||
# world frame | ||
θ = meas[1] + xi[3] | ||
mx = meas[2]*cos(θ) | ||
my = meas[2]*sin(θ) | ||
|
||
ex = lm[1] - (mx + xi[1]) | ||
ey = lm[2] - (my + xi[2]) | ||
er = sqrt(ex^2 + ey^2) | ||
|
||
eθ = atan((my + xi[2]), (mx + xi[1])) - atan(lm[2], lm[1]) | ||
|
||
res = [eθ, er] | ||
|
||
return res' * iΣ * res | ||
|
||
end | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is great thanks! consolidated. |
||
# Support for database based solving | ||
|
||
passTypeThrough(d::FunctionNodeData{Pose2Point2Range}) = d | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,21 +24,16 @@ mutable struct DynPoint2DynPoint2{T <: SamplableBelief} <: AbstractRelativeRoots | |
end | ||
|
||
getSample(cfo::CalcFactor{<:DynPoint2DynPoint2}, N::Int=1) = (rand(cfo.factor.z,N), ) | ||
function (cfo::CalcFactor{<:DynPoint2DynPoint2})( | ||
res::AbstractVector{<:Real}, | ||
z, | ||
xi, | ||
xj ) | ||
|
||
function (cfo::CalcFactor{<:DynPoint2DynPoint2})(z, xi, xj) | ||
# | ||
dt = Dates.value(cfo.metadata.fullvariables[2].nstime - cfo.metadata.fullvariables[1].nstime)*1e-9 # roughly the intended use of userdata | ||
res[1:2] = z[1:2] - (xj[1:2] - (xi[1:2]+dt*xi[3:4])) | ||
res[3:4] = z[3:4] - (xj[3:4] - xi[3:4]) | ||
nothing | ||
res12 = z[1:2] - (xj[1:2] - (xi[1:2]+dt*xi[3:4])) | ||
res34 = z[3:4] - (xj[3:4] - xi[3:4]) | ||
return [res12; res34] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we'll see how the allocations go. if bad then we can turn to using the cfo.residual container -- likely best done after consolidating CPT? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The function will probably get inlined, so it shouldn't make much of a difference. NLSolve reuses the residual in any case. |
||
end | ||
|
||
|
||
|
||
|
||
""" | ||
$(TYPEDEF) | ||
""" | ||
|
@@ -49,19 +44,18 @@ mutable struct Point2Point2Velocity{T <: IIF.SamplableBelief} <: IIF.AbstractRel | |
end | ||
|
||
getSample(cfo::CalcFactor{<:Point2Point2Velocity}, N::Int=1) = (rand(cfo.factor.z,N), ) | ||
function (cfo::CalcFactor{<:Point2Point2Velocity})( res::AbstractVector{<:Real}, | ||
z, | ||
function (cfo::CalcFactor{<:Point2Point2Velocity})( z, | ||
xi, | ||
xj ) | ||
# | ||
dt = (cfo.metadata.fullvariables[2].nstime - cfo.metadata.fullvariables[1].nstime)*1e-9 # roughly the intended use of userdata | ||
dp = (xj[1:2] .- xi[1:2]) | ||
dv = (xj[3:4] .- xi[3:4]) | ||
|
||
res[1:2] .= z[1:2] .- dp | ||
res[3:4] .= dp/dt .- 0.5*(xj[3:4] .+ xi[3:4]) # (dp/dt - 0.5*(xj[3:4]+xi[3:4])) # midpoint integration | ||
res12 = z[1:2] .- dp | ||
res34 = dp/dt .- 0.5*(xj[3:4] .+ xi[3:4]) # (dp/dt - 0.5*(xj[3:4]+xi[3:4])) # midpoint integration | ||
|
||
nothing | ||
return [res12; res34] | ||
end | ||
|
||
|
||
|
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.
we will probably drop the reuse.residual container here at some point, right?
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.
Yes, there are a couple of different ways in use currently. I agree we can experiment and then standardise.