-
Notifications
You must be signed in to change notification settings - Fork 13
/
testParametricSimulated.jl
159 lines (96 loc) · 3.88 KB
/
testParametricSimulated.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# test simulated PPE in reverse
using Test
using RoME
##
@testset "ensure solveParametricBinary is working" begin
##
fg = initfg()
addVariable!(fg, :x0, Pose2)
pp = PriorPose2( MvNormal(zeros(3), diagm(0.01*ones(3)) ))
addFactor!(fg, [:x0;], pp)
# reference ppe on :x0
refVal = zeros(3)
refKey = :simulated
ppe = DFG.MeanMaxPPE(refKey, refVal, refVal, refVal)
setPPE!(fg[:x0], refKey, DFG.MeanMaxPPE, ppe)
pp2 = Pose2Pose2( MvNormal([0;0;-pi+0.01], diagm(0.03*ones(3)) ))
##
@test isapprox( abs.(testFactorResidualBinary(pp2, Pose2, Pose2, zeros(3), zeros(3), ([0;0;-pi],))), [0;0;pi] )
@test isapprox( testFactorResidualBinary(pp2, Pose2, Pose2, zeros(3), [0;0;-pi], ([0;0;-pi],) ), [0;0;0], atol=1e-14 )
@test isapprox( testFactorResidualBinary(pp2, Pose2, Pose2, zeros(3), [0;0;pi], ([0;0;-pi],) ), [0;0;0], atol=1e-14 )
# wXjhat = SE2(zeros(3))*SE2([0;0;-pi])
# jXjhat = SE2(wxj) \ wXjhat
# return se2vee(jXjhat)
## do in factor graph
addVariable!(fg, :x1, Pose2)
addFactor!( fg, [:x0; :x1], pp2, graphinit=false )
##
refVal = accumulateFactorMeans(fg, [:x0f1; :x0x1f1])
@test isapprox(refVal[1:2], [0;0], atol=1e-4)
@test 0.9pi < abs(refVal[3])
## alternate API
isAlready, simPPE, genLabel = IIF._checkVariableByReference(fg, :x0, r"x\\d+", Pose2, pp2)
@test isapprox(simPPE.suggested[1:2], [0;0], atol=1e-4)
@test 0.9pi < abs(simPPE.suggested[3])
##
end
@testset "Secondary binary parametric solve test case" begin
##
fg = initfg()
addVariable!(fg, :x2, Pose2)
addFactor!(fg, [:x2],
PriorPose2( MvNormal( [
15.000000000016204;
8.660254037814505;
2.0943951023931953; #+1e-5;
],
diagm([0.01;0.01;0.01]) )) )
#
addVariable!(fg, :x3, Pose2)
pp = Pose2Pose2(MvNormal([10;0;pi/3], diagm([0.01;0.01;0.01])))
addFactor!(fg, [:x2;:x3], pp, graphinit=false)
##
# nlsolve failing ?
meas = ([10.0, 0.0, 1.0471975511965976],)
X1 = [15.000000000016204, 8.660254037814505, 2.0943951023931953]
# X2 = [0.0004014798555661571, 0.0006953833518543132, 1.206557444798529e-10]
X2 = [10.00004891350537; 17.320479835550103; 4.498439149584132e-6]
## NLsolve not moving the cost value and "terminating too early"
# res = [3.469264352442895e-5, -2.002964655985515e-5, -3.1415887889926792]
# x = [9.999965307450084, 17.32052810543953, -3.864597114787283e-6]
# res = [3.469264352798169e-5, -2.0029646563407863e-5, -3.141588788992679]
# x = [9.999965307450083, 17.32052810543953, -3.864597114889992e-6]
# res = [3.469264352798169e-5, -2.0029646563407863e-5, -3.141588788992679]
# x = [9.999965307450083, 17.32052810543953, -3.864597114941346e-6]
# @test isapprox(
resVal = testFactorResidualBinary( pp, Pose2, Pose2, X1, X2, meas )
@test isapprox( resVal[1:2], [0;0], atol=1e-4)
@test isapprox( abs(resVal[3]), π, atol=1e-4)
# test positive angle
X2 = [10.00004891350537; 17.320479835550103; π]
resVal = testFactorResidualBinary( pp, Pose2, Pose2, X1, X2, meas )
@test isapprox( resVal[1:2], [0;0], atol=1e-4)
@test isapprox( abs(resVal[3]), 0, atol=1e-4)
# test negative angle
X2 = [10.00004891350537; 17.320479835550103; -π]
resVal = testFactorResidualBinary( pp, Pose2, Pose2, X1, X2, meas )
@test isapprox( resVal[1:2], [0;0], atol=1e-4)
@test isapprox( abs(resVal[3]), 0, atol=1e-4)
##
refVal = accumulateFactorMeans(fg, [:x2f1; :x2x3f1])
@test isapprox(refVal[1:2], [10;17.32], atol=1e-2)
@test isapprox( abs(refVal[3]), pi, atol = 1e-2)
##
end
@testset "Test canonical FG Beehive generation" begin
##
# build the graph
fg = RoME.generateCanonicalFG_Beehive!()
# check that pose :x3 has rotation near +-pi
t,m,gn = IIF._checkVariableByReference(fg, :x2, r"x\d+", Pose2, getFactorType(fg, :x2x3f1),destPrefix=:x, srcNumber=2)
@test isapprox( m.suggested[1], 10, atol = 1e-1)
@test isapprox( m.suggested[2], 17.32, atol = 1e-1)
@test isapprox( abs(m.suggested[3]), π, atol = 1e-2)
##
end
#