Skip to content

Refactor module links and improve code documentation. #1211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 27 additions & 6 deletions Mapping/circle_fitting/circle_fitting.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,33 @@

def circle_fitting(x, y):
"""
Circle Fitting with least squared
input: point x-y positions
output cxe x center position
cye y center position
re radius of circle
error: prediction error
Fits a circle to a given set of points using a least-squares approach.

This function calculates the center (x, y) and radius of a circle that best fits
the given set of points in a two-dimensional plane. It minimizes the squared
errors between the circle and the provided points and returns the calculated
center coordinates, radius, and the fitting error.

Raises
------
ValueError
If the input lists x and y do not contain the same number of elements.

Parameters
----------
x : list[float]
The x-coordinates of the points.
y : list[float]
The y-coordinates of the points.

Returns
-------
tuple[float, float, float, float]
A tuple containing:
- The x-coordinate of the center of the fitted circle (float).
- The y-coordinate of the center of the fitted circle (float).
- The radius of the fitted circle (float).
- The fitting error as a deviation metric (float).
"""

sumx = sum(x)
Expand Down
27 changes: 26 additions & 1 deletion Mapping/kmeans_clustering/kmeans_clustering.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,37 @@


def kmeans_clustering(rx, ry, nc):
"""
Performs k-means clustering on the given dataset, iteratively adjusting cluster centroids
until convergence within a defined threshold or reaching the maximum number of
iterations.

The implementation initializes clusters, calculates initial centroids, and refines the
clusters through iterative updates to optimize the cost function based on minimum
distance between datapoints and centroids.

Arguments:
rx: List[float]
The x-coordinates of the dataset points to be clustered.
ry: List[float]
The y-coordinates of the dataset points to be clustered.
nc: int
The number of clusters to group the data into.

Returns:
Clusters
An instance containing the final cluster assignments and centroids after
convergence.

Raises:
None

"""
clusters = Clusters(rx, ry, nc)
clusters.calc_centroid()

pre_cost = float("inf")
for loop in range(MAX_LOOP):
print("loop:", loop)
cost = clusters.update_clusters()
clusters.calc_centroid()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def atan_zero_to_twopi(y, x):
return angle


def precasting(minx, miny, xw, yw, xyreso, yawreso):
def pre_casting(minx, miny, xw, yw, xyreso, yawreso):

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

Expand Down Expand Up @@ -81,7 +81,7 @@ def generate_ray_casting_grid_map(ox, oy, xyreso, yawreso):

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

precast = precasting(minx, miny, xw, yw, xyreso, yawreso)
precast = pre_casting(minx, miny, xw, yw, xyreso, yawreso)

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

Expand Down
4 changes: 4 additions & 0 deletions docs/modules/3_mapping/circle_fitting/circle_fitting_main.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ The red crosses are observations from a ranging sensor.

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

Code Link
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. autofunction:: Mapping.circle_fitting.circle_fitting.circle_fitting
4 changes: 2 additions & 2 deletions docs/modules/3_mapping/distance_map/distance_map_main.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ The algorithm is demonstrated on a simple 2D grid with obstacles:

.. image:: distance_map.png

API
~~~
Code Link
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. autofunction:: Mapping.DistanceMap.distance_map.compute_sdf

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,9 @@ Gaussian grid map
This is a 2D Gaussian grid mapping example.

.. image:: https://github.com/AtsushiSakai/PythonRoboticsGifs/raw/master/Mapping/gaussian_grid_map/animation.gif

Code Link
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. autofunction:: Mapping.gaussian_grid_map.gaussian_grid_map.generate_gaussian_grid_map

Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@ k-means object clustering
This is a 2D object clustering with k-means algorithm.

.. image:: https://github.com/AtsushiSakai/PythonRoboticsGifs/raw/master/Mapping/kmeans_clustering/animation.gif

Code Link
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. autofunction:: Mapping.kmeans_clustering.kmeans_clustering.kmeans_clustering

Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,9 @@ Let’s use this flood fill on real data:

.. image:: lidar_to_grid_map_tutorial_14_1.png

Code Link
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. autofunction:: Mapping.lidar_to_grid_map.lidar_to_grid_map.main


Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ This is an example of normal vector calculation:

.. figure:: normal_vector_calc.png

API
=====
Code Link
==========

.. autofunction:: Mapping.normal_vector_estimation.normal_vector_estimation.calc_normal_vector

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

.. figure:: ransac_normal_vector_estimation.png

API
=====
Code Link
==========

.. autofunction:: Mapping.normal_vector_estimation.normal_vector_estimation.ransac_normal_vector_estimation

Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ This method determines which each point is in a grid, and replaces the point
clouds that are in the same Voxel with their average to reduce the number of
points.

API
=====
Code Link
==========

.. autofunction:: Mapping.point_cloud_sampling.point_cloud_sampling.voxel_point_sampling

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

API
=====
Code Link
==========

.. autofunction:: Mapping.point_cloud_sampling.point_cloud_sampling.poisson_disk_sampling

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,9 @@ Ray casting grid map

This is a 2D ray casting grid mapping example.

.. image:: https://github.com/AtsushiSakai/PythonRoboticsGifs/raw/master/Mapping/raycasting_grid_map/animation.gif
.. image:: https://github.com/AtsushiSakai/PythonRoboticsGifs/raw/master/Mapping/raycasting_grid_map/animation.gif

Code Link
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. autofunction:: Mapping.ray_casting_grid_map.ray_casting_grid_map.generate_ray_casting_grid_map
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ This evaluation function uses the squreed distances between the edges of the rec
Calculating the squared error is the same as calculating the variance.
The smaller this variance, the more it signifies that the points fit within the rectangle.

API
~~~~~~
Code Link
~~~~~~~~~~~

.. autoclass:: Mapping.rectangle_fitting.rectangle_fitting.LShapeFitting
:members:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import conftest # Add root path to sys.path
from Mapping.raycasting_grid_map import raycasting_grid_map as m
from Mapping.ray_casting_grid_map import ray_casting_grid_map as m


def test1():
Expand Down