LIO_SAM LMOptimization公式推导

点到直线的距离理解

如果点在法线一侧,则点到直线的距离可表示为:
n T × x + D = 0 d = n T × ( x i − x 0 ) = n T × x i + D ≥ 0 n^T \times x +D = 0 \\ d = n^T \times (x_i-x_0) = n^T \times x_i +D \ge 0 nT×x+D=0d=nT×(xix0)=nT×xi+D0
这样的话就可以直接求导,不需要考虑绝对值的问题。所以在原代码中应该保证距离为正值,cornerOptimization()中使用向量叉乘保证了点在平面法线一侧,但是surfOptimization()却没有,可能是作者的疏忽,pd2为负值用高斯牛顿法迭代是有问题的!

float pd2 = pa * pointSel.x + pb * pointSel.y + pc * pointSel.z + pd;
// if(pd2<0)  //* 这里应该加一个改变pd2值和法线方向的代码!!
//     ROS_ERROR("Distance less than 0!!");

cornerOptimization()中求解法线是为了将点到线的距离变为点到面的距离,这样combineOptimizationCoeffs()将所有系数放到一起才有意义,且符合后面的高斯牛顿法求解。

e r r o r = c o e f f T × ( R × p o i n t + T ) + D error = coeff ^T\times (R \times point + T)+D error=coeffT×(R×point+T)+D

e r r o r error error就是点到面的距离, D D D为平面方程中的常数,不影响 J a c o b i Jacobi Jacobi矩阵
R = R y a w × R p i t c h × R r o l l = R r y × R r x × R r z = [ c r y 0 s r y 0 1 0 − s r y 0 c r y ] × [ 1 0 0 0 c r x − s r x 0 s r x c r x ] × [ c r z − s r z 0 s r z c r z 0 0 0 1 ] = [ c r y c r z + s r x s r y s r z s r x s r y c r z − c r y s r z c r x s r y c r x s r z c r x c r z − s r x s r x c r y s r z − s r y c r z s r y s r z + s r x c r y c r z c r x c r y ] \begin{aligned} R & = R_{yaw} \times R_{pitch} \times R_{roll} \\ & = R_{ry} \times R_{rx} \times R_{rz} \\ & = \begin{bmatrix} cry & 0 & sry \\ 0 & 1 & 0\\ -sry & 0 & cry \end{bmatrix} \times \begin{bmatrix} 1 & 0 & 0 \\ 0 & crx & -srx \\ 0 & srx & crx \end{bmatrix} \times \begin{bmatrix} crz & -srz & 0 \\ srz & crz & 0 \\ 0 & 0 & 1 \end{bmatrix} \\ & = \begin{bmatrix} crycrz+srxsrysrz & srxsrycrz-crysrz & crxsry \\ crxsrz & crxcrz & -srx \\ srxcrysrz-srycrz & srysrz+srxcrycrz & crxcry \end{bmatrix} \end{aligned} R=Ryaw×Rpitch×Rroll=Rry×Rrx×Rrz=cry0sry010sry0cry×1000crxsrx0srxcrx×crzsrz0srzcrz0001=crycrz+srxsrysrzcrxsrzsrxcrysrzsrycrzsrxsrycrzcrysrzcrxcrzsrysrz+srxcrycrzcrxsrysrxcrxcry
其中: c r x = c o s ( r x ) , s r x = s i n ( r x ) crx=cos(rx),srx=sin(rx) crx=cos(rx),srx=sin(rx)
T = [ t x , t y , t z ] T , c o e f f = [ c o e f f x , c o e f f y , c o e f f z ] T , p o i n t = [ p o i n t x , p o i n t y , p o i n t z ] T T=[tx,ty,tz]^T,coeff=[coeff_x,coeff_y,coeff_z]^T,point=[point_x,point_y,point_z]^T T=[tx,ty,tz]T,coeff=[coeffx,coeffy,coeffz]T,point=[pointx,pointy,pointz]T

