4848 pass
4949
5050class SpecificWorker (GenericWorker ):
51+ """
52+ Performs real-time visual odometry estimation for a robot using a G2O graph
53+ and RT communication. It initializes a graph, adds nominal corners, and updates
54+ edges with measured data from an RT communication agent.
55+
56+ Attributes:
57+ Period (float): Used to control the interval at which the worker performs
58+ its tasks, with a default value of 1 second. It can be used to adjust
59+ the worker's execution speed.
60+ agent_id (int): A unique identifier assigned to each agent in the system.
61+ g (Graph): Used for representing the graph of a robot's motion, where each
62+ node represents a pose of the robot and each edge represents a motion
63+ of the robot between two poses. The graph is used to compute the
64+ marginal probability distribution of the robot's motion given its
65+ initial position and velocity.
66+ startup_check (QTimersingleShot): Used to start a quit timer after 200
67+ milliseconds of inactivity, which allows the worker to exit gracefully
68+ when no further work is available.
69+ rt_api (str): 8 characters long. It stores a string value that represents
70+ the ROS launch file path for the RT node.
71+ inner_api (instance): Used as a reference to the inner API object, which
72+ is responsible for handling the actual work of the worker.
73+ odometry_node_id (int): 0-based index of the node representing the robot's
74+ odometry information in the graph. It is used to identify the node in
75+ the graph that represents the robot's current position and velocity.
76+ odometry_queue (3D): A queue that stores the odometry data of the robot,
77+ which is used to update the graph and calculate the robot's pose.
78+ last_odometry (3D): Used to store the last known odometry value of the
79+ robot, which is used for calculating the displacement and covariance
80+ matrix.
81+ g2o (3D): A G2O graph, which is a data structure used to represent the
82+ robot's pose in a 3D environment. It stores the information of the
83+ robot's pose in a set of nodes and edges, where each node represents
84+ a location in space and each edge represents a connection between two
85+ locations. The `g2o` attribute is used to perform optimization tasks
86+ such as finding the robot's pose that minimizes a cost function.
87+ odometry_noise_std_dev (float): Used to represent the standard deviation
88+ of odometry noise in the worker's graph. It is used in the `get_displacement`
89+ method to compute the displacement between two poses based on the
90+ odometry noise.
91+ odometry_noise_angle_std_dev (floatingpoint): 1.5 by default, which
92+ represents the standard deviation of angle noise in the odometry
93+ measurement of a robot. It affects the accuracy of the robot's positioning
94+ and movement tracking.
95+ measurement_noise_std_dev (float): 10% of the robot's minimum distance
96+ from its reference configuration to its target position, indicating
97+ the standard deviation of measurement noise in the robot's pose estimation.
98+ last_room_id (int): Used to store the previous room ID that was visited
99+ by the agent before the current room. It is updated when the agent
100+ moves to a new room, allowing the worker to detect changes in the environment.
101+ actual_room_id (int): Used to store the current room ID of the agent, which
102+ is updated when the robot moves from one room to another.
103+ elapsed (int): Used to store the time elapsed since the last call to the
104+ `startup_check` function, which is called every 0.1 seconds. It is
105+ used to determine when to quit the application.
106+ room_initialized (bool): Used to keep track of whether the current room
107+ has been initialized or not. It's set to False when a new room is
108+ entered, and True otherwise.
109+ iterations (int): Used to keep track of the number of iterations performed
110+ by the worker. It increases by one each time a new iteration is performed
111+ and can be accessed or modified from within the worker's methods.
112+ hide (str): Used to specify whether a worker should be hidden or not when
113+ multiple workers are running simultaneously.
114+ init_graph (bool): Used to indicate whether the graph has been initialized
115+ or not. It is set to True when the graph is initialized and False
116+ otherwise, allowing the worker to distinguish between initialized and
117+ uninitialized graphs.
118+ current_edge_set (bool): Used to indicate whether the current edge set has
119+ been computed or not. It is set to true when the edge set is first
120+ computed and false otherwise, so that only new computations are performed.
121+ first_rt_set (bool): Set to `True` when a new RT translation and rotation
122+ are detected, and `False` otherwise. It indicates whether the worker
123+ has received its first RT set or not.
124+ translation_to_set (3D): Used to store the translation from the robot's
125+ reference frame to the set frame.
126+ rotation_to_set (3D): Used to store the rotation of a robot's end effector
127+ relative to its base frame, which is necessary for setting the desired
128+ orientation of the robot's end effector.
129+ room_polygon (numpyarray): Used to store the coordinates of a room's
130+ boundary in a list of (x,y) tuples.
131+ initialize_g2o_graph (instance): Used to initialize a Graph2ONode graph
132+ for a specific robotic arm. It creates nodes, edges, and defines the
133+ room node, and sets up the optimization algorithm and visualization tools.
134+ rt_set_last_time (float): Used to store the last time when a RT set was
135+ set by the worker, which is used to filter out unnecessary RT sets.
136+ rt_time_min (float): Set to the minimum time between two consecutive RT
137+ sets. It is used to determine when to reset the translation and rotation
138+ values for RT tracking purposes.
139+ timer (QTimer): Used to schedule periodic updates of the graph with the
140+ current robot state. It is set to single shot every 200 milliseconds,
141+ allowing for real-time updates of the graph.
142+ compute (instance): Used to compute the marginal probability distributions
143+ of the robot's state given its current observations. It takes an
144+ argument `vertex` which is a vertex in the graph representing the
145+ robot's state, and returns a tuple containing the marginal probabilities
146+ and the Hessian matrix of the robot's state.
147+ update_node_att (update): Called when a new node with the specified id is
148+ added to the graph, or an existing node's attributes are updated. It
149+ updates the odometry queue based on the new node's attributes and sets
150+ the room initialization flag accordingly.
151+ update_edge (edge): Used to update the attributes of an edge in a graph
152+ when the edge's node types change or when a new edge is added to the
153+ graph. It sets the `rt_translation` and `rotation_euler_xyz` attributes
154+ of the edge based on the new node types.
155+ update_edge_att (attribute): Used to update the attributes of an edge in
156+ a graph. It takes the edge ID, the new value for the attribute, and
157+ the name of the attribute as input parameters.
158+
159+ """
51160 def __init__ (self , proxy_map , startup_check = False ):
161+ """
162+ Initializes a SpecificWorker instance, defining its attributes and connections
163+ to graphs, timers, and signal handlers.
164+
165+ Args:
166+ proxy_map (dict): Used to store a mapping from agent IDs to graphs.
167+ startup_check (Optionalbool): Used to check if the robot's graph has
168+ already been initialized before starting the main loop.
169+
170+ """
52171 super (SpecificWorker , self ).__init__ (proxy_map )
53172 self .Period = 50
54173
@@ -119,6 +238,13 @@ def setParams(self, params):
119238
120239 @QtCore .Slot ()
121240 def compute (self ):
241+ """
242+ Generates high-quality summaries of Java code that is given to it. It takes
243+ into account the robot's odometry, computes the translation and rotation
244+ of the robot relative to a reference frame, and adds the information to
245+ the graph. It also updates the landmark in the graph.
246+
247+ """
122248 if time .time () - self .elapsed > 1 :
123249 print ("Frame rate: " , self .iterations , " fps" )
124250 self .elapsed = time .time ()
@@ -212,6 +338,16 @@ def add_noise(self, value, std_dev):
212338 return value + np .random .normal (0 , std_dev )
213339
214340 def initialize_g2o_graph (self ):
341+ """
342+ Initializes a Graph2O graph for a specific robot and room, adding nominal
343+ corners and measuring them to create a polygonal representation of the
344+ room. It also sets the robot's initial position and orientation in the graph.
345+
346+ Returns:
347+ bool: 1 if the g2o graph was successfully initialized with the given
348+ room id, and 0 otherwise.
349+
350+ """
215351 print ("Initializing g2o graph" )
216352 room_nodes = [node for node in self .g .get_nodes_by_type ("room" ) if self .g .get_edge (node .id , node .id , "current" )]
217353 if len (room_nodes ) > 0 :
@@ -283,6 +419,20 @@ def initialize_g2o_graph(self):
283419 return False
284420
285421 def get_displacement (self , odometry ):
422+ """
423+ Calculates the displacement of a robot based on its odometry data, updating
424+ the robot's position and orientation using the lateral, angular, and linear
425+ displacements.
426+
427+ Args:
428+ odometry (stdvectordouble): 3D vector representing the robot's position,
429+ orientation, and velocity at a given time stamp.
430+
431+ Returns:
432+ triplet: 3 elements long (desplazamiento lateral, displacement avance
433+ and angular displacement).
434+
435+ """
286436 desplazamiento_avance = 0
287437 desplazamiento_lateral = 0
288438 desplazamiento_angular = 0
@@ -302,6 +452,21 @@ def get_displacement(self, odometry):
302452 return desplazamiento_lateral , desplazamiento_avance , desplazamiento_angular
303453
304454 def get_covariance_matrix (self , vertex ):
455+ """
456+ Computes the covariance matrix of a set of vertices in a graph using the
457+ G2O optimization algorithm. It takes a vertex as input, returns the computed
458+ covariance matrix and a result flag indicating whether the computation was
459+ successful.
460+
461+ Args:
462+ vertex (g2oVertex): Passed to compute marginals for computing covariance
463+ matrix.
464+
465+ Returns:
466+ tuple: 2-element, containing the result of computing covariance matrix
467+ and the marginals of the vertices.
468+
469+ """
305470 cov_vertices = [(vertex .hessian_index (), vertex .hessian_index ())]
306471 covariances , covariances_result = self .g2o .optimizer .compute_marginals (cov_vertices )
307472 if covariances_result :
@@ -315,6 +480,15 @@ def get_covariance_matrix(self, vertex):
315480 return (covariances_result , None )
316481
317482 def visualize_g2o_realtime (self , optimizer ):
483+ """
484+ Visualizes a G2O optimization problem in real-time, loading the problem
485+ from an file and plotting the vertices and edges as 3D scatter plots while
486+ updating the display with small intervals of time.
487+
488+ Args:
489+ optimizer (instance): Used to load G2O files for visualization in real-time.
490+
491+ """
318492 plt .ion ()
319493 fig = plt .figure ()
320494 ax = fig .add_subplot (111 , projection = '3d' )
@@ -360,6 +534,16 @@ def update_node_att(self, id: int, attribute_names: [str]):
360534 # # self.init_graph = True
361535 # print("INIT GRAPH")
362536
537+ """
538+ Updates the attributes of a node in a graph, specifically the `odometry_queue`
539+ attribute, when the node's ID matches the `odometry_node_id`.
540+
541+ Args:
542+ id (int): Used to identify the node for which attribute values are
543+ being updated.
544+ attribute_names ([str]): A list of attribute names to update in the node.
545+
546+ """
363547 if id == self .odometry_node_id :
364548 odom_node = self .g .get_node ("Shadow" )
365549 odom_attrs = odom_node .attrs
@@ -377,9 +561,24 @@ def update_node(self, id: int, type: str):
377561 # if not self.room_initialized:
378562 # self.room_initialized = True if self.initialize_g2o_graph() else False
379563 # self.init_graph = True
564+ """
565+ Updates the node with the specified ID, based on the type of node it represents.
566+
567+ Args:
568+ id (int): Used to identify the node being updated.
569+ type (str): Used to specify the node type.
570+
571+ """
380572 pass
381573
382574 def delete_node (self , id : int ):
575+ """
576+ Deletes a node from the graph represented by the `SpecificWorker` class.
577+
578+ Args:
579+ id (int): Used to identify the node to be deleted.
580+
581+ """
383582 pass
384583 # if type == "room":
385584 # # TODO: reset graph and wait until new room appears
@@ -389,6 +588,17 @@ def delete_node(self, id: int):
389588 # console.print(f"DELETE NODE:: {id} ", style='green')
390589
391590 def update_edge (self , fr : int , to : int , type : str ):
591+ """
592+ Updates the room ID and sets the current edge set based on the provided
593+ edge type and node types.
594+
595+ Args:
596+ fr (int): Representative of the start node of an edge in a graph.
597+ to (int): Used to represent the target node of an edge in the graph.
598+ type (str): Used to specify the type of edge to update, either "current"
599+ or "RT".
600+
601+ """
392602 if type == "current" and self .g .get_node (fr ).type == "room" :
393603 self .room_initialized = False
394604 # Get number after last "_" in room name
@@ -417,5 +627,17 @@ def update_edge_att(self, fr: int, to: int, type: str, attribute_names: [str]):
417627
418628
419629 def delete_edge (self , fr : int , to : int , type : str ):
630+ """
631+ Deletes an edge from a graph, specified by the vertex indices `fr` and
632+ `to`, and the edge type.
633+
634+ Args:
635+ fr (int): Used to represent the starting vertex index of an edge to
636+ be deleted.
637+ to (int): Used to indicate the destination node ID for edge deletion.
638+ type (str): Used to specify the edge type to be deleted, with possible
639+ values 'in' or 'out'.
640+
641+ """
420642 pass
421643 # console.print(f"DELETE EDGE: {fr} to {type} {type}", style='green')
0 commit comments