2026年3月

#pragma     once

#include        <stdio.h>
//#include        <fmt/color.h>
//#include        <fmt/format.h>



//fmt::print(fg(fmt::color::red), format, ##__VA_ARGS__);  \
//fmt::print(fg(fmt::color::yellow), format, ##__VA_ARGS__);       \

#define     LOG_ERR(format, ...)   \
    do{                 \
        printf("\033[0m\033[1;31m" format "\033[0m", ##__VA_ARGS__);       \
    }while(0)       \


#define     LOG_WARN(format, ...)   \
    do{                   \
        printf("\033[0m\033[1;33m" format "\033[0m", ##__VA_ARGS__);       \
    }while(0)

#define     LOG_INFO(format, ...)   \
    do{                   \
        printf(format, ##__VA_ARGS__);       \
    }while(0)



















































sftp:


sftp://192.168.3.17/share/XI_HDD8T/Xi
port:22
name: hsx
pwd: hong0504

gitlab配置:
gitlab:
  environment:
    DEBUG: 'false'
    GITLAB_PORT: 6500
    GITLAB_SECRETS_DB_KEY_BASE: qcs-gitlab-app
    GITLAB_SECRETS_OTP_KEY_BASE: qcs-gitlab-app
    GITLAB_SECRETS_SECRET_KEY_BASE: qcs-gitlab-app
    GITLAB_SSH_PORT: 6501
    GITLAB_HOST: 192.168.3.17
  image: sameersbn/gitlab:11.4.0
  links:
  - redis:redisio
  - postgresql:postgresql
  ports:
  - 6500:80
  - '6501:22'
  volumes:
  - /share/XI_HDD8T/git_repository/data:/home/git/data
  restart: always
postgresql:
  environment:
    DB_EXTENSION: pg_trgm
    DB_NAME: gitlabhq_production
    DB_PASS: password
    DB_USER: gitlab
  image: sameersbn/postgresql:9.6-2
  volumes:
  - /share/XI_HDD8T/git_repository/postgresql:/var/lib/postgresql
  restart: always
redis:
  command:
  - --loglevel warning
  image: sameersbn/redis:latest
  volumes:
  - /share/XI_HDD8T/git_repository/redis:/var/lib/redis
  restart: always







1:QNAP ID:
  name: kuafu80@163.com  
  name: 13975186180
  ****: Good@0504

2: NAS admin
  name: hsx
  ****: hong0504

3: NAS gitlab
  name: xsh
  ****: Good@0504

4: halo blog:
  name: xsh
  ****: Good@0504

5: 蒲公英: https://www.pgybox.com/
  name: 13975086180
  ****: Good@1980










SE(3) constraints for robotics

2021-09-08

This document summarizes some common maths used for state estimation of rigid bodies such as in robotics.

1 Transformation parameterisation

Rigid transformations in 3 dimensions are known as the special Euclidean group, SE(3), and can be written in the homogeneous form.

1 T4×4=[R3×3t3×101×31]SE(3).

The rotation matrix R is in the special orthogonal group SO(3), which means that it is orthogonal (its columns are normal and orthogonal to each other) and it has determinant +1.

1.1 Transforming a point

An element TSE(3) may transform a 3D point pR3:

2 p3×1=[xyz].

In this document we use it interchangeably with the homogeneous representation:

3 p4×1=[xyz1]

so that points may be transformed rigidly

4 TpRp+t.

1.2 The Lie algebra

Each element in SE(3) is associated with an element on the corresponding Lie algebra, se(3):

5 ξ4×4=[[ω]×τ01×30]se(3)=[0ω3ω2τ1ω30ω1τ2ω2ω10τ30000]se(3)

where [ω]× is the skew symmetric form of the cross product by ω. We may also write it as a 6×1 vector.

6 ξ6×1=[ω3×1τ3×1].

We will use the 6×1 and 4×4 representations interchangeably depending on context.

Note that some other textbooks put the translational part on top and the rotational part below. It doesn’t matter much, but it will affect our notation for things like the adjoint action, differentials, etc below.

1.3 The exponential map

The group SE(3) and its algebra se(3) are related by the exponential map:

7 exp:se(3)SE(3)log:SE(3)se(3).

The definition of exp is based on the Taylor series:

8 exp(ξ)=I4×4+ξ4×4+12!ξ4×42+13!ξ4×43

Closed forms exist.See: J. L. Blanco’s report jlblanco.

Note that SE(3) is not commutative. The adjoint action relates things in different orders:

9 Texp(δ)=exp(Ad(T)δ)T.

The adjoint is a 6×6 matrix:

10 Ad(T)=[R03×3[t]×RR].

1.4 Notation summary

In general,

  • bold lowercase refers to vectors (e.g. translation t)
  • bold uppercase refers to matrices (e.g. transformation T)
  • non-bold lowerase refers to scalars (e.g. time t)

Here we define and summarise some notation for the following sections.

Description Notation
skew-symmetric cross product matrix [0t3t2t30t1t2t10] [t]×
translational part of TSE(3) t(T)
rotational part of TSE(3) R(T)
translational part of ξse(3) τ(ξ)
rotational part of ξse(3) ω(ξ)
compose T1,T2SE(3) T1T2
exp ξse(3) exp(ξ)
log of TSE(3) log(T)
exp ωso(3) exp(ω)
log of RSO(3) log(R)
inverse of ξse(3) ξ
inverse of TSE(3) T1
inverse of ωso(3) ω
inverse of RSO(3) RT
adjoint of TSE(3) Ad(T)
i th element of {ξξse(3)} ξi
i th element of {TTSE(3)} Ti
transform pR3 by TSE(3) Tp
transform pR3 by ξse(3) exp(ξ)p
Table 1 Summary of notation and implementation. For the array ones, operations are applied elementwise.

2 Derivatives

Here, we only differentiate with respect to δse(3) around the point δ=0. In other words, we have a function F(T) where TSE(3) and we would like to perturb T by a very small δ.

Suppose δ=[ωτ]T.If F is of dimension n, then the resulting derivative is an n×6 Jacobian.

11 Jn×6F(Tδ)δ]δ=0=[F1ω1F1ω2F1ω3F1τ1F1τ2F1τ3Fnω1Fnω2Fnω3Fnτ1Fnτ2Fnτ3]

where F(Tδ)=F(exp(δ)T) in the case of left-perturbations and F(Texp(δ)) in the case of right-perturbations.

The adjoint action can be used to relate the left and right derivatives by using the chain rule.

12 F(Aexp(δ)B)δ=F(exp(Ad(A)δ)AB)δ=δF(exp(Ad(A)δϵ)AB)=ϵF(exp(ϵ)AB)ϵδ=ϵF(exp(ϵ)AB)Ad(A).

We also have a derivative of the log function:

13 Dlog(T)δ]δ=06×1log(exp(δ)T)=[Dlog(ω)03×3Dlog(ω)BDlog(ω)Dlog(ω)]

where

14 Dlog(ω)=I12[ω×]+eθ[ω]×2Bbθ[u]×+cθ(ωuT+uωT)+(ωtu)W(ω)θ=ωaθ=sinθθbθ=1cosθθ2cθ=1aθθ2eθ=bθ2cθ2aθ

The exact derivation is in Ethan Eade’s report eade.

Let TSE(3), pR3, then the following table lists some useful derivatives.

As you will see later, these are basically all the derivatives you need, and all other derivatives can be easily derived from these, often together with using the adjoint.

Function Derivative
F(δ) Fδ]δ=0
exp(δ)Tp [[Tp]×I]
Texp(δ)p R(T)[[p]×I]
log(exp(δ)T) Dlog(T)
Table 2 Summary of derivatives

