pymavswarm.safety package#

Submodules#

pymavswarm.safety.hyperrectangle module#

class pymavswarm.safety.hyperrectangle.HyperRectangle(intervals: list[pymavswarm.safety.interval.Interval])#

Bases: object

Orthotope used for computing reachable drone states.

contains(inside: HyperRectangle) bool#

Determine if this hyperrectangle contains the given hyperrectangle.

Parameters

inside (HyperRectangle) – hyperrectangle to check for containment

Raises

ValueError – dimensions of the hyperrectangles do not match

Returns

inside is contained by this hyperrectangle

Return type

bool

convex_hull(rect: HyperRectangle, in_place: bool = True) pymavswarm.safety.hyperrectangle.HyperRectangle | None#

Compute the convex hull of this rectangle and another rectangle.

Parameters
  • rect (HyperRectangle) – rectangle to compute the convex hull with

  • in_place (bool, optional) – compute the hull in place, defaults to True

Raises

ValueError – dimensions of the containing rectangle don’t match the dimensions of this rectangle

Returns

convex hull if not computed in place

Return type

HyperRectangle | None

property dimensions: int#

Total number of dimensions in the hyperrectangle.

Returns

dimensions

Return type

int

property faces: int#

Total number of faces in the hyperrectangle.

Returns

number of faces

Return type

int

intersects(rect: HyperRectangle, dimensions: Optional[list[int]] = None) bool#

Check if this rectangle intersects another rectangle.

Parameters
  • rect (HyperRectangle) – rectangle to check for intersection with

  • dimensions (list[int], optional) – dimensions to check for intersection; leave as None for all dimensions, defaults to None

Raises

ValueError – rectangle dimensions do not match

Returns

the two rectangles intersect

Return type

bool

property intervals: list[pymavswarm.safety.interval.Interval]#

Intervals in the hyperrectangle.

Returns

intervals

Return type

list[Interval]

property max_width: float#

Get the maximum interval width.

Returns

maximum distance between the intervals

Return type

float

pymavswarm.safety.interval module#

class pymavswarm.safety.interval.Interval(interval_min: float, interval_max: float)#

Bases: object

Interval used for a HyperRectangle face.

property interval_max: float#

Maximum interval value.

Returns

interval maximum

Return type

float

property interval_min: float#

Minimum value in the interval.

Returns

interval minimum

Return type

float

pymavswarm.safety.safety_checker module#

class pymavswarm.safety.safety_checker.SafetyChecker#

Bases: object

Real-time reachability analysis for collision prevention.

This implementation is inspired by the following source:

Tran, H. D., Nguyen, L. V., Musau, P., Xiang, W., & Johnson, T. T. (2019, June). Decentralized real-time safety verification for distributed cyber-physical systems. In International Conference on Formal Techniques for Distributed Objects, Components, and Systems (pp. 261-277). Springer, Cham.

static compute_derivative_bounds(rect: HyperRectangle, face: int, acceleration: tuple[float, float, float]) float#

Compute position bounds using simplified quadrotor motion dynamics.

The dynamics of the system are modeled as a double integrator where:

  • q_{double_overdot} = u(t)

  • y = q(t)

with the state vector x(t) = [q, q_{overdot}], where q is the drone position (x, y, z) and q_{overdot} is the velocity of the agent (vx, vy, vz) [m/s].

Parameters
  • rect (HyperRectangle) – rectangle that should be used to compute the face derivative

  • face (int) – face who’s derivative should be computed

  • acceleration (tuple[float, float, float]) – control signal; current acceleration of the agent [m/s^2]

Returns

derivative of the current face

Return type

float

static face_lifting_iterative_improvement(rect: HyperRectangle, start_time: float, acceleration: tuple[float, float, float], reach_time: float, initial_step_size: float = 0.01, timeout: float = 0.01, min_step_size: float = 1e-07) tuple[pymavswarm.safety.hyperrectangle.HyperRectangle, float]#

Perform iterative face lifting to compute the reachable state.

Parameters
  • rect (HyperRectangle) – initial state of the agent that sent the position message

  • start_time (float) – estimated time since boot of the agent that sent the message in the global clock [ms]

  • acceleration (tuple[float, float, float]) – acceleration [m/s^2] of the agent that sent the position message

  • reach_time (float, optional) – maximum reach time [s], defaults to 2.0

  • initial_step_size (float, optional) – step size to start the algorithm with, defaults to 0.01

  • timeout (float, optional) – maximum time to execute the face lifting algorithm [s], defaults to 0.01

  • min_step_size (float, optional) – minimum step size to allow before automatically cancelling the algorithm’s execution, defaults to 0.0000001

Returns

reachable set, time in the global clock that the algorithm has computed forward to

Return type

tuple[HyperRectangle, float]

static make_neighborhood_rectangle(original: HyperRectangle, bloated: HyperRectangle, face: int, neighborhood_width: float) HyperRectangle#

Create a face’s neighborhood given a target width.

Parameters
  • original (HyperRectangle) – initial rectangle to

  • bloated (HyperRectangle) – rectangle that should be used to create the neighborhood

  • face (int) – face who’s neighborhood should be created

  • neighborhood_width (float) – width of the neighborhood

Returns

neighborhood hyperrectangle

Return type

HyperRectangle

static single_face_lift(rect: HyperRectangle, acceleration: tuple[float, float, float], step_size: float, time_remaining: float) tuple[pymavswarm.safety.hyperrectangle.HyperRectangle, float]#

Perform a single face lifting operation.

Parameters
  • rect (HyperRectangle) – hyperrectangle that the face lifting operation should be applied to

  • acceleration (tuple[float, float, float]) – current acceleration of the agent [m/s^2]

  • step_size (float) – scale to apply to the derivative

  • time_remaining (float) – amount of time left to perform the face lift

Raises
  • RuntimeError – minimum neighborhood cross time is less than half of the step size

  • RuntimeError – lifted rectangle is outside of the bloated rectangle

Returns

lifted rectangle, elapsed reach time

Return type

tuple[HyperRectangle, float]

Module contents#