a r x = ∂ e r r o r ∂ r x = [ c o e f f x c o e f f y c o e f f z ] × [ c r x s r y s r z c r x s r y c r z − s r x s r y − s r x s r z − s r x c r z − c r x c r x c r y s r z c r x c r y c r z − s r x c r y ] × [ p o i n t x p o i n t y p o i n t z ] arx=\cfrac{\partial{error}}{\partial{rx}} = \begin{bmatrix} coeff_x & coeff_y & coeff_z \end{bmatrix} \times \begin{bmatrix} crxsrysrz & crxsrycrz & -srxsry \\ -srxsrz & -srxcrz & -crx \\ crxcrysrz & crxcrycrz & -srxcry \end{bmatrix} \times \begin{bmatrix} point_x \\ point_y \\ point_z \end{bmatrix} arx=rxerror=[coeffxcoeffycoeffz]×crxsrysrzsrxsrzcrxcrysrzcrxsrycrzsrxcrzcrxcrycrzsrxsrycrxsrxcry×pointxpointypointz
a r y = ∂ e r r o r ∂ r y = [ c o e f f x c o e f f y c o e f f z ] × [ s r x c r y s r z − s r y c r z s r x c r y c r z + s r y s r z c r x c r y 0 0 0 − s r x s r y s r z − c r y c r z c r y s r z − s r x s r y c r z − c r x s r y ] × [ p o i n t x p o i n t y p o i n t z ] ary=\cfrac{\partial{error}}{\partial{ry}} = \begin{bmatrix} coeff_x & coeff_y & coeff_z \end{bmatrix} \times \begin{bmatrix} srxcrysrz-srycrz & srxcrycrz+srysrz & crxcry \\ 0 & 0 & 0 \\ -srxsrysrz-crycrz & crysrz-srxsrycrz & -crxsry \end{bmatrix} \times \begin{bmatrix} point_x \\ point_y \\ point_z \end{bmatrix} ary=ryerror=[coeffxcoeffycoeffz]×srxcrysrzsrycrz0srxsrysrzcrycrzsrxcrycrz+srysrz0crysrzsrxsrycrzcrxcry0crxsry×pointxpointypointz
a r z = ∂ e r r o r ∂ r z = [ c o e f f x c o e f f y c o e f f z ] × [ s r x s r y c r z − c r y s r z − s r x s r y s r z − c r y c r z 0 c r x c r z − c r x s r z 0 s r x c r y c r z + s r y s r z s r y c r z − s r x c r y s r z 0 ] × [ p o i n t x p o i n t y p o i n t z ] arz=\cfrac{\partial{error}}{\partial{rz}} = \begin{bmatrix} coeff_x & coeff_y & coeff_z \end{bmatrix} \times \begin{bmatrix} srxsrycrz-crysrz & -srxsrysrz-crycrz & 0 \\ crxcrz & -crxsrz & 0 \\ srxcrycrz+srysrz & srycrz-srxcrysrz & 0 \end{bmatrix} \times \begin{bmatrix} point_x \\ point_y \\ point_z \end{bmatrix} arz=rzerror=[coeffxcoeffycoeffz]×srxsrycrzcrysrzcrxcrzsrxcrycrz+srysrzsrxsrysrzcrycrzcrxsrzsrycrzsrxcrysrz000×pointxpointypointz
∂ e r r o r ∂ t x = c o e f f x ∂ e r r o r ∂ t y = c o e f f y ∂ e r r o r ∂ t z = c o e f f z \cfrac{\partial{error}}{\partial{tx}} = coeff_x \\ \cfrac{\partial{error}}{\partial{ty}} = coeff_y \\ \cfrac{\partial{error}}{\partial{tz}} = coeff_z \\ txerror=coeffxtyerror=coeffytzerror=coeffz
m a t A = [ ∂ e r r o r ∂ r x 0 ∂ e r r o r ∂ r y 0 ∂ e r r o r ∂ r z 0 ∂ e r r o r ∂ t x 0 ∂ e r r o r ∂ t y 0 ∂ e r r o r ∂ t z 0 ⋮ ⋮ ⋮ ⋮ ⋮ ⋮ ∂ e r r o r ∂ r x n ∂ e r r o r ∂ r y n ∂ e r r o r ∂ r z n ∂ e r r o r ∂ t x n ∂ e r r o r ∂ t y n ∂ e r r o r ∂ t z n ] matA = \begin{bmatrix} \cfrac{\partial{error}}{\partial{rx_0}} & \cfrac{\partial{error}}{\partial{ry_0}} & \cfrac{\partial{error}}{\partial{rz_0}} & \cfrac{\partial{error}}{\partial{tx_0}} & \cfrac{\partial{error}}{\partial{ty_0}} & \cfrac{\partial{error}}{\partial{tz_0}} \\ \vdots & \vdots & \vdots& \vdots & \vdots & \vdots \\ \cfrac{\partial{error}}{\partial{rx_n}} & \cfrac{\partial{error}}{\partial{ry_n}} & \cfrac{\partial{error}}{\partial{rz_n}} & \cfrac{\partial{error}}{\partial{tx_n}} & \cfrac{\partial{error}}{\partial{ty_n}} & \cfrac{\partial{error}}{\partial{tz_n}} \\ \end{bmatrix} matA=rx0errorrxnerrorry0errorrynerrorrz0errorrznerrortx0errortxnerrorty0errortynerrortz0errortznerror
m a t B = [ − d 0 ⋮ − d n ] matB = \begin{bmatrix} -d_0\\ \vdots \\ -d_n \end{bmatrix} matB=d0dn
其中 d i d_i di为角点到主特征向量所在直线的距离或者面点到平面的距离。
m a t A t A = m a t A T × m a t A m a t A t B = m a t A T × m a t B matAtA = matA^T \times matA \\ matAtB = matA^T \times matB matAtA=matAT×matAmatAtB=matAT×matB
高斯牛顿法的原型是 J T × J × Δ x = − J T × f ( x ) J^T \times J \times \Delta_x = -J^T \times f(x) JT×J×Δx=JT×f(x)
J = m a t A , f ( x ) = − m a t B , Δ x = m a t X J=matA,f(x)=-matB,\Delta_x=matX J=matA,f(x)=matB,Δx=matX
通过QR分解的方式,求解 m a t A T × m a t A × m a t X = m a t A T × m a t B matA^T \times matA \times matX=matA^T \times matB matAT×matA×matX=matAT×matB,得到解 Δ x = m a t X \Delta_x=matX Δx=matX

你可能感兴趣的:(linux)