Skip to content
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
41 changes: 34 additions & 7 deletions docs/modules/12_appendix/internal_sensors_main.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,59 @@
Internal Sensors for Robots
============================

This project, `PythonRobotics`, focuses on algorithms, so hardware is not included.
However, having basic knowledge of hardware in robotics is also important for understanding algorithms.
Therefore, we will provide an overview.
This project, `PythonRobotics`, focuses on algorithms, so hardware is not included. However, having basic knowledge of hardware in robotics is also important for understanding algorithms. Therefore, we will provide an overview.

Introduction
------------
-------------

In robotic systems, internal sensors play a crucial role in monitoring the robot’s internal state, such as orientation, acceleration, angular velocity, altitude, and temperature. These sensors provide essential feedback that supports control, localization, and safety mechanisms. While external sensors perceive the environment, internal sensors give the robot self-awareness of its own motion and condition. Understanding the principles and characteristics of these sensors is vital to fully utilize their information within algorithms and decision-making systems. This section outlines the main internal sensors used in robotics.

Global Navigation Satellite System (GNSS)
-------------------------------------------
-----------------------------------------

GNSS is a satellite-based navigation system that provides global positioning and time information by analyzing signals from multiple satellites. It is commonly used in outdoor environments for absolute positioning. Although GNSS offers global coverage without infrastructure dependency, its performance is limited indoors or in obstructed areas, and it suffers from low update rates and susceptibility to signal noise. It is widely used in outdoor navigation for drones, vehicles, and delivery robots.

Gyroscope
----------

A gyroscope measures angular velocity around the robot’s axes, enabling orientation and attitude estimation through detection of the Coriolis effect. Gyroscopes are compact, cost-effective, and provide high update rates, but they are prone to drift and require calibration or sensor fusion for long-term accuracy. These sensors are essential in drones, balancing robots, and IMU-based systems for motion tracking.

Accelerometer
--------------
---------------

An accelerometer measures linear acceleration along one or more axes, typically by detecting mass displacement due to motion. It is small, affordable, and useful for detecting movement, tilt, or vibration. However, accelerometers are limited by noisy output and cannot independently determine position without integration and fusion. They are commonly applied in wearable robotics, step counters, and vibration sensing.

Magnetometer
--------------

A magnetometer measures the direction and intensity of magnetic fields, enabling heading estimation based on Earth’s magnetic field. It is lightweight and useful for orientation, especially in GPS-denied environments, though it is sensitive to interference from electronics and requires calibration. Magnetometers are often used in conjunction with IMUs for navigation and directional awareness.

Inertial Measurement Unit (IMU)
--------------------------------

An IMU integrates a gyroscope, accelerometer, and sometimes a magnetometer to estimate a robot's motion and orientation through sensor fusion techniques such as Kalman filters. IMUs are compact and provide high-frequency data, which is essential for localization and navigation in GPS-denied areas. Nonetheless, they accumulate drift over time and require complex filtering to maintain accuracy. IMUs are found in drones, mobile robots, and motion tracking systems.

Pressure Sensor
-----------------
----------------

Pressure sensors detect atmospheric or fluid pressure by measuring the force exerted on a diaphragm. They are effective for estimating altitude and monitoring environmental conditions, especially in drones and underwater robots. Although cost-effective and efficient, their accuracy may degrade due to temperature variation and limitations in low-altitude resolution.

Temperature Sensor
--------------------

Temperature sensors monitor environmental or internal component temperatures, using changes in resistance or voltage depending on sensor type (e.g., RTD or thermocouple). They are simple and reliable for safety and thermal regulation, though they may respond slowly and be affected by nearby electronics. Common applications include battery and motor monitoring, safety systems, and ambient sensing.

References
----------

- *Introduction to Autonomous Mobile Robots*, Roland Siegwart, Illah Nourbakhsh, Davide Scaramuzza
- *Probabilistic Robotics*, Sebastian Thrun, Wolfram Burgard, Dieter Fox
- Wikipedia articles:

- `Inertial Measurement Unit (IMU) <https://en.wikipedia.org/wiki/Inertial_measurement_unit>`_
- `Accelerometer <https://en.wikipedia.org/wiki/Accelerometer>`_
- `Gyroscope <https://en.wikipedia.org/wiki/Gyroscope>`_
- `Magnetometer <https://en.wikipedia.org/wiki/Magnetometer>`_
- `Pressure sensor <https://en.wikipedia.org/wiki/Pressure_sensor>`_
- `Temperature sensor <https://en.wikipedia.org/wiki/Thermometer>`_
- `Adafruit Sensor Guides <https://learn.adafruit.com/>`_
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
Loading