Skip to content

Commit ae74573

Browse files
Added comments to 31 functions across 4 files
1 parent cfadd50 commit ae74573

4 files changed

Lines changed: 506 additions & 0 deletions

File tree

agents/g2o_agent/src/specificworker.py

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,20 @@
4545

4646
class SpecificWorker(GenericWorker):
4747
def __init__(self, proxy_map, startup_check=False):
48+
"""
49+
sets up a specific worker class with a unique ID, creates an RT API object
50+
and visualizer, connects signals to handle node and edge updates, and
51+
initializes g2o graph with visualizer.
52+
53+
Args:
54+
proxy_map (dict): 2D grid of the environment, which is used to initialize
55+
the G2O graph and store the node positions for obstacle detection
56+
and mapping.
57+
startup_check (bool): initializing check to be run when the SpecificWorker
58+
is created, which may include running some additional initialization
59+
steps for the worker instance.
60+
61+
"""
4862
super(SpecificWorker, self).__init__(proxy_map)
4963
self.Period = 50
5064

@@ -95,6 +109,11 @@ def setParams(self, params):
95109
@QtCore.Slot()
96110
def compute(self):
97111

112+
"""
113+
performs computer vision-based SLAM using RT3D, computing landmarks and
114+
optimizing the pose of a robot.
115+
116+
"""
98117
if self.room_initialized:
99118
# Get robot odometry
100119
if self.odometry_queue:
@@ -154,6 +173,16 @@ def compute(self):
154173

155174
def initialize_g2o_graph(self):
156175
# get robot pose in room
176+
"""
177+
Initializes a Graph2O graph for pose estimation, given an ROS robot node
178+
and room node. It gets fixed robot pose, corner values from room node, and
179+
adds landmarks to the Graph2O graph for optimization.
180+
181+
Returns:
182+
bool: a successful initialization of the G2O graph with fixed pose
183+
added and corner landmarks detected and added to the graph.
184+
185+
"""
157186
odom_node = self.g.get_node("Shadow")
158187
self.odometry_node_id = odom_node.id
159188
room_node = self.g.get_node("room")
@@ -193,6 +222,17 @@ def initialize_g2o_graph(self):
193222
return True
194223

195224
def get_displacement(self, odometry):
225+
"""
226+
computes the total displacement, velocity, and angular displacement of an
227+
object based on its odometry data, taking into account the timestamp of
228+
each point in the sequence.
229+
230+
Args:
231+
odometry (float): 3D movement of a robot or agent, which is used to
232+
calculate the displacement, velocity, and acceleration along
233+
different axes.
234+
235+
"""
196236
desplazamiento_avance = 0
197237
desplazamiento_lateral = 0
198238
desplazamiento_angular = 0
@@ -215,6 +255,37 @@ def get_displacement(self, odometry):
215255
return desplazamiento_lateral, desplazamiento_avance, -desplazamiento_angular
216256

217257
def get_covariance_matrix(self, vertex):
258+
"""
259+
computes the covariance matrix of a given vertex in a graph using the
260+
Graph2O optimization framework and its internal optimizer. The resulting
261+
matrix is returned as a concatenation of non-diagonal elements from the
262+
upper triangle.
263+
264+
Args:
265+
vertex (G2O.Vertex object.): 2D or 3D vertex for which the covariance
266+
matrix is to be computed.
267+
268+
- `hessian_index`: An integer index representing the vertex's
269+
position in the graph.
270+
- `vertices`: A list of vertices, each representing a point in
271+
the graph.
272+
273+
Returns:
274+
`np.array`.: a matrix containing the covariance between a set of
275+
vertices in a graph.
276+
277+
1/ The return value is a matrix.
278+
2/ If the `compute_marginals` method succeeds, the returned matrix
279+
will have non-zero entries only off the diagonal, indicating a covariance
280+
matrix.
281+
3/ The upper triangle of the matrix will contain only non-zero elements
282+
below the diagonal, indicating an upper triangular matrix.
283+
4/ The resulting matrix will be a concatenation of rows from the input
284+
covariances array, where each row is a list of non-zero elements.
285+
5/ The resulting matrix will have a shape of (n, n), where n is the
286+
number of vertices in the graph.
287+
288+
"""
218289
cov_vertices = [(vertex.hessian_index(), vertex.hessian_index())]
219290
covariances, covariances_result = self.g2o.optimizer.compute_marginals(cov_vertices)
220291
if covariances_result:
@@ -234,6 +305,19 @@ def startup_check(self):
234305

235306
def update_node_att(self, id: int, attribute_names: [str]):
236307
# pass
308+
"""
309+
updates a node's attributes with information related to robot position,
310+
side speed, advance speed and timestamp, when the node id matches the
311+
odometry node id.
312+
313+
Args:
314+
id (int): identifier of the node to be updated with the odometry data,
315+
which is specifically set to the value of `self.odometry_node_id`
316+
within the function.
317+
attribute_names ([str]): list of names of attributes to be extracted
318+
from the Shadow node in the simulation.
319+
320+
"""
237321
if id == self.odometry_node_id:
238322
odom_node = self.g.get_node("Shadow")
239323
odom_attrs = odom_node.attrs
@@ -242,23 +326,74 @@ def update_node_att(self, id: int, attribute_names: [str]):
242326

