Skip to content

BaseMap

src.python_motion_planning.common.env.map.base_map.BaseMap

Bases: ABC

Base class for Path Planning Map.

Parameters:

Name Type Description Default
bounds Iterable

The size of map in the world (shape: (n, 2) (n>=2)). bounds[i, 0] means the lower bound of the world in the i-th dimension. bounds[i, 1] means the upper bound of the world in the i-th dimension.

required
dtype dtype

data type of coordinates

required
Source code in src\python_motion_planning\common\env\map\base_map.py
Python
class BaseMap(ABC):
    """
    Base class for Path Planning Map.

    Args:
        bounds: The size of map in the world (shape: (n, 2) (n>=2)). bounds[i, 0] means the lower bound of the world in the i-th dimension. bounds[i, 1] means the upper bound of the world in the i-th dimension.  
        dtype: data type of coordinates
    """
    def __init__(self, bounds: Iterable, dtype: np.dtype) -> None:
        super().__init__()
        self._bounds = np.asarray(bounds, dtype=float)
        self._dtype = dtype

        if len(self._bounds.shape) != 2 or self._bounds.shape[0] <= 1 or self._bounds.shape[1] != 2:
            raise ValueError(f"The shape of bounds must be (n, 2) (n>=2) instead of {self._bounds.shape}")

        for d in range(self._bounds.shape[0]):
            if self._bounds[d, 0] >= self._bounds[d, 1]:
                raise ValueError(f"The lower bound of the world in the {d}-th dimension must be smaller than the upper bound of the world in the {d}-th dimension.")

    @property
    def bounds(self) -> np.ndarray:
        return self._bounds

    @property
    def dim(self) -> int:
        return self._bounds.shape[0]

    @property
    def dtype(self) -> np.dtype:
        return self._dtype

    @abstractmethod
    def map_to_world(self, point: tuple) -> tuple:
        """
        Convert map coordinates to world coordinates.

        Args:
            point: Point in map coordinates.

        Returns:
            point: Point in world coordinates.
        """
        pass

    @abstractmethod
    def world_to_map(self, point: tuple) -> tuple:
        """
        Convert world coordinates to map coordinates.

        Args:
            point: Point in world coordinates.

        Returns:
            point: Point in map coordinates.
        """
        pass

    @abstractmethod
    def get_distance(self, p1: tuple, p2: tuple) -> float:
        """
        Get the distance between two points.

        Args:
            p1: First point.
            p2: Second point.

        Returns:
            dist: Distance between two points.
        """
        pass

    @abstractmethod
    def get_neighbors(self, node: Node) -> list:
        """
        Get neighbor nodes of a given node.

        Args:
            node: Node to get neighbor nodes.

        Returns:
            nodes: List of neighbor nodes.
        """
        pass

    @abstractmethod
    def is_expandable(self, point: tuple) -> bool:
        """
        Check if a point is expandable.

        Args:
            point: Point to check.

        Returns:
            expandable: True if the point is expandable, False otherwise.
        """
        pass

    @abstractmethod
    def in_collision(self, p1: tuple, p2: tuple) -> bool:
        """
        Check if the line of sight between two points is in collision.

        Args:
            p1: Start point of the line.
            p2: End point of the line.

        Returns:
            in_collision: True if the line of sight is in collision, False otherwise.
        """
        pass

get_distance(p1, p2) abstractmethod

Get the distance between two points.

Parameters:

Name Type Description Default
p1 tuple

First point.

required
p2 tuple

Second point.

required

Returns:

Name Type Description
dist float

Distance between two points.

Source code in src\python_motion_planning\common\env\map\base_map.py
Python
@abstractmethod
def get_distance(self, p1: tuple, p2: tuple) -> float:
    """
    Get the distance between two points.

    Args:
        p1: First point.
        p2: Second point.

    Returns:
        dist: Distance between two points.
    """
    pass

get_neighbors(node) abstractmethod

Get neighbor nodes of a given node.

Parameters:

Name Type Description Default
node Node

Node to get neighbor nodes.

required

Returns:

Name Type Description
nodes list

List of neighbor nodes.

Source code in src\python_motion_planning\common\env\map\base_map.py
Python
@abstractmethod
def get_neighbors(self, node: Node) -> list:
    """
    Get neighbor nodes of a given node.

    Args:
        node: Node to get neighbor nodes.

    Returns:
        nodes: List of neighbor nodes.
    """
    pass

in_collision(p1, p2) abstractmethod

Check if the line of sight between two points is in collision.

Parameters:

Name Type Description Default
p1 tuple

Start point of the line.

required
p2 tuple

End point of the line.

required

Returns:

Name Type Description
in_collision bool

True if the line of sight is in collision, False otherwise.

Source code in src\python_motion_planning\common\env\map\base_map.py
Python
@abstractmethod
def in_collision(self, p1: tuple, p2: tuple) -> bool:
    """
    Check if the line of sight between two points is in collision.

    Args:
        p1: Start point of the line.
        p2: End point of the line.

    Returns:
        in_collision: True if the line of sight is in collision, False otherwise.
    """
    pass

is_expandable(point) abstractmethod

Check if a point is expandable.

Parameters:

Name Type Description Default
point tuple

Point to check.

required

Returns:

Name Type Description
expandable bool

True if the point is expandable, False otherwise.

Source code in src\python_motion_planning\common\env\map\base_map.py
Python
@abstractmethod
def is_expandable(self, point: tuple) -> bool:
    """
    Check if a point is expandable.

    Args:
        point: Point to check.

    Returns:
        expandable: True if the point is expandable, False otherwise.
    """
    pass

map_to_world(point) abstractmethod

Convert map coordinates to world coordinates.

Parameters:

Name Type Description Default
point tuple

Point in map coordinates.

required

Returns:

Name Type Description
point tuple

Point in world coordinates.

Source code in src\python_motion_planning\common\env\map\base_map.py
Python
@abstractmethod
def map_to_world(self, point: tuple) -> tuple:
    """
    Convert map coordinates to world coordinates.

    Args:
        point: Point in map coordinates.

    Returns:
        point: Point in world coordinates.
    """
    pass

world_to_map(point) abstractmethod

Convert world coordinates to map coordinates.

Parameters:

Name Type Description Default
point tuple

Point in world coordinates.

required

Returns:

Name Type Description
point tuple

Point in map coordinates.

Source code in src\python_motion_planning\common\env\map\base_map.py
Python
@abstractmethod
def world_to_map(self, point: tuple) -> tuple:
    """
    Convert world coordinates to map coordinates.

    Args:
        point: Point in world coordinates.

    Returns:
        point: Point in map coordinates.
    """
    pass