3 Optimisation

Suppose we have a trajectory S(t)SE(3) that is a smooth curve. We would like to minimise some objective function:

15 cost(S)=F(S)TF(S).

We seek to reduce the cost as much as possible. This is a nonlinear least squares problem. During the optimisation process, we perturb it by a small perturbation δ(t)se(3):

16 Snew(t)=S(t)δ(t)

where the operator can either be the left-update:

17 Sδexp(δ)S

or the right-update:

18 SδSexp(δ).

Both are valid depending on numerical properties of the problem.

In any case, we linearise the problem around δ=0.

Let the Jacobian matrix be:

19 J=δF(Sδ)]δ=0.

Then we can solve δ using Gauss-Newton:

20 JTJδGN=JTF

or steepest descent:

21 δs=JTF

or more sophisticated algorithms. In practice, we use Powell’s Dog Leg. The update is

22 δ=cGNδGN+csδs

where scalar weights cGN, cs are chosen such that δΔ where the scalar parameter Δ is the radius of the trust region. When Δ is small, the problem is behaving badly and the quadratic approximation that Gauss-Newton uses is not very valid. In this case, cGN is zero, allowing the optimiser to take timid steps along the steepest descent direction. When Δ is large, the quadratic approximation is good and we take bigger steps in the Gauss-Newton direction.