243327
def update_node(self, id: int, type: str):
244328
# console.print(f"UPDATE NODE: {id} {type}", style='green')
329+
"""
330+
updates the type of a node, logging a message when doing so. If the updated
331+
type is "room," it initializes a graph if necessary.
332+
333+
Args:
334+
id (int): unique identifier of the node to be updated.
335+
type (str): type of node to be updated, with values of "room" and
336+
"node", which trigger different actions within the function.
337+
338+
"""
245339
if type == "room":
246340
if not self.room_initialized:
247341
self.room_initialized = True if self.initialize_g2o_graph() else False
248342

249343

250344
def delete_node(self, id: int):
345+
"""
346+
deletes a node with the specified `id`.
347+
348+
Args:
349+
id (int): unique identifier of the node to be deleted.
350+
351+
"""
251352
pass
252353
# console.print(f"DELETE NODE:: {id} ", style='green')
253354

254355
def update_edge(self, fr: int, to: int, type: str):
356+
"""
357+
updates an edge in a graph with given frame and type.
358+
359+
Args:
360+
fr (int): source vertex index of the edge being updated.
361+
to (int): edge being updated as a string value indicating its new type.
362+
type (str): edge type of the edge being updated in the graph.
363+
364+
"""
255365
pass
256366
# console.print(f"UPDATE EDGE: {fr} to {type}", type, style='green')
257367

258368
def update_edge_att(self, fr: int, to: int, type: str, attribute_names: [str]):
369+
"""
370+
updates the attributes of an edge based on the given values for `fr`, `to`,
371+
and `type`.
372+
373+
Args:
374+
fr (int): 1st edge to be updated in the range of [0, 2], which is used
375+
as the index for accessing the relevant attribute names from the
376+
`attribute_names` list.
377+
to (int): type of edge attribute to be updated in the graph.
378+
type (str): type of attribute that is being updated in the edge, as a
379+
string value.
380+
attribute_names ([str]): 0-based array of attribute names for the edge
381+
being updated in the given type, as denoted by the `type` parameter.
382+
383+
"""
259384
pass
260385
# console.print(f"UPDATE EDGE ATT: {fr} to {type} {attribute_names}", style='green')
261386

262387
def delete_edge(self, fr: int, to: int, type: str):
388+
"""
389+
deletes an edge in a graph based on its ID and type.
390+
391+
Args:
392+
fr (int): 0-based index of the first vertex in the edge to be deleted.
393+
to (int): 2nd node in the edge being deleted.
394+
type (str): type of edge being deleted, which is passed as a string
395+
to identify the type of edge for logging purposes.
396+
397+
"""
263398
pass
264399
# console.print(f"DELETE EDGE: {fr} to {type} {type}", style='green')

components/g2o/src/genericworker.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,29 @@ class GenericWorker(QtCore.QObject):
3939
kill = QtCore.Signal()
4040

4141
def __init__(self, mprx):
42+
"""
43+
establishes a worker object, setting up a mutex and timer for the GenericWorker
44+
class.
45+
46+
Args:
47+
mprx (`object` type as declared by its enclosing code.): Qt mutex
48+
object that provides mutual exclusion access to the worker's
49+
internal state during execution.
50+
51+
- `super(GenericWorker, self).__init__()` is called to initiate
52+
the subclassing process with the parent class ` QtCore.QObject`.
53+
- `self.mutex` is a `QtCore.QMutex` instance that provides mutual
54+
exclusivity for the function. It can be used to protect the worker's
55+
internal state during concurrent access.
56+
- `self.Period` is an integer variable that specifies the interval
57+
between the worker's execution. This interval is set to 30 in this
58+
example, but it can be changed according to the application's requirements.
59+
- `self.timer` is a `QtCore.QTimer` instance that is used to
60+
schedule the worker's execution at a later time. When `self. Period`
61+
elapses, the `timer_timeout()` method will be called automatically
62+
to initiate the worker's execution.
63+
64+
"""
4265
super(GenericWorker, self).__init__()
4366

4467

@@ -49,13 +72,29 @@ def __init__(self, mprx):
4972

5073
@QtCore.Slot()
5174
def killYourSelf(self):
75+
"""
76+
emits the `kill` signal, which is presumably used to terminate the execution
77+
of the object and any associated processes.
78+
79+
"""
5280
rDebug("Killing myself")
5381
self.kill.emit()
5482

5583
# \brief Change compute period
5684
# @param per Period in ms
5785
@QtCore.Slot(int)
5886
def setPeriod(self, p):
87+
"""
88+
sets the time interval for which the timer will run, using the provided
89+
value and updating the `Period` attribute accordingly. It then starts the
90+
timer using the new period.
91+
92+
Args:
93+
p (int): period value to be set for the object, which is then assigned
94+
to the `Period` attribute and used to start the timer with the
95+
corresponding duration.
96+
97+
"""
5998
print("Period changed", p)
6099
self.Period = p
61100
self.timer.start(self.Period)

0 commit comments

Comments
 (0)