Main Content

importFactorGraph

Import factor graph from g2o log file

Since R2022a

    Description

    example

    graph = importFactorGraph(filename) imports a factor graph from the specified G2o file filename.

    Examples

    collapse all

    Import factor graph from the huskyGazebo2DPG.g2o file.

    fg = importFactorGraph("huskyGazebo2DPG.g2o")
    fg = 
      factorGraph with properties:
    
          NumNodes: 152
        NumFactors: 357
    
    

    Get the node type of the first pose node.

    type = nodeType(fg,1)
    type = 
    "POSE_SE2"
    

    Get all of the pose nodes of the same type.

    poseIDs = nodeIDs(fg,NodeType=type)
    poseIDs = 1×152
    
         0     1     2     3     4     5     6     7     8     9    10    11    12    13    14    15    16    17    18    19    20    21    22    23    24    25    26    27    28    29    30    31    32    33    34    35    36    37    38    39    40    41    42    43    44    45    46    47    48    49
    
    

    Fix the first node so it is an anchor during optimization and then optimize the factor graph with default solver options.

    fixNode(fg,0);
    optimize(fg);
    poses = nodeState(fg,poseIDs);

    Plot the poses of the factor graph as an SE(2) transformations.

    poseTFs = se2(poses,"xytheta");
    plotTransforms(poseTFs,FrameSize=0.5);
    xlabel("x(m)")
    ylabel("y(m)")
    title("Imported Factor Graph")

    Input Arguments

    collapse all

    Name of the G2o log file to import a factor graph from, specified as a string scalar or character vector. The specified G2o log file must contain either only 'EDGE_SE2' and 'VERTEX_SE2' tokens, or only 'EDGE_SE3:QUAT' and 'VERTEX_SE3:QUAT' tokens.

    Output Arguments

    collapse all

    Factor graph imported from the G2o file, returned as a factorGraph object.

    Version History

    Introduced in R2022a