@@ -13,7 +13,7 @@ buildPose2OdoNN_01_FromElements();
1313# FluxModelsPose2Pose2
1414
1515# the factor definitions
16- export FluxModelsPose2Pose2, sampleFluxModelsPose2Pose2, PackedFluxModelsPose2Pose2
16+ export FluxModelsPose2Pose2, PackedFluxModelsPose2Pose2
1717# some utilities
1818export setShuffleAll!, setNaiveFracAll!
1919
@@ -33,7 +33,6 @@ struct FluxModelsPose2Pose2{P,D<:AbstractArray,M<:SamplableBelief} <: AbstractRe
3333 naiveFrac:: Ref{Float64}
3434 # TODO type stability likely wants parameter Pose2Pose2{<:SamplableBelief}
3535 Zij:: Pose2Pose2{<:SamplableBelief}
36- specialSampler:: Function # special keyword field name used to invoke 'specialSampler' logic
3736 DT:: Ref{Float64}
3837 shuffle:: Ref{Bool}
3938end
4241
4342function calcVelocityInterPose2! ( nfb:: FluxModelsPose2Pose2 ,
4443 iPts:: AbstractMatrix{<:Real} ,
45- jPts:: AbstractMatrix{<:Real} ,
46- idx:: Int )
44+ jPts:: AbstractMatrix{<:Real} )
4745 #
4846 # 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 ]
5149 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 ]
5351 # just set zero if something is wrong
5452 if isnan (nfb. joyVelData[1 ,3 ]) || isinf (abs (nfb. joyVelData[1 ,3 ])) || isnan (nfb. joyVelData[1 ,4 ]) || isinf (abs (nfb. joyVelData[1 ,4 ]))
5553 nfb. joyVelData[1 ,3 : 4 ] .= 0.0
@@ -60,32 +58,32 @@ function calcVelocityInterPose2!( nfb::FluxModelsPose2Pose2,
6058end
6159
6260
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
8279
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 )
8882 #
83+ nfb = cfo. factor
84+ fmd = cfo. metadata
85+ Xi = fmd. fullvariables[1 ] # X
86+ Xj = fmd. fullvariables[2 ] # A / B
8987
9088 # get the naive samples
9189 # model samples (all for theta at this time)
@@ -97,14 +95,14 @@ function sampleFluxModelsPose2Pose2(nfb::FluxModelsPose2Pose2,
9795 # number of predictors to choose from, and choose random subset
9896 numModels = length (nfb. allPredModels)
9997 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
10199 if numModels < N
102100 repeat (allPreds, ceil (Int, (N- numModels)/ N) + 1 )
103101 allPreds = allPreds[1 : N]
104102 end
105103 # samples for the order in which to use models, dont shuffle if N models
106104 # can suppress shuffle for NN training purposes
107- 1 < numModels && nfb. shuffle[] ? shuffle! (allPreds) : nothing
105+ 1 < numModels && nfb. shuffle[] ? Random . shuffle! (allPreds) : nothing
108106
109107 # cache the time difference estimate
110108 nfb. DT[] = (getTimestamp (Xj) - getTimestamp (Xi)). value * 1e-3
@@ -113,43 +111,60 @@ function sampleFluxModelsPose2Pose2(nfb::FluxModelsPose2Pose2,
113111end
114112
115113# 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 (
123120 allModels,
124121 jvd,
125122 naiveModel,
126- naiveFrac,
123+ Ref ( naiveFrac) ,
127124 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) )
131127#
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
132138
133139
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} )
141148 #
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
142155 # if, use prediction sample
143- if meas[2 ][idx] == 2
156+ if meas[2 ] == 2 # meas2 == 2
144157 # get live velocity estimate for each sample (nfb.joyVelData[:,3:4])
145- calcVelocityInterPose2! (nfb, Xi, Xj, idx )
158+ calcVelocityInterPose2! (nfb, Xi, Xj)
146159 # 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)
148161 end
149162
150163 # 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+
153168end
154169
155170"""
0 commit comments