Skip to content

Commit

Permalink
Fix Bearing2D bug (#730)
Browse files Browse the repository at this point in the history
  • Loading branch information
Affie authored Feb 19, 2024
1 parent 57b2b48 commit f7347f4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
8 changes: 2 additions & 6 deletions src/factors/Bearing2D.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,14 @@ preambleCache(::AbstractDFG, ::AbstractVector{<:DFGVariable}, ::Pose2Point2Beari

getManifold(::Pose2Point2Bearing) = SpecialOrthogonal(2)
# Pose2Point2Bearing(x1::B) where {B <: IIF.SamplableBelief} = Pose2Point2Bearing{B}(x1)
# FIXME, there might be something wrong with the sign here
function getSample(cfo::CalcFactor{<:Pose2Point2Bearing})
return rand(cfo.factor.Z)
end

function (cfo::CalcFactor{<:Pose2Point2Bearing})(Xc, p, l)
function (cfo::CalcFactor{<:Pose2Point2Bearing})(X, p, l)
# wl = l
# wTp = p
# pl = pTw*wl
pl = transpose(p.x[2]) * (l - p.x[1])
# δθ = mθ - plθ
δθ = Manifolds.sym_rem(Xc[1] - atan(pl[2], pl[1]))
δθ = Manifolds.sym_rem(X[2] - atan(pl[2], pl[1]))
return [δθ]
end

Expand Down
13 changes: 8 additions & 5 deletions test/testBearing2D.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ rs = [0, -pi/4, -pi/2, -3pi/4, -pi, 3pi/4, pi/2, pi/4, pi/4, -pi/4]
push!(rs, pi/4 - atan(3,4))

q = [5., 5]
m = [pi/4]
SO2 = SpecialOrthogonal(2)
m = hat(SO2, getPointIdentity(SO2), [pi/4])

f = Pose2Point2Bearing(Normal(pi/4,0.05))

Expand All @@ -59,7 +60,9 @@ res = calcFactorResidualTemporary(f, (Pose2, Point2), [], (xi, xj))
f = Pose2Point2Bearing(Normal(pi,0.001))
xi = ArrayPartition([0.,0], [1. 0; 0 1])
xj = [-1, -0.001]
res = calcFactorResidualTemporary(f, (Pose2, Point2), [pi], (xi, xj))

m = hat(SO2, getPointIdentity(SO2), [pi])
res = calcFactorResidualTemporary(f, (Pose2, Point2), m, (xi, xj))
@test isapprox(res, [-0.001], atol=1e-3)

##
Expand Down Expand Up @@ -200,9 +203,9 @@ lmp_noise = Matrix(Diagonal([0.01;0.01].^2))
fg = initfg()

# landmarks
addVariable!(fg, :l1, Point2)
addVariable!(fg, :l2, Point2)
addVariable!(fg, :l3, Point2)
addVariable!(fg, :l1, RoME.Point2)
addVariable!(fg, :l2, RoME.Point2)
addVariable!(fg, :l3, RoME.Point2)

addFactor!(fg, [:l1], PriorPoint2(MvNormal([-10.0;1.0-10.0],lmp_noise)), graphinit=false)
addFactor!(fg, [:l2], PriorPoint2(MvNormal([-10.0+sqrt(3)/2;-0.5-10.0],lmp_noise)), graphinit=false)
Expand Down

0 comments on commit f7347f4

Please sign in to comment.