g2o
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members
ExampleSlamInterface Class Reference

example for an interface to a SLAM algorithm More...

#include <example_slam_interface.h>

Inheritance diagram for ExampleSlamInterface:
Inheritance graph
[legend]
Collaboration diagram for ExampleSlamInterface:
Collaboration graph
[legend]

Public Member Functions

 ExampleSlamInterface ()
 
bool addNode (const std::string &tag, int id, int dimension, const std::vector< double > &values)
 
bool addEdge (const std::string &tag, int id, int dimension, int v1, int v2, const std::vector< double > &measurement, const std::vector< double > &information)
 
bool fixNode (const std::vector< int > &nodes)
 
bool queryState (const std::vector< int > &nodes)
 
bool solveState ()
 

Protected Attributes

std::map< int, std::pair< std::string, std::vector< double > > > _vertices
 

Detailed Description

example for an interface to a SLAM algorithm

Example for an interface to a SLAM algorithm. You may modify this class to fit your needs. The example class does not actually perform any optimization, it just keeps the input values and outputs the same values if asked. See the documentation of SlamParser::AbstractSlamInterface for details.

Definition at line 43 of file example_slam_interface.h.

Constructor & Destructor Documentation

◆ ExampleSlamInterface()

ExampleSlamInterface::ExampleSlamInterface ( )

Definition at line 32 of file example_slam_interface.cpp.

32{}

Member Function Documentation

◆ addEdge()

bool ExampleSlamInterface::addEdge ( const std::string &  tag,
int  id,
int  dimension,
int  v1,
int  v2,
const std::vector< double > &  measurement,
const std::vector< double > &  information 
)
virtual

adding an edge to the SLAM engine.

Parameters
tagthe tag specifying the type of the vertex
idthe unique id of the edge.
dimensionthe dimension of the edge.
v1the unique id of the edge of the first vertex
v2the unique id of the edge of the second vertex
measurementthe measurement of the constraint
informationthe information matrix (inverse of the covariance) representing the uncertainty of the measurement (row-major upper triangular and diagonal)
Returns
true, if adding was successful

Implements SlamParser::AbstractSlamInterface.

Definition at line 53 of file example_slam_interface.cpp.

56 {
57 cerr << "ADDING EDGE " << tag << " id=" << id << " dim=" << dimension << " ("
58 << v1 << " <-> " << v2 << ")"
59 << " measurement=";
60 for (size_t i = 0; i < measurement.size(); ++i) cerr << " " << measurement[i];
61 cerr << " information=";
62 for (size_t i = 0; i < information.size(); ++i) cerr << " " << information[i];
63 cerr << endl;
64 return true;
65}

◆ addNode()

bool ExampleSlamInterface::addNode ( const std::string &  tag,
int  id,
int  dimension,
const std::vector< double > &  values 
)
virtual

adding a node to the SLAM engine.

Parameters
tagthe tag specifying the type of the vertex
idthe unique id of the node.
dimensionthe dimension of the node.
valuesthe pose of the node, may be empty (i.e., the engine should initialize the node itself)
Returns
true, if adding was successful

Implements SlamParser::AbstractSlamInterface.

Definition at line 34 of file example_slam_interface.cpp.

36 {
37 cerr << "ADDING NODE " << tag << " id=" << id << " dim=" << dimension;
38 if (values.size()) {
39 cerr << "\tpose=";
40 for (size_t i = 0; i < values.size(); ++i) cerr << " " << values[i];
41 }
42 cerr << endl;
43
44 // store the values
45 if (values.size() == 0)
46 _vertices[id] = make_pair(tag, std::vector<double>(dimension));
47 else
48 _vertices[id] = make_pair(tag, values);
49
50 return true;
51}
std::map< int, std::pair< std::string, std::vector< double > > > _vertices

References _vertices.

◆ fixNode()

bool ExampleSlamInterface::fixNode ( const std::vector< int > &  nodes)
virtual

set some nodes to a fixed position

Parameters
nodesthe list of vertex IDs to fix
Returns
true, if successful

Implements SlamParser::AbstractSlamInterface.

Definition at line 67 of file example_slam_interface.cpp.

67 {
68 cerr << "FIXING NODE";
69 for (size_t i = 0; i < nodes.size(); ++i) cerr << " " << nodes[i];
70 cerr << endl;
71 return true;
72}

◆ queryState()

bool ExampleSlamInterface::queryState ( const std::vector< int > &  nodes)
virtual

Ask the SLAM engine to print the current estimate of the variables

Parameters
nodesthe list of vertex IDs to print, if empty print all variables
Returns
true, if successful

Implements SlamParser::AbstractSlamInterface.

Definition at line 74 of file example_slam_interface.cpp.

74 {
75 cerr << "QUERY STATE";
76 for (size_t i = 0; i < nodes.size(); ++i) cerr << " " << nodes[i];
77 cerr << endl;
78
79 // actually output the values to the evaluator
80 // If a SLAM algorithm is running we would need to copy its estimate
81 if (nodes.size() == 0) {
82 // print all nodes
83 for (std::map<int,
84 std::pair<std::string, std::vector<double> > >::const_iterator
85 it = _vertices.begin();
86 it != _vertices.end(); ++it) {
87 cout << it->second.first << " " << it->first;
88 const vector<double>& values = it->second.second;
89 for (size_t j = 0; j < values.size(); ++j) cout << " " << values[j];
90 cout << endl;
91 }
92 } else {
93 for (size_t i = 0; i < nodes.size(); ++i) {
94 std::map<int,
95 std::pair<std::string, std::vector<double> > >::const_iterator
96 it = _vertices.find(nodes[i]);
97 if (it != _vertices.end()) {
98 cout << it->second.first << " " << it->first;
99 const vector<double>& values = it->second.second;
100 for (size_t j = 0; j < values.size(); ++j) cout << " " << values[j];
101 cout << endl;
102 }
103 }
104 }
105
106 return true;
107}

References _vertices.

◆ solveState()

bool ExampleSlamInterface::solveState ( )
virtual

ask the engine to solve

Returns
true, if successful

Implements SlamParser::AbstractSlamInterface.

Definition at line 109 of file example_slam_interface.cpp.

109 {
110 cerr << "SOLVE STATE" << endl;
111 return true;
112}

Member Data Documentation

◆ _vertices

std::map<int, std::pair<std::string, std::vector<double> > > ExampleSlamInterface::_vertices
protected

the original value of the input (actually not needed if a real SLAM engine is running)

Definition at line 64 of file example_slam_interface.h.

Referenced by addNode(), and queryState().


The documentation for this class was generated from the following files: