Skip to content
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

fix IMUDelta factor serde #749

Merged
merged 1 commit into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/ExportAPI.jl
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ export DynPose2, DynPose2VelocityPrior, PackedDynPose2VelocityPrior, DynPose2Pos
export PriorIMUBias, PackedPriorIMUBias
export PriorVelPos3, PackedPriorVelPos3
export VelPosRotVelPos, PackedVelPosRotVelPos
export IMUDeltaFactor, PackedIMUDeltaFactor

# InertialPose3
export
Expand Down
42 changes: 35 additions & 7 deletions src/factors/Inertial/IMUDeltaFactor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -495,34 +495,62 @@ end

## serde

Base.@kwdef struct PackedIMUDeltaFactor{T <: PackedSamplableBelief} <: AbstractPackedFactor
struct PackedIMUDeltaFactor{T <: PackedSamplableBelief} <: AbstractPackedFactor
Z::T # NOTE dim is 9 as Δt is not included in covariance
dt::Float64
D::Vector{Float64}
Sigma::Vector{Float64} #SMatrix{10,10,Float64}
# J_b::SMatrix{10,6,Float64} = zeros(SMatrix{10,6,Float64})
# accelerometer bias, gyroscope bias
b::Vector{Float64} = zeros(6)
b::Vector{Float64}
end

function PackedIMUDeltaFactor(;
Z,
dt,
D,
Sigma,
b
)
_gettype(zt::PackedSamplableBelief) = zt
_gettype(zt) = DistributedFactorGraphs.getTypeFromSerializationModule(zt["_type"])(; zt...)

_Z = _gettype(Z)
# _Z = ZT(; Z...)
_dt = Float64(dt)
_D = Float64.(D)
_Sigma = Float64.(Sigma)
_b = Float64.(b)
PackedIMUDeltaFactor(
_Z,
_dt,
_D,
_Sigma,
_b
)
end


function convert(::Type{<:PackedIMUDeltaFactor}, d::IMUDeltaFactor)
Z = convert(PackedSamplableBelief, d.Z)
return PackedIMUDeltaFactor(;
Z = convert(PackedSamplableBelief, d.Z),
Z,
dt = d.Δt,
D = vcat(collect(d.Δ.x[1][:]), collect(d.Δ.x[2]), collect(d.Δ.x[3])),
Sigma = collect(d.Σ[:])
D = vcat(collect(d.Δ.x[1][:]), collect(d.Δ.x[2]), collect(d.Δ.x[3]), d.Δ.x[4]),
Sigma = collect(d.Σ[:]),
b = collect(d.b),
)
end
function convert(::Type{<:IMUDeltaFactor}, d::PackedIMUDeltaFactor)
15 == length(d.D) && @error("Deserializing a PackedIMUDeltaFactor has wrong length .D = $(length(d.D))")
16 !== length(d.D) && @error("Deserializing a PackedIMUDeltaFactor not 16 in length, .D = $(length(d.D))")
return IMUDeltaFactor(;
Z = convert(SamplableBelief, d.Z),
Δt = d.dt,
Δ = ArrayPartition(
SMatrix{3,3,Float64}(reshape(d.D[1:9],3,3)),
SVector{3,Float64}(d.D[10:12]),
SVector{3,Float64}(d.D[13:15])
SVector{3,Float64}(d.D[13:15]),
Float64(d.D[16])
),
Σ = SMatrix{10,10,Float64}(reshape(d.Sigma, 10,10)),
)
Expand Down
Loading