Skip to content

Commit f725549

Browse files
Added comments to 45 functions across 6 files
1 parent 9d3ca3d commit f725549

File tree

6 files changed

+1116
-0
lines changed

6 files changed

+1116
-0
lines changed

agents/g2o_agent/src/g2o_visualizer.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@
55

66
class G2OVisualizer:
77
def __init__(self, title):
8+
"""
9+
initializes a Figure and Axes object for the visualization of data using
10+
Matplotlib. It sets up the graphical interface, defines the title, sets
11+
limits for the axes, and flushes events to display the figure on the screen.
12+
13+
Args:
14+
title (str): title of the graphical window displayed by Matplotlib.
15+
16+
"""
817
self.title = title
918

1019
# Configurar la ventana gráfica interactiva de Matplotlib
@@ -22,12 +31,70 @@ def __init__(self, title):
2231
# self.ax.set_ylim([-3000, 3000]) # Por ejemplo, límites para el eje y de 0 a 10
2332

2433
def edges_coord(self, edges, dim):
34+
"""
35+
takes an iterable of edges and a dimension, it returns a sequence of floats
36+
representing the coordinates of the vertices of each edge, followed by
37+
three `None` values to indicate the end of the sequence.
38+
39+
Args:
40+
edges (iterable/collection containing edges as its values.): 2-D graph
41+
edges, which are used to estimate their corresponding coordinate
42+
values for each dimension.
43+
44+
- `edges` is an instance of `List[Edge']`, where `Edge' =
45+
Tuple[Void, Void]`.
46+
- Each element in `edges` represents a pair of vertices connected
47+
by an edge. The first element in each pair is the start vertex,
48+
while the second element is the end vertex.
49+
- The `dim` parameter specifies the dimensionality of the
50+
coordinates for each vertex in the edges.
51+
dim (int): dimensionality of the space in which the coordinates are estimated.
52+
53+
"""
2554
for e in edges:
2655
yield e.vertices()[0].estimate()[dim]
2756
yield e.vertices()[1].estimate()[dim]
2857
yield None
2958

3059
def update_graph(self, optimizer, ground_truth=None):
60+
"""
61+
updates the graph shown on a figure with the latest measurements from an
62+
optimizer, ground truth data (if provided), and poses of the vertices.
63+
64+
Args:
65+
optimizer (`g2o.Optimizer` object, as seen by inspecting it directly
66+
with Python's built-in `inspect` module, without further evaluation
67+
or contextualizing.): 3D object pose optimization instance, which
68+
provides the updated vertices and edges information through the
69+
`edges()` and `vertices()` methods.
70+
71+
1/ `edges`: A list of edges in the graph, where each edge is an
72+
instance of `g2o.Edge`.
73+
2/ `vertices`: A dictionary containing the positions of the
74+
vertices in the graph, where each key is a vertex index and each
75+
value is a 3D vector representing the vertex position.
76+
3/ `edges_coord`: A function that maps an edge list to a 2D list
77+
of coordinate pairs, where each pair represents a point on the edge.
78+
4/ `poses`: A list of 3D vectors representing the poses of the
79+
vertices in the graph.
80+
5/ `measurments`: A list of 2D points representing the measurements
81+
obtained from the optimizer.
82+
6/ `rotation`: An instance of `g2o.Quaternion` representing the
83+
rotation of each vertex in the graph.
84+
ground_truth (ndarray or a Python object representing a 2D numpy array
85+
containing the ground truth pose coordinates for the objects in
86+
the scene.): 3D positions of the robot's body or reference points,
87+
which are used to compare and visualize the estimated poses from
88+
the optimization process.
89+
90+
- If `ground_truth` is not `None`, it represents the ground truth
91+
data for the robot pose and measurement edges.
92+
- `ground_truth[0]` and `ground_truth[1]` denote the positions
93+
of the robot in SE(2) format, i.e., (x, y, z) where x, y, and z
94+
are the coordinates in the world frame.
95+
- `ground_truth.shape` gives the number of pose data points.
96+
97+
"""
3198
self.ax.clear()
3299
# Fijar límites de los ejes
33100
# self.ax.set_xlim([-3000, 3000]) # Por ejemplo, límites para el eje x de 0 a 10

agents/g2o_agent/src/genericworker.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,39 @@ class GenericWorker(QtWidgets.QWidget):
4545
kill = QtCore.Signal()
4646

4747
def __init__(self, mprx):
48+
"""
49+
sets up a worker object's user interface, creates a mutex for synchronization,
50+
and initializes a timer to periodically check the system status every 30
51+
seconds.
52+
53+
Args:
54+
mprx (`Ui_guiDlg`.): GUI widget used for initializing the UI of the
55+
`GenericWorker` class.
56+
57+
- `super(GenericWorker, self).__init__()` calls the constructor
58+
of the base class, which sets up the necessary objects and members.
59+
- `self.ui = Ui_guiDlg()` creates a new instance of the `Ui_guiDlg`
60+
class, which is a user interface class. The `Ui_guiDlg` object is
61+
then set as a member of the current instance using the assignment
62+
operator (`=`).
63+
- `self.ui.setupUi(self)` calls a method on the `Ui_guiDlg` class
64+
to set up the user interface for the current instance.
65+
- `self.show()` displays the user interface of the current instance.
66+
- `self.mutex = QtCore.QMutex(QtCore.QMutex.Recursive)` creates
67+
a new instance of the `QMutex` class, which is used to synchronize
68+
access to the methods of the current instance. The `QMutex.Recursive`
69+
argument specifies that the mutex should be recursive, meaning
70+
that it can be acquired and released multiple times during its lifetime.
71+
- `self.Period = 30` sets a variable called `Period` to the value
72+
30. This variable represents the interval at which the current
73+
instance will execute its timer function.
74+
- `self.timer = QtCore.QTimer(self)` creates a new instance of
75+
the `QTimer` class, which is used to schedule execution of methods
76+
on the current instance at a later time. The `QTimer` object is
77+
set as a member of the current instance using the assignment
78+
operator (`=`).
79+
80+
"""
4881
super(GenericWorker, self).__init__()
4982

5083

@@ -59,13 +92,27 @@ def __init__(self, mprx):
5992

6093
@QtCore.Slot()
6194
def killYourSelf(self):
95+
"""
96+
emits the `kill` signal, which is catchable and causes an immediate
97+
termination of the program.
98+
99+
"""
62100
rDebug("Killing myself")
63101
self.kill.emit()
64102

65103
# \brief Change compute period
66104
# @param per Period in ms
67105
@QtCore.Slot(int)
68106
def setPeriod(self, p):
107+
"""
108+
sets the ` Period ` attribute and starts a timer with the new period using
109+
the `timer.start()` method.
110+
111+
Args:
112+
p (int): new period value, which is then assigned to the instance
113+
attribute ` Period ` and used to set the timer interval.
114+
115+
"""
69116
print("Period changed", p)
70117
self.Period = p
71118
self.timer.start(self.Period)

0 commit comments

Comments
 (0)