Main Content

factorGraph

Graph-based framework for multisensor state estimation

Since R2022a

Description

A factorGraph object stores a bipartite graph consisting of factors connected to variable nodes. The nodes represent the unknown random variables in an estimation problem, such as robot poses, and the factors represent probabilistic constraints on those nodes, derived from measurements or prior knowledge. During optimization, the factor graph uses all the factors and current node states to update the node states.

For more information about factor graph and how to use it, see Factor Graph for SLAM.

Creation

Description

fg = factorGraph creates an empty factorGraph object.

example

Properties

expand all

This property is read-only.

Number of nodes in the factor graph, specified as a positive integer. NumNodes has a value of 0 when the factor graph is empty and NumNodes increases each time you add a factor that specifies new node IDs to the factor graph.

The nodes in the factor graph can be any of these types:

  • "POSE_SE2" — Pose in SE(2) state space

  • "POSE_SE3" — Pose in SE(3) state space

  • "POSE_SE3_SCALE" — Pose scale in SE(3) state space

  • "TRANSFORM_SE3" — Sensor transform in SE(3) state space

  • "GRAVITY_ROTATION" — Gravity rotation represented as quaternion

  • "VEL3" — 3-D velocity

  • "POINT_XY" — 2-D point

  • "POINT_XYZ" — 3-D point

  • "IMU_BIAS" — IMU gyroscope and accelerometer bias

To check the node type of a node in the graph, use the nodeType function.

Note

The factor graph sets the node type when you add the factor object that specifies that node to the factor graph. You cannot change the node type of a node after you add it to the graph.

This property is read-only.

Number of factors in the factor graph, specified as a positive integer. NumFactors has a value of 0 when the factor graph is empty and NumFactors increases each time you add a factor to the factor graph.

You can use addfactor to add any of these factor objects to the factor graph:

Relate Poses to Each Other

  • factorTwoPoseSE2 — Connect pairs of SE(2) pose nodes ("POSE_SE2") using relative pose measurements. You can calculate the relative pose using 2-D lidar scan registration using functions like matchScans.

  • factorTwoPoseSE3 — Connect pairs of SE(3) pose nodes ("POSE_SE3") using relative pose measurements. You can calculate the relative pose using 3-D lidar scan registration using functions like pcregistericp (Computer Vision Toolbox) and estrelpose (Computer Vision Toolbox).

  • factorTwoPoseSIM3 — Connect pairs of SIM(3) pose nodes using relative pose measurements. A SIM(3) pose node is represented using a combination of an SE(3) pose node ("POSE_SE3") and an SE(3) pose scale node ("POSE_SE3_SCALE"). You can use the estgeotform3d (Computer Vision Toolbox) function to calculate the relative pose measurement for this factor.

Relate Poses to Landmark Positions

  • factorCameraSE3AndPointXYZ — Connect the SE(3) pose node of a pinhole camera ("POSE_SE3") to 3-D landmark nodes ("Point_XYZ"), or the SE(3) pose node of a pinhole camera ("POSE_SE3"), 3-D landmark nodes ("Point_XYZ") , and an SE(3) sensor transform node ("TRANSFORM_SE3") using the 2-D image point measurements from the camera.

  • factorPoseSE2AndPointXY — Connect an SE(2) pose node ("POSE_SE2") to 2-D landmark nodes ("POINT_XY") using 2-D position measurements in the reference frame of the pose node.

  • factorPoseSE3AndPointXYZ — Connect an SE(3) pose node ("POSE_SE3") to 3-D landmark nodes ("POINT_XYZ") using 3-D position measurements in the reference frame of the pose node.

Relate Poses to Sensor Measurements

  • factorGPS — Connect an SE(3) pose node ("POSE_SE3") to a GPS measurement.

  • factorIMU — Connect two SE(3) pose nodes ("POSE_SE3"), two 3-D velocity nodes ("VEL3"), and two IMU bias nodes ("IMU_BIAS") using IMU measurements. These measurements consist of accelerometer and gyroscope data that capture changes in pose and velocity.

Relate Poses or Velocities to Prior-Known Measurements

If a pose, IMU bias, velocity or SE(3) state space transform is a known quantity, add one of these prior factors to softly fix the node states, enabling slight variations only if doing so significantly reduces the overall cost:

  • factorIMUBiasPrior — Connect SE(3) pose nodes ("POSE_SE3"), 3-D velocity nodes ("VEL3"), and IMU bias nodes ("IMU_BIAS") to prior-known IMU measurements.

  • factorPoseSE3Prior — Connect SE(3) pose nodes ("POSE_SE3") to prior-known SE(3) pose measurements.

  • factorVelocity3Prior — Connect a 3-D velocity node ("VEL_3") to prior-known SE(3) velocity measurements.

  • factorTransformSE3Prior — Connect SE(3) Sensor Transform node ("TRANSFORM_SE3") to prior-known SE(3) Sensor Transform measurements.

Object Functions

expand all

generateNodeIDGenerate new node IDs
hasNodeCheck if node ID exists in factor graph
nodeIDsGet node IDs in factor graph
nodeStateGet or set node state in factor graph
nodeTypeGet node type of node in factor graph
fixNodeFix or free nodes in factor graph
isNodeFixedCheck if node is fixed
removeNodeRemove node from factor graph
addFactorAdd factor to factor graph
removeFactorRemove factor from factor graph
optimizeOptimize factor graph
marginalizeFactorMarginalize factors from factor graph into marginal factor
marginalizeNodeMarginalize node and related factors from factor graph into marginal factor
isConnectedCheck if factor graph is connected
nodeCovarianceGet state covariance of nodes in factor graph
showPlot pose nodes, pose node edges, and landmark nodes of factor graph
copyCopy factor graph

Examples

More About

expand all

Tips

  • To specify multiple factors and nodes at once for a specific factor type, use the generateNodeID function and specify the number of factors and the factor type. See the generateNodeID function for more details.

    poseIDPairs = generateNodeID(fg,3,"factorTwoPoseSE2");
    ftpse2 = factorTwoPoseSE2(poseIDPairs);
  • You can get the states of all the pose nodes by first using the nodeIDs function and specifying the node type as "POSE_SE2" for SE(2) robot poses and "POSE_SE3" for SE(3) robot poses. Then, use the nodeState function with those node IDs to get the node states of the robot pose nodes.

    poseIDs = nodeIDs(fg,NodeType="POSE_SE2");
    poseStates = nodeState(fg,poseIDs);
  • Check the types of nodes that each factor creates or connects to before adding factors to the factor graph to avoid node type mismatch errors. For a list of expected node types for each factor, see Expected Node Types of Factor Objects.

References

[1] Dellaert, Frank. Factor graphs and GTSAM: A Hands-On Introduction. Georgia: Georgia Tech, September, 2012.

Extended Capabilities

expand all

Version History

Introduced in R2022a

expand all