4545
4646class 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')
0 commit comments