|
53 | 53 | Parses a single g2o instruction to add information to factor graph.
|
54 | 54 | """
|
55 | 55 | function parseG2oInstruction!(fg::AbstractDFG,
|
56 |
| - instruction::Array{SubString{String},1}) |
57 |
| - if instruction[1] == "EDGE_SE2" |
| 56 | + instruction::Array{SubString{String},1}; |
| 57 | + initialize::Bool=true) |
| 58 | + # |
| 59 | + infoM6 = zeros(6,6) |
| 60 | + |
| 61 | + if instruction[1] == "VERTEX_SE2" |
| 62 | + poseId = Symbol("x", instruction[2]) |
| 63 | + x = parse(Float64,instruction[3]) |
| 64 | + y = parse(Float64,instruction[4]) |
| 65 | + θ = parse(Float64,instruction[5]) |
| 66 | + #NOTE just useing some covariance as its not included |
| 67 | + cov = diagm([1,1,0.1]) |
| 68 | + addVariable!(fg, poseId, Pose2) |
| 69 | + if initialize |
| 70 | + # initVariable!(fg, poseId, MvNormal([x,y,θ],cov)) |
| 71 | + initVariable!(fg, poseId, MvNormal([x,y,θ],cov), :parametric) |
| 72 | + end |
| 73 | + elseif instruction[1] == "EDGE_SE2" |
58 | 74 | # Need to add a relative pose measurement between two variables.
|
59 | 75 | # Parse all of the variables starting with the symbols.
|
60 | 76 | from_pose = Symbol("x", instruction[2])
|
@@ -86,6 +102,52 @@ function parseG2oInstruction!(fg::AbstractDFG,
|
86 | 102 | measurement = MvNormal([x_state; y_state; theta_state], cov_mat)
|
87 | 103 | rel_pose_factor = Pose2Pose2(measurement)
|
88 | 104 | addFactor!(fg, [from_pose, to_pose], rel_pose_factor)
|
| 105 | + elseif instruction[1] == "EDGE_SE3:QUAT" |
| 106 | + |
| 107 | + # MU1 = Unitary(1,ℍ) |
| 108 | + # ϵU1 = identity_element(MU1) |
| 109 | + MSO3 = SpecialOrthogonal(3) |
| 110 | + ϵSO3 = identity_element(MSO3) |
| 111 | + |
| 112 | + # Need to add a relative pose measurement between two variables. |
| 113 | + # Parse all of the variables starting with the symbols. |
| 114 | + from_pose = Symbol("x", instruction[2]) |
| 115 | + to_pose = Symbol("x", instruction[3]) |
| 116 | + |
| 117 | + dt = parse.(Float64, instruction[4:6]) |
| 118 | + qvec = parse.(Float64, instruction[[10;7:9]]) |
| 119 | + |
| 120 | + dR = TU.convert(SO3, TU.Quaternion(qvec[1],qvec[2:4])).R |
| 121 | + X = log(MSO3, ϵSO3, dR) |
| 122 | + Xc = vee(MSO3, ϵSO3, X) |
| 123 | + |
| 124 | + a = parse.(Float64, instruction[11:31]) |
| 125 | + for i=1:6 |
| 126 | + vw = view(a, (1+(i-1)*(14-i)÷2):(i*(13-i)÷2)) |
| 127 | + infoM6[i,i:6] = vw |
| 128 | + infoM6[i:6,i] = vw |
| 129 | + end |
| 130 | + cov_mat = inv(infoM6) |
| 131 | + # NOTE workaround to ensure cov_mat is Hermitian -- TODO use inf_mat directly for MvNormal |
| 132 | + cov_mat += cov_mat' |
| 133 | + cov_mat ./= 2 |
| 134 | + |
| 135 | + # Make sure both variables are in the FG. Otherwise add them. |
| 136 | + if (from_pose in ls(fg)) == false |
| 137 | + addVariable!(fg, from_pose, Pose3) |
| 138 | + end |
| 139 | + if (to_pose in ls(fg)) == false |
| 140 | + addVariable!(fg, to_pose, Pose3) |
| 141 | + end |
| 142 | + |
| 143 | + #FIXME conversion between U(1,ℍ) and SO3 covariances? |
| 144 | + @error "3D covariance from Quaternion is not done yet!" maxlog=1 |
| 145 | + # dq = Manifolds.Quaternion(qvec...) |
| 146 | + |
| 147 | + # Add a factor between the two poses with the relative measurement. |
| 148 | + measurement = MvNormal([dt;Xc], cov_mat) |
| 149 | + rel_pose_factor = Pose3Pose3(measurement) |
| 150 | + addFactor!(fg, [from_pose, to_pose], rel_pose_factor) |
89 | 151 | end
|
90 | 152 | return fg
|
91 | 153 | end
|
|
0 commit comments