@@ -13,7 +13,7 @@ buildPose2OdoNN_01_FromElements();
13
13
# FluxModelsPose2Pose2
14
14
15
15
# the factor definitions
16
- export FluxModelsPose2Pose2, sampleFluxModelsPose2Pose2, PackedFluxModelsPose2Pose2
16
+ export FluxModelsPose2Pose2, PackedFluxModelsPose2Pose2
17
17
# some utilities
18
18
export setShuffleAll!, setNaiveFracAll!
19
19
@@ -33,7 +33,6 @@ struct FluxModelsPose2Pose2{P,D<:AbstractArray,M<:SamplableBelief} <: AbstractRe
33
33
naiveFrac:: Ref{Float64}
34
34
# TODO type stability likely wants parameter Pose2Pose2{<:SamplableBelief}
35
35
Zij:: Pose2Pose2{<:SamplableBelief}
36
- specialSampler:: Function # special keyword field name used to invoke 'specialSampler' logic
37
36
DT:: Ref{Float64}
38
37
shuffle:: Ref{Bool}
39
38
end
42
41
43
42
function calcVelocityInterPose2! ( nfb:: FluxModelsPose2Pose2 ,
44
43
iPts:: AbstractMatrix{<:Real} ,
45
- jPts:: AbstractMatrix{<:Real} ,
46
- idx:: Int )
44
+ jPts:: AbstractMatrix{<:Real} )
47
45
#
48
46
# DXY[1:2,i] .= TransformUtils.R(iPts[3,i])'*DXY[1:2,i]
49
- nfb. joyVelData[1 ,3 : 4 ] .= jPts[1 : 2 ,idx ]
50
- nfb. joyVelData[1 ,3 : 4 ] .- = iPts[1 : 2 ,idx ]
47
+ nfb. joyVelData[1 ,3 : 4 ] .= jPts[1 : 2 ]
48
+ nfb. joyVelData[1 ,3 : 4 ] .- = iPts[1 : 2 ]
51
49
nfb. joyVelData[1 ,3 : 4 ] ./= nfb. DT[] # convert to velocity
52
- nfb. joyVelData[1 ,3 : 4 ] .= TransformUtils. R (iPts[3 ,idx ])' * nfb. joyVelData[1 ,3 : 4 ]
50
+ nfb. joyVelData[1 ,3 : 4 ] .= TransformUtils. R (iPts[3 ])' * nfb. joyVelData[1 ,3 : 4 ]
53
51
# just set zero if something is wrong
54
52
if isnan (nfb. joyVelData[1 ,3 ]) || isinf (abs (nfb. joyVelData[1 ,3 ])) || isnan (nfb. joyVelData[1 ,4 ]) || isinf (abs (nfb. joyVelData[1 ,4 ]))
55
53
nfb. joyVelData[1 ,3 : 4 ] .= 0.0
@@ -60,32 +58,32 @@ function calcVelocityInterPose2!( nfb::FluxModelsPose2Pose2,
60
58
end
61
59
62
60
63
- function calcVelocityInterPose2! ( nfb:: FluxModelsPose2Pose2 ,
64
- iPts:: AbstractMatrix{<:Real} ,
65
- jPts:: AbstractMatrix{<:Real} )
66
- #
67
- @assert size (jPts,2 ) == size (iPts,2 ) " sampleFluxModelsPose2Pose2 can currently only evaluate equal population size variables"
68
-
69
- # calculate an average velocity component
70
- if nfb. DT[] == 0
71
- # DXY = (@view jPts[1:2,:]) - (@view jPts[1:2,:])
72
- # rotate delta position from world to local iX frame
73
- for i in 1 : size (iPts,2 )
74
- calcVelocityInterPose2! (nfb, iPts, jPts, i)
75
- end
76
- else
77
- nfb. joyVelData[:,3 : 4 ] .= 0.0
78
- end
79
- nothing
80
- end
81
-
61
+ # function calcVelocityInterPose2!( nfb::FluxModelsPose2Pose2,
62
+ # iPts::AbstractMatrix{<:Real},
63
+ # jPts::AbstractMatrix{<:Real} )
64
+ # #
65
+ # @assert size(jPts,2) == size(iPts,2) "sampleFluxModelsPose2Pose2 can currently only evaluate equal population size variables"
66
+
67
+ # # calculate an average velocity component
68
+ # if nfb.DT[] == 0
69
+ # # DXY = (@view jPts[1:2,:]) - (@view jPts[1:2,:])
70
+ # # rotate delta position from world to local iX frame
71
+ # for i in 1:size(iPts,2)
72
+ # calcVelocityInterPose2!(nfb, iPts, jPts, i)
73
+ # end
74
+ # else
75
+ # nfb.joyVelData[:,3:4] .= 0.0
76
+ # end
77
+ # nothing
78
+ # end
82
79
83
- function sampleFluxModelsPose2Pose2 (nfb:: FluxModelsPose2Pose2 ,
84
- N:: Int ,
85
- fmd:: FactorMetadata ,
86
- Xi:: DFGVariable ,
87
- Xj:: DFGVariable )
80
+ # sampleFluxModelsPose2Pose2
81
+ function IIF. getSample (cfo:: CalcFactor{<:FluxModelsPose2Pose2} , N:: Int = 1 )
88
82
#
83
+ nfb = cfo. factor
84
+ fmd = cfo. metadata
85
+ Xi = fmd. fullvariables[1 ] # X
86
+ Xj = fmd. fullvariables[2 ] # A / B
89
87
90
88
# get the naive samples
91
89
# model samples (all for theta at this time)
@@ -97,14 +95,14 @@ function sampleFluxModelsPose2Pose2(nfb::FluxModelsPose2Pose2,
97
95
# number of predictors to choose from, and choose random subset
98
96
numModels = length (nfb. allPredModels)
99
97
allPreds = 1 : numModels |> collect # 1:Npreds |> collect
100
- # TODO -- compensate when there arent enough prediction models
98
+ # TODO -- compensate when there aren't enough prediction models
101
99
if numModels < N
102
100
repeat (allPreds, ceil (Int, (N- numModels)/ N) + 1 )
103
101
allPreds = allPreds[1 : N]
104
102
end
105
103
# samples for the order in which to use models, dont shuffle if N models
106
104
# can suppress shuffle for NN training purposes
107
- 1 < numModels && nfb. shuffle[] ? shuffle! (allPreds) : nothing
105
+ 1 < numModels && nfb. shuffle[] ? Random . shuffle! (allPreds) : nothing
108
106
109
107
# cache the time difference estimate
110
108
nfb. DT[] = (getTimestamp (Xj) - getTimestamp (Xi)). value * 1e-3
@@ -113,43 +111,60 @@ function sampleFluxModelsPose2Pose2(nfb::FluxModelsPose2Pose2,
113
111
end
114
112
115
113
# Convenience function to help call the right constuctor
116
- FluxModelsPose2Pose2 ( allModels:: Vector{P} ,
117
- jvd:: D ,
118
- naiveModel:: M ,
119
- naiveFrac:: Real = 0.5 ,
120
- ss:: Function = sampleFluxModelsPose2Pose2,
121
- DT:: Real = 0.0 ,
122
- shuffle:: Bool = true ) where {P, M <: SamplableBelief , D <: AbstractMatrix } = FluxModelsPose2Pose2 {P,D,M} (
114
+ FluxModelsPose2Pose2 ( allModels:: Vector ,
115
+ jvd:: AbstractMatrix ,
116
+ naiveModel:: SamplableBelief ,
117
+ naiveFrac:: Float64 = 0.5 ,
118
+ DT:: Float64 = 0.0 ,
119
+ shuffle:: Bool = true ) = FluxModelsPose2Pose2 (
123
120
allModels,
124
121
jvd,
125
122
naiveModel,
126
- naiveFrac,
123
+ Ref ( naiveFrac) ,
127
124
Pose2Pose2 (MvNormal (zeros (3 ),diagm (ones (3 )))), # this dummy distribution does not get used
128
- ss,
129
- DT,
130
- shuffle )
125
+ Ref (DT),
126
+ Ref (shuffle) )
131
127
#
128
+ # struct FluxModelsPose2Pose2{P,D<:AbstractArray,M<:SamplableBelief} <: AbstractRelativeRoots
129
+ # allPredModels::Vector{P}
130
+ # joyVelData::D
131
+ # naiveModel::M
132
+ # naiveFrac::Ref{Float64}
133
+ # # TODO type stability likely wants parameter Pose2Pose2{<:SamplableBelief}
134
+ # Zij::Pose2Pose2{<:SamplableBelief}
135
+ # DT::Ref{Float64}
136
+ # shuffle::Ref{Bool}
137
+ # end
132
138
133
139
134
- function (nfb:: FluxModelsPose2Pose2 )(
135
- res:: AbstractArray{<:Real} ,
136
- userdata:: FactorMetadata ,
137
- idx:: Int ,
138
- meas:: Tuple{AbstractArray{<:Real},AbstractArray{<:Int},AbstractArray{<:Int}} ,
139
- Xi:: AbstractArray{<:Real,2} ,
140
- Xj:: AbstractArray{<:Real,2} )
140
+ function (cfo:: CalcFactor{<:FluxModelsPose2Pose2} )(meas1,meas2,meas3,Xi,Xj)
141
+ # function (nfb::FluxModelsPose2Pose2)(
142
+ # res::AbstractArray{<:Real},
143
+ # userdata::FactorMetadata,
144
+ # idx::Int,
145
+ # meas::Tuple{AbstractArray{<:Real},AbstractArray{<:Int},AbstractArray{<:Int}},
146
+ # Xi::AbstractArray{<:Real,2},
147
+ # Xj::AbstractArray{<:Real,2} )
141
148
#
149
+ userdata = cfo. metadata
150
+ nfb = cfo. factor
151
+ fmd = cfo. metadata
152
+ meas = (meas1, meas2, meas3)
153
+
154
+ # # MAYBE JUST MOVE THIS INTO getSample and be done
142
155
# if, use prediction sample
143
- if meas[2 ][idx] == 2
156
+ if meas[2 ] == 2 # meas2 == 2
144
157
# get live velocity estimate for each sample (nfb.joyVelData[:,3:4])
145
- calcVelocityInterPose2! (nfb, Xi, Xj, idx )
158
+ calcVelocityInterPose2! (nfb, Xi, Xj)
146
159
# predict odom for this sample from a specific prediction model
147
- meas[1 ][1 : 2 ,idx ] = nfb. allPredModels[meas[3 ][idx ]](nfb. joyVelData)
160
+ meas[1 ][1 : 2 ] = nfb. allPredModels[meas[3 ]](nfb. joyVelData)
148
161
end
149
162
150
163
# calculate the error for that measurement sample as Pose2Pose2
151
- nfb. Zij (res, userdata, idx, (meas[1 ],), Xi, Xj)
152
- nothing
164
+ # TODO
165
+ cfZij = CalcFactor ( nfb. Zij, nothing , 0 , 0 , (), [])
166
+ res = cfZij ((meas[1 ],), Xi, Xj)
167
+
153
168
end
154
169
155
170
"""
0 commit comments