src.environment.problem.MOO.UAV.utils

Module Contents

Functions

createmodel

Generates a simulation model for a drone navigation task in a terrain with threats.

generate_terrain

Generates a series of points that approximate terrain using a simple algorithm with minimal parameters.

interpolate

Introduction

  • Performs scattered 2D linear interpolation from known (x0, y0, v0) to new points (xn, yn).

  • Adds artificial boundary points to ensure smooth interpolation near edges.

API

src.environment.problem.MOO.UAV.utils.createmodel(map_size=900, r=100, rr=10, num_threats=5, rng=None)[source]

Generates a simulation model for a drone navigation task in a terrain with threats.

This function creates a synthetic terrain map and places cylindrical threats randomly. It also determines suitable start and end points for the drone, ensuring they are not in immediate collision with any threats.

Parameters:

map_size : int, optional (default=900) Size of the square terrain grid. r : float, optional (default=100) Initial roughness of the terrain. rr : float, optional (default=10) Roughness variation factor controlling terrain detail. num_threats : int, optional (default=5) Number of cylindrical threats to be placed on the map. seed : int, optional (default=3849) Random seed for reproducibility.

Returns:

model : dict A dictionary containing terrain, threat information, and start/end points:

- 'drone_size' : float
  The size of the drone.
- 'danger_dist' : float
  Minimum safety distance from threats.
- 'threats' : ndarray, shape (num_threats, 4)
  Array where each row represents a threat: `[x, y, height, radius]`.
- 'start' : ndarray, shape (3, 1)
  Start position `[x, y, z]` for the drone.
- 'end' : ndarray, shape (3, 1)
  End position `[x, y, z]` for the drone.
- 'xmin', 'xmax', 'ymin', 'ymax', 'zmin', 'zmax' : float
  Boundaries of the map.
- 'MAPSIZE_X', 'MAPSIZE_Y' : float
  Dimensions of the terrain grid.
- 'X', 'Y' : ndarray
  Meshgrid representing terrain coordinates.
- 'H' : ndarray
  Heightmap of the terrain.

Notes:

  • The threats are randomly placed with constraints ensuring they remain within bounds.

  • Start and end points are selected to avoid initial collisions with threats.

  • If no valid start/end points are found after 20 attempts, an assertion error is raised.

Example:


src.environment.problem.MOO.UAV.utils.generate_terrain(n=8, map_size=900, h0=130, r0=None, rr=None, rng=None)[source]

Generates a series of points that approximate terrain using a simple algorithm with minimal parameters.

Parameters:

n : int Number of iterations of the algorithm, controlling the level of detail. Values beyond 8 add negligible visible detail but significantly increase computation time. mesh_size : int The size of the output mesh (e.g., 512 for a 512x512 grid). h0 : float Initial elevation. r0 : float Initial roughness, determining how much terrain can vary in a step. rr : float Roughness roughness, controlling how much roughness itself can vary in a step.

Returns:

hm : ndarray 2D mesh grids useful for surface plotting.

src.environment.problem.MOO.UAV.utils.interpolate(x0, y0, v0, xn, yn)[source]

Introduction

  • Performs scattered 2D linear interpolation from known (x0, y0, v0) to new points (xn, yn).

  • Adds artificial boundary points to ensure smooth interpolation near edges.

Args

  • x0 (ndarray): Known x-coordinates.

  • y0 (ndarray): Known y-coordinates.

  • v0 (ndarray): Known values at (x0, y0).

  • xn (ndarray): New x-coordinates to interpolate.

  • yn (ndarray): New y-coordinates to interpolate.

Returns

  • v (ndarray): Interpolated values at coordinates (xn, yn), shape matches xn.