Skip to content

Commit c40f2be

Browse files
Added comments to 5 functions across 2 files
1 parent cd17b20 commit c40f2be

2 files changed

Lines changed: 65 additions & 0 deletions

File tree

components/g2o_cpp/circle_gen.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ def add_noise(value, std_dev):
1111

1212

1313
def main():
14+
"""
15+
Generates a G2O file for a circular trajectory with noisy landmark observations,
16+
adding noise to the robot's poses, edges, and observation edges according to
17+
given standard deviations.
18+
19+
"""
1420
num_steps = 50 # Number of steps in the circle
1521
angle_step = 360/num_steps # Angle step in degrees
1622
radius = 3.0 # Radius of the circle

components/g2o_cpp/draw_circle.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,19 @@
33
import numpy as np
44

55
def parse_g2o_file(filename):
6+
"""
7+
Reads a file containing G2O data and returns two dictionaries: `poses` stores
8+
vertex positions as (x, y, theta), while `landmarks` stores the corresponding
9+
vertex indices.
10+
11+
Args:
12+
filename (str): 3D pose or Landmark file that is being parsed by the function.
13+
14+
Returns:
15+
dict: a tuple of two dictionaries: `poses` and `landmarks`, where `poses`
16+
contains 3D pose data and `landmarks` contains 2D coordinate data.
17+
18+
"""
619
poses = {}
720
landmarks = {}
821
with open(filename, 'r') as file:
@@ -23,6 +36,18 @@ def parse_g2o_file(filename):
2336

2437

2538
def read_covariances_from_file(filename):
39+
"""
40+
Reads a file containing vertex id and pairwise matrix values, and constructs
41+
a dictionary of covariance matrices for each vertex based on the read data.
42+
43+
Args:
44+
filename (str): file from which the covariances are to be read.
45+
46+
Returns:
47+
dict: a dictionary of matrices, where each matrix represents the covariance
48+
between two vertices in the graph.
49+
50+
"""
2651
covariances = {}
2752
try:
2853
with open(filename, 'r') as file:
@@ -56,6 +81,34 @@ def read_covariances_from_file(filename):
5681

5782
def plot_graph(poses, landmarks, ax, title, covariances=None, original=True):
5883
# Plot landmarks
84+
"""
85+
Plots landmarks on a map using circles and orientation lines, also plots poses
86+
with circles and orientation lines.
87+
88+
Args:
89+
poses (dict): 3D positions of the robot's end effector over time, which
90+
are plotted along with the landmarks and orientation lines to visualize
91+
the robot's motion.
92+
landmarks (dict): 2D coordinates of distinct landmarks in the robot's
93+
environment, which are used to plot circles for each landmark in the
94+
graph.
95+
ax ("Artifact" object, based on its name and how it is used within the
96+
function's code block.): 2D axis object in which the graph will be plotted.
97+
98+
- `ax`: The axis object to be used for plotting the data. It has
99+
several attributes and methods that can be used to customize the plot.
100+
- `set_xlabel()`: Sets the label for the x-axis.
101+
- `set_ylabel()`: Sets the label for the y-axis.
102+
- `set_title()`: Sets the title of the plot.
103+
- `axis('equal')`: Sets the plot layout to be equal-sized axis.
104+
title (str): title that will be displayed on the graph's axis.
105+
covariances (dict): 2D covariance matrix of landmark positions, which can
106+
be optionally plotted as ellipses around each landmark in addition to
107+
the landmarks themselves.
108+
original (bool): whether to plot original landmarks or covariance ellipses
109+
for landmarks, when `covariances` is provided as an argument to the function.
110+
111+
"""
59112
for landmark in landmarks.values():
60113
ax.plot(landmark[0], landmark[1], 'ro') # 'ro' for red circle
61114

@@ -132,6 +185,12 @@ def draw_covariance_ellipse(x, y, cov, ax):
132185

133186
def main():
134187
# Filenames for the original and optimized graphs
188+
"""
189+
1) parses two .g2o files using `parse_g2o_file()`, 2) reads covariances from
190+
a file, and 3) plots both original and optimized graphs with different labels
191+
using `plot_graph()`.
192+
193+
"""
135194
original_filename = 'circle.g2o' # Update this to your original .g2o file path
136195
optimized_filename = 'optimized_circle.g2o' # Update this to your optimized .g2o file path
137196

0 commit comments

Comments
 (0)