Main MRPT website > C++ reference for MRPT 1.9.9
graph_slam_levmarq_test_common.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2017, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include <mrpt/graphslam/types.h>
11 #include <mrpt/graphslam/levmarq.h>
12 #include <mrpt/graphs.h>
13 #include <mrpt/random.h>
15 
16 using namespace mrpt;
17 using namespace mrpt::random;
18 using namespace mrpt::utils;
19 using namespace mrpt::poses;
20 using namespace mrpt::graphs;
21 using namespace mrpt::math;
22 using namespace std;
23 
24 template <class my_graph_t>
26 {
27  public:
28  // adds a new edge to the graph. The edge is annotated with the relative
29  // position of the two nodes
30  static void addEdge(
31  TNodeID from, TNodeID to,
32  const typename my_graph_t::global_poses_t& real_poses,
33  my_graph_t& graph)
34  {
35  typename my_graph_t::edge_t RelativePose =
36  real_poses.find(to)->second - real_poses.find(from)->second;
37  graph.insertEdge(from, to, RelativePose);
38  }
39 
40  // The graph: nodes + edges:
41  static void create_ring_path(
42  my_graph_t& graph, size_t N_VERTEX = 50, double DIST_THRES = 7,
43  double NODES_XY_MAX = 20)
44  {
45  // The global poses of each node (without covariance):
46  typename my_graph_t::global_poses_t real_node_poses;
47 
48  // ----------------------------
49  // Create a random graph:
50  // ----------------------------
51  // Level of noise in nodes initial positions:
52  const double STD_NOISE_NODE_XYZ = 0.5;
53  const double STD_NOISE_NODE_ANG = DEG2RAD(5);
54 
55  // Level of noise in edges:
56  const double STD_NOISE_EDGE_XYZ = 0; // 0.01;
57  const double STD_NOISE_EDGE_ANG = 0; // DEG2RAD(0.1);
58 
59  for (TNodeID j = 0; j < N_VERTEX; j++)
60  {
61  static double ang = 2 * M_PI / N_VERTEX;
62  const double R = NODES_XY_MAX + 2 * (j % 2 ? 1 : -1);
63  CPose2D p(R * cos(ang * j), R * sin(ang * j), ang);
64 
65  // Save real pose:
66  real_node_poses[j] = p;
67 
68  // Copy the nodes to the graph, and add some noise:
69  graph.nodes[j] = p;
70  }
71 
72  // Add some edges
73  for (TNodeID i = 0; i < N_VERTEX; i++)
74  {
75  for (TNodeID j = i + 1; j < N_VERTEX; j++)
76  {
77  if (real_node_poses[i].distanceTo(real_node_poses[j]) <
78  DIST_THRES)
79  addEdge(i, j, real_node_poses, graph);
80  }
81  }
82 
83  // Cross-links:
84  addEdge(0, N_VERTEX / 2, real_node_poses, graph);
85 
86  // The root node (the origin of coordinates):
87  graph.root = TNodeID(0);
88 
89  // This is the ground truth graph (make a copy for later use):
90  const my_graph_t graph_GT = graph;
91 
92  // Add noise to edges & nodes:
93  for (typename my_graph_t::edges_map_t::iterator itEdge =
94  graph.edges.begin();
95  itEdge != graph.edges.end(); ++itEdge)
96  itEdge->second += typename my_graph_t::edge_t(
97  CPose3D(
98  getRandomGenerator().drawGaussian1D(0, STD_NOISE_EDGE_XYZ),
99  getRandomGenerator().drawGaussian1D(0, STD_NOISE_EDGE_XYZ),
100  getRandomGenerator().drawGaussian1D(0, STD_NOISE_EDGE_XYZ),
101  getRandomGenerator().drawGaussian1D(0, STD_NOISE_EDGE_ANG),
102  getRandomGenerator().drawGaussian1D(0, STD_NOISE_EDGE_ANG),
103  getRandomGenerator().drawGaussian1D(0, STD_NOISE_EDGE_ANG)));
104 
105  for (typename my_graph_t::global_poses_t::iterator itNode =
106  graph.nodes.begin();
107  itNode != graph.nodes.end(); ++itNode)
108  if (itNode->first != graph.root)
109  itNode->second += typename my_graph_t::edge_t::type_value(
110  CPose3D(
111  getRandomGenerator().drawGaussian1D(0, STD_NOISE_NODE_XYZ),
112  getRandomGenerator().drawGaussian1D(0, STD_NOISE_NODE_XYZ),
113  getRandomGenerator().drawGaussian1D(0, STD_NOISE_NODE_XYZ),
114  getRandomGenerator().drawGaussian1D(0, STD_NOISE_NODE_ANG),
115  getRandomGenerator().drawGaussian1D(0, STD_NOISE_NODE_ANG),
116  getRandomGenerator().drawGaussian1D(0, STD_NOISE_NODE_ANG)));
117  }
118 };
A namespace of pseudo-random numbers genrators of diferent distributions.
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
Abstract graph and tree data structures, plus generic graph algorithms.
Scalar * iterator
Definition: eigen_plugins.h:26
STL namespace.
#define M_PI
Definition: bits.h:92
This base provides a set of functions for maths stuff.
Definition: CArrayNumeric.h:19
uint64_t TNodeID
The type for node IDs in graphs of different types.
Definition: types_simple.h:49
#define DEG2RAD
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Definition: CPoint.h:17
static void addEdge(TNodeID from, TNodeID to, const typename my_graph_t::global_poses_t &real_poses, my_graph_t &graph)
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
A class used to store a 2D pose, including the 2D coordinate point and a heading (phi) angle...
Definition: CPose2D.h:40
const float R
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:88
static void create_ring_path(my_graph_t &graph, size_t N_VERTEX=50, double DIST_THRES=7, double NODES_XY_MAX=20)
CRandomGenerator & getRandomGenerator()
A static instance of a CRandomGenerator class, for use in single-thread applications.
GLfloat GLfloat p
Definition: glext.h:6305



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019