Heuristics are used to determine when to increase Δ and when to decrease it.

3.1 Optimisation under uncertainty

When uncertainty is present, the data is associated with some covariance matrix Σ which is an n×n matrix where n is the sise of the residual. The Gauss-Newton update then becomes:

23 JTΣ1Jδ=JTΣ1F

The matrix Σ1 is also sometimes called the information matrix. In practice, it is useful to factor this matrix, for example, by taking the matrix square root. Let W=Σ12, then,

24 (WJ)T(WJ)δ=(WJ)T(WF).

In other words, we just pre-multiply the Jacobian and residual by a weight matrix. This is a form of whitening. In the common case where Σ is a diagonal matrix, we simply divide each row of the Jacobian and the residual by the standard deviation.

Another common factorisation is the eigendecomposition of the covariance matrix Σ:

25 Σ=QΛQT

where QSO(n) is the square matrix whose columns are the orthonormal eigenvectors of Σ and Λ is the diagonal matrix whose entries are the eigenvalues. Then,

26 W=Λ12QT.

This is useful, for example, in the case of surfel matches. Recall that the covariance matrix is always symmetric positive semidefinite, allowing for easy eigendecomposition.

3.2 Robust loss functions

A least squares problem can be thought of as minimising the negative log likelihood function of a Gaussian. The likelihood function is of the form

27 L=exp(fi2)

Then, the log likelihood is of the least squares form:

28 cost=logL=fi2.

However, in many cases, the random variable is not Gaussian. The Gaussian has very thin tails, making it incredibly unlikely to have outliers. In the real life, there are often many outliers that necessitate a more thick-tailed distribution. To model such situations, we need robust loss functions.

Instead of optimising fi2, we optimise:

29 cost=ρ(fi)2

where ρ is a robust loss function. We can then weigh each row or block of the Jacobian J and the residual F with a robust reweighting factor:

