Skip to content

Commit 5392fcf

Browse files
authored
Refactor module links and improve code documentation. (#1211)
* Refactor module links and improve code documentation. Updated documentation to rename "API" sections to "Code Link" for clarity and consistency. Enhanced docstrings for `circle_fitting` and `kmeans_clustering` functions, improving parameter descriptions and adding return value details. Fixed typos in function and file names in the ray casting grid map module. * Fix import typo in ray casting grid map test module. Corrected the import statement in the test file by updating the module's name to `ray_casting_grid_map` for consistency with the source file. This ensures proper functionality of the test suite.
1 parent 22cbee4 commit 5392fcf

File tree

13 files changed

+96
-23
lines changed

13 files changed

+96
-23
lines changed

Mapping/circle_fitting/circle_fitting.py

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,33 @@
1616

1717
def circle_fitting(x, y):
1818
"""
19-
Circle Fitting with least squared
20-
input: point x-y positions
21-
output cxe x center position
22-
cye y center position
23-
re radius of circle
24-
error: prediction error
19+
Fits a circle to a given set of points using a least-squares approach.
20+
21+
This function calculates the center (x, y) and radius of a circle that best fits
22+
the given set of points in a two-dimensional plane. It minimizes the squared
23+
errors between the circle and the provided points and returns the calculated
24+
center coordinates, radius, and the fitting error.
25+
26+
Raises
27+
------
28+
ValueError
29+
If the input lists x and y do not contain the same number of elements.
30+
31+
Parameters
32+
----------
33+
x : list[float]
34+
The x-coordinates of the points.
35+
y : list[float]
36+
The y-coordinates of the points.
37+
38+
Returns
39+
-------
40+
tuple[float, float, float, float]
41+
A tuple containing:
42+
- The x-coordinate of the center of the fitted circle (float).
43+
- The y-coordinate of the center of the fitted circle (float).
44+
- The radius of the fitted circle (float).
45+
- The fitting error as a deviation metric (float).
2546
"""
2647

2748
sumx = sum(x)

Mapping/kmeans_clustering/kmeans_clustering.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,37 @@
1717

1818

1919
def kmeans_clustering(rx, ry, nc):
20+
"""
21+
Performs k-means clustering on the given dataset, iteratively adjusting cluster centroids
22+
until convergence within a defined threshold or reaching the maximum number of
23+
iterations.
24+
25+
The implementation initializes clusters, calculates initial centroids, and refines the
26+
clusters through iterative updates to optimize the cost function based on minimum
27+
distance between datapoints and centroids.
28+
29+
Arguments:
30+
rx: List[float]
31+
The x-coordinates of the dataset points to be clustered.
32+
ry: List[float]
33+
The y-coordinates of the dataset points to be clustered.
34+
nc: int
35+
The number of clusters to group the data into.
36+
37+
Returns:
38+
Clusters
39+
An instance containing the final cluster assignments and centroids after
40+
convergence.
41+
42+
Raises:
43+
None
44+
45+
"""
2046
clusters = Clusters(rx, ry, nc)
2147
clusters.calc_centroid()
2248

2349
pre_cost = float("inf")
2450
for loop in range(MAX_LOOP):
25-
print("loop:", loop)
2651
cost = clusters.update_clusters()
2752
clusters.calc_centroid()
2853

Mapping/raycasting_grid_map/raycasting_grid_map.py renamed to Mapping/ray_casting_grid_map/ray_casting_grid_map.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def atan_zero_to_twopi(y, x):
4848
return angle
4949

5050

51-
def precasting(minx, miny, xw, yw, xyreso, yawreso):
51+
def pre_casting(minx, miny, xw, yw, xyreso, yawreso):
5252

5353
precast = [[] for i in range(int(round((math.pi * 2.0) / yawreso)) + 1)]
5454

@@ -81,7 +81,7 @@ def generate_ray_casting_grid_map(ox, oy, xyreso, yawreso):
8181

8282
pmap = [[0.0 for i in range(yw)] for i in range(xw)]
8383

84-
precast = precasting(minx, miny, xw, yw, xyreso, yawreso)
84+
precast = pre_casting(minx, miny, xw, yw, xyreso, yawreso)
8585

8686
for (x, y) in zip(ox, oy):
8787

docs/modules/3_mapping/circle_fitting/circle_fitting_main.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@ The red crosses are observations from a ranging sensor.
1111

1212
The red circle is the estimated object shape using circle fitting.
1313

14+
Code Link
15+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16+
17+
.. autofunction:: Mapping.circle_fitting.circle_fitting.circle_fitting

docs/modules/3_mapping/distance_map/distance_map_main.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ The algorithm is demonstrated on a simple 2D grid with obstacles:
1414

1515
.. image:: distance_map.png
1616

17-
API
18-
~~~
17+
Code Link
18+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1919

2020
.. autofunction:: Mapping.DistanceMap.distance_map.compute_sdf
2121

docs/modules/3_mapping/gaussian_grid_map/gaussian_grid_map_main.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,9 @@ Gaussian grid map
66
This is a 2D Gaussian grid mapping example.
77

88
.. image:: https://github.com/AtsushiSakai/PythonRoboticsGifs/raw/master/Mapping/gaussian_grid_map/animation.gif
9+
10+
Code Link
11+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
13+
.. autofunction:: Mapping.gaussian_grid_map.gaussian_grid_map.generate_gaussian_grid_map
14+

docs/modules/3_mapping/k_means_object_clustering/k_means_object_clustering_main.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,9 @@ k-means object clustering
44
This is a 2D object clustering with k-means algorithm.
55

66
.. image:: https://github.com/AtsushiSakai/PythonRoboticsGifs/raw/master/Mapping/kmeans_clustering/animation.gif
7+
8+
Code Link
9+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10+
11+
.. autofunction:: Mapping.kmeans_clustering.kmeans_clustering.kmeans_clustering
12+

docs/modules/3_mapping/lidar_to_grid_map_tutorial/lidar_to_grid_map_tutorial_main.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,3 +196,9 @@ Let’s use this flood fill on real data:
196196
197197
.. image:: lidar_to_grid_map_tutorial_14_1.png
198198

199+
Code Link
200+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
201+
202+
.. autofunction:: Mapping.lidar_to_grid_map.lidar_to_grid_map.main
203+
204+

docs/modules/3_mapping/normal_vector_estimation/normal_vector_estimation_main.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ This is an example of normal vector calculation:
2525

2626
.. figure:: normal_vector_calc.png
2727

28-
API
29-
=====
28+
Code Link
29+
==========
3030

3131
.. autofunction:: Mapping.normal_vector_estimation.normal_vector_estimation.calc_normal_vector
3232

@@ -67,8 +67,8 @@ This is an example of RANSAC based normal vector estimation:
6767

6868
.. figure:: ransac_normal_vector_estimation.png
6969

70-
API
71-
=====
70+
Code Link
71+
==========
7272

7373
.. autofunction:: Mapping.normal_vector_estimation.normal_vector_estimation.ransac_normal_vector_estimation
7474

docs/modules/3_mapping/point_cloud_sampling/point_cloud_sampling_main.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ This method determines which each point is in a grid, and replaces the point
2727
clouds that are in the same Voxel with their average to reduce the number of
2828
points.
2929

30-
API
31-
=====
30+
Code Link
31+
==========
3232

3333
.. autofunction:: Mapping.point_cloud_sampling.point_cloud_sampling.voxel_point_sampling
3434

@@ -61,8 +61,8 @@ Although this method does not have good performance comparing the Farthest
6161
distance sample where each point is distributed farther from each other,
6262
this is suitable for real-time processing because of its fast computation time.
6363

64-
API
65-
=====
64+
Code Link
65+
==========
6666

6767
.. autofunction:: Mapping.point_cloud_sampling.point_cloud_sampling.poisson_disk_sampling
6868

0 commit comments

Comments
 (0)