30 riρ(fi)fi.
Name Definition
TrivialLoss ρ(x)=x
CauchyLoss ρ(x)=log(1+x)
HuberLoss ρ(x)={xx<k2kxk2xk2
Table 3 Some loss functions for x=f.

4 Trajectory representation

The goal is to recover the trajectory of a vehicle as a parametric curve S(t)SE(3) as a function of time t.

We may assume the curve does not oscillate faster than some frequency (say, 10~Hz).

Now we should find a trajectory representation that satisfies the following properties:

  • For some finite period of time, the trajectory should be approximately correct and differentiable.
  • For any given real number t within the domain of the curve, we can efficiently evaluate S(t) in constant time.
  • Local perturbations δ(t) may be applied to the curve, so that Snew(t)=S(t)δ(t), such that the perturbation δ(t) may be parameterised with a finite number of parameters, each with compact support.
  • The trajectory must be independent of the choice of the inertial reference frame.

Our solution to satisfy these requirements is a piecewise linear trajectory.The trajectory is represented as a sequence of elements Si that represent S(ti) for some ti sampled with even spacing at a high frequency (say, 100~Hz).To evaluate S(t), we use a geodesic interpolation for tit<ti+1.

31 S(t)=exp((tti)log(Si+1Si1))Si.

To perturb this spline with a curve δ(t), we update each Si, like so:

32 Si,new=Siδ(ti)

Alternative approaches for parameterising trajectories include:

5 Parameterisation of the perturbation

When applying perturbations, the curve δ is a smooth curve which may be thought of as a vector of infinite dimension.

To ensure that the problem is computationally tractable and that Snew remains twice-differentiable, we parameterise the perturbation δ by a finite vector ξ.The vector ξ is the concatenation many six-dimensional vectors ξise(3), such that

33 δ(t)=inξiβ((ti)Δt).

Notice that, since δ(t) only applies small local perturbations, it is possible to add together the ξi treating them as vectors in R6.The scalar-valued function β is a basis function with compact support, which means that it is nonzero for a finite contiguous segment of t and zero everywhere else.A good choice is the piecewise polynomial for a cardinal cubic B-spline:

34 β(t)={16t3t[0,1]16(3t3+12t212t+4)t[1,2]16(3t324t2+60t44)t[2,3]16(t3+12t248t+64)t[3,4]0t[0,4]

We can now redefine the Jacobian to be with respect to the parameters:

35 J=ξF(Sδ)δ=0.

Since β is a constant,

36 ξi=β((ti)Δt)δ(t).

The elements ξise(3) are known as the spline knots. Since each knot is a 6×1 vector, the number of columns of J is 6×nknots where nknots is the number of spline knots.

As you can see, the derivative of the trajectory at any point t in time is a linear combination of the derivatives of up to four spline knots.

In the next sections we will compute derivatives

37 δ(t)

knowing that each of these blocks will contribute up to four blocks, weighted with scalar weights β, to the actual Jacobian where we are optimizing the spline knots ξ.

6 Constraints

The function F is known as the residual. It consists of many constraints:

38 F=[FpositionFloopFgravity]

For people familiar with the Ceres library, each constraint is a residual block.

6.1 Position constraint

The position constraint seeks to penalise the distance between the pose’s translational component and a 3D point.

For example, the 3D point may be the GPS position p(t) measured at time t.

6.1.1 Residual

The residual is a 3×1 vector:

39 Fposition=t(T(t))p(t)

Recall from the notation section that t(T) is the translational component of the SE(3) element T.

6.1.2 Left Jacobian

The left Jacobian is 3×6:

40 JleftFpositionδ=t(exp(δ)T(t))δ=[[t(T(t))]×I3×3]

The trick is to view t(T)=Tp where p=0.Then we can apply the Jacobian for transforming a point in the derivatives table.

6.1.3 Right Jacobian

The right Jacobian is 3×6:

41 JrightFpositionδ=t(T(t)exp(δ))δ=[03×3R(T(t))]

6.2 Loop closure constraint

Suppose that we have aligned the poses from two points in time along a trajectory, e.g. using ICP.

This produces a relative transformation A.

6.2.1 Residual

The residual is a 6×1 vector:

42 Floop closure=log(T(t1)1T(t2)trajectoryA)

6.2.2 Left Jacobians

43 Jleft,t1Floop closureδ(t1)=log((exp(δ)T(t1))1T(t2)A)δ=log(T(t1)1exp(δ)T(t2)A)δ=log(T(t1)1exp(δ)T(t2)A)δ=log(exp(Ad(T(t1)1)δ)T(t1)1T(t2))δ=log(exp(ϵ)T(t1)1T(t2)A)ϵAd(T(t1)1)=Dlog(T(t1)1T(t2)A)Ad(T(t1)1)
44 Jleft,t2Floop closureδ(t2)=log(T(t1)1exp(δ)T(t2)A)δ=Dlog(T(t1)1T(t2)A)Ad(T(t1)1)

6.2.3 Right Jacobians

45 Jright,t1Floop closureδ(t1)=log((T(t1)exp(δ))1T(t2)A)δ=log(exp(δ)T(t1)1T(t2)A)δ=Dlog(T(t1)1T(t2)A)
46 Jright,t2Floop closureδ(t2)=log((T(t1)1T(t2)exp(δ)A)δ=Dlog(T(t1)1T(t2)A)Ad(T(t1)1T(t2))

6.3 Gravity constraint

The gravity constraint seeks to penalise the distance between up vector of the car R(T(t))u and the true up vector utrue=[0,0,1]T.

For example, if the sensor were mounted perfectly upright, then u=utrue.

We can also use the accelerometer reading to obtain a different u at each point in time, as long as you remember to subtract the inertial acceleration.

6.3.1 Residual

The residual is a 3×1 vector:

47 Fgravity=(R(T(t))uutrue)

6.3.2 Left Jacobian

Since the gravity constraint only depends on rotation and not on translation, we only care about the derivative with respect to ω(δ), which we hereafter write as ω.

48 JleftFgravityω=exp(ω)R(T(t))uω=[R(T(t))u]×

6.3.3 Right Jacobian

49 JrightFgravityω=R(T(t))exp(ω)uω=R(T(t))[u]×

Recall that R(T) is the rotational component of the pose T.

6.4 Point constraint

We are aligning a “moving” or “map” point m to a “static” or “scene” point s by transforming the moving point with the pose T.

The matrix A can be used to store the uncertainty of the point s, i.e. an information matrix (the inverse of a covariance matrix).

  • If you are registering the point to a line, you can let A be 2×3. A common choice is to compute an orthonormal basis from the direction of the ray, e.g. using Duff et al’s approach. This is commonly used in visual odometry.
  • If you are registering the point to a plane, you can let A be 1×3.

6.4.1 Residual

The residual is a 3×1 vector:

50 Fpoint=A(Tms).

6.4.2 Left Jacobian

The left Jacobian is k×6, where A is k×3.

51 Jleft=A[[Tm]×I]

6.4.3 Right Jacobian

The right Jacobian is k×6, where A is k×3.

52 Jright=AR(T)[[m]×I]

Recall that R(T) is the rotational component of the pose T.

6.5 Velocity constraint

The velocity constraint seeks to penalise deviations in vehicle velocity from the 6 degree of freedom velocity estimates from another source.

For ease of implementation, the vehicle velocity is obtained by numerical differentiation, e.g. by evaluating the pose at times t1 and t2.Let h=1/(t2t1).

6.5.1 Residual

The residual is a 6×1 vector.For concise notation let us define the 6×6 matrix Δ such that

53 Fvelocity=hlog(Δ)ξvelocity=hlog(T(t2)T(t1)1)ξvelocity

6.5.2 Left Jacobian

Consider differentiating with respect to left-updates of T(t1).

The Jacobian is 6×6.

54 Jleft(t1)Fvelocityδ(t1)=δhlog(T(t2)(exp(δ)T(t1))1)=δhlog(T(t2)T(t1)1Δexp(δ))=δhlog(exp(Ad(Δ)δϵ)Δ)=ϵhlog(exp(ϵ)Δ)ϵδ=hDlog(Δ)Ad(Δ)=hDlog(T(t2)T(t1)1)Ad(T(t2)T(t1)1).

Now, consider differentiating with respect to left-updates to T(t2).

55 Jleft(t2)Fvelocityδ(t2)=δhlog(exp(δ)T(t2)T(t1)1)=hDlog(T(t2)T(t1)1).

6.6 Regularisation constraint

The regularisation constraint implements a basic Tikhonov regulariser.It seeks to dampen the problem to avoid divergent oscillations, overfitting, or other types of poor convergence.

6.6.1 Residual

The residual is 6×1:

56 Fregulariser=ξ.

6.6.2 Jacobian

The Jacobian is the identity:

57 Jregulariser=I.

7 References

  • jlblanco Blanco, J.L. (2020) A tutorial on SE(3) transformation parameterizations and on-manifold optimization. link
  • eade Eade, E. (2018) Derivative of the Exponential map. link

#include    <iostream>
#include    <cmath>

#include    <Eigen/Dense>
#include    <sophus/common.hpp>
#include    <sophus/geometry.hpp>

using namespace  std;
using namespace  Eigen;



int main(int argc, const char *argv[])
{
    Matrix3d R = AngleAxisd(M_PI / 2, Vector3d(0, 0, 1)).toRotationMatrix();
    Quaterniond q(R);
    // ************  SO(3) ************
    Sophus::SO3d SO3d_R(R); 
    Sophus::SO3d SO3d_q(q); // Result should be the same as SO3d_R
    cout << "SO(3) from rotation matrix = \n" << SO3d_R.matrix() << endl;
    cout << "SO(3) from quaternion = \n" << SO3d_q.matrix() << endl;
    // Logarithmic map to get the lie algebra
    Vector3d so3 = SO3d_R.log();
    cout << "so3 = \n" << so3.transpose() << endl;
    // Hat is from vector to skew-symmetric matrix
    cout << "so3 hat = \n" << Sophus::SO3d::hat(so3) << endl;
    // Vee is from skew-symmetric matrix to vector
    cout << "so3 vee = \n" << Sophus::SO3d::vee(Sophus::SO3d::hat(so3)).transpose() << endl;
    // Update by perturbation model
    Vector3d update_so3(1e-4, 0, 0);
    Sophus::SO3d SO3d_updated = Sophus::SO3d::exp(update_so3) * SO3d_R;
    cout << "SO3 updated = \n" << SO3d_updated.matrix() << endl;
    cout << "****************************" << endl;
    return 0;
}