swarmsim.sensors.BinaryFOVSensor#

Binary Field of View Sensor

class swarmsim.sensors.BinaryFOVSensor.BinaryFOVSensor(agent=None, parent=None, theta=10.0, distance=100.0, bias=0.0, false_positive=0.0, false_negative=0.0, walls=None, goal_sensing_range=10.0, wall_sensing_range=10.0, time_step_between_sensing=1, invert=False, store_history=False, detect_goal_with_added_state=False, show=True, seed=None, target_team=None, detect_only_origins=False, **kwargs)[source]#

A binary sensor for whether there are matching agents within the sensor’s cone of vision.

Parameters:
  • theta (float, default=10.0) – The half-angle of the sensor cone. The effective FOV is \(2 \theta\).

  • distance (float, default=100.0) – The maximum distance from the sensor to look for targets.

  • bias (float, default=0.0) – The angle offset of the sensor cone. Positive values shift the cone to the same direction as a positive turn.

  • false_positive (float, default=0.0) – The probability of a negative detection being reported as a positive detection.

  • false_negative (float, default=0.0) – The probability of a positive detection being reported as a negative detection.

  • time_step_between_sensing (int, default=1) – The number of time steps between sensory perceptions.

  • invert (bool, default=False) – Whether to invert the sensor’s output. If True, a positive detection will be reported as a negative detection, and vice versa.

  • store_history (bool, default=False) – Whether to store the history of targets.

  • show (bool, default=True) – Whether to draw the sensory vector.

  • seed (int | None, default=None) – The seed for the random number generator. If None, the parent’s RNG is used.

  • target_team (int | str | None, default=None) – The team to look for agents or objects in. If None, any team is considered.

  • detect_only_origins (bool, default=False) – Whether to only detect the origin of the agent.

Attributes:
position

Methods

as_config_dict

checkForLOSCollisions

determineState

draw

from_dict

getBiasedSightAngle

getLOSVector

getSectorVectors

get_state

line_seg_int_point

lines_segments_intersect

set_agent

set_parent

set_seed

state_pretty

step

withinRadiusExclusiveFast

DEBUG = False[source]#
as_config_dict()[source]#
checkForLOSCollisions(world: RectangularWorld) None[source]#
circle_interesect_sensing_cone(u, r)[source]#
config_vars = ['static_position', 'n_possible_states', 'show', 'theta', 'distance', 'bias', 'false_positive', 'false_negative', 'walls', 'wall_sensing_range', 'time_step_between_sensing', 'invert', 'store_history', 'detect_goal_with_added_state', 'show', 'target_team', 'seed'][source]#
determineState(real_value, agent, world=None)[source]#
draw(screen, offset=((0, 0), 1.0))[source]#
static from_dict(d)[source]#
getAARectContainingSector(world: RectangularWorld)[source]#
getBiasedSightAngle()[source]#
getLOSVector() List[source]#
getSectorVectors()[source]#
line_seg_int_point(line1, line2)[source]#
lines_segments_intersect(l1, l2)[source]#
point_orientation(p1, p2, p3)[source]#

Used in calculating Line Segment Intersection See: https://www.geeksforgeeks.org/orientation-3-ordered-points/amp/%C2%A0/ Motivation: https://www.geeksforgeeks.org/check-if-two-given-line-segments-intersect/

step(world)[source]#
withinRadiusExclusiveFast(origin, other, radius)[source]#
swarmsim.sensors.BinaryFOVSensor.vectorize(angle)[source]#

Convert an angle to a representative unit vector.

Parameters:

angle (float) – Angle in radians

Returns:

Vector

Return type:

np.ndarray

swarmsim.sensors.BinaryFOVSensor.turn(p1, p2)[source]#

Compute the vector turn value from origin→p1 to origin→p2.

This value is positive if a left turn is the fastest way to go from p1 to p2, zero if p1 and p2 are colinear, and negative otherwise

Parameters:
  • p1 (tuple | np.ndarray) – Point

  • p2 (tuple | np.ndarray) – Point

Return type:

float

swarmsim.sensors.BinaryFOVSensor.project(a, b)[source]#

Project vector a onto vector b.

Parameters:
  • a (tuple | np.ndarray) – Vector

  • b (tuple | np.ndarray) – Vector

Return type:

np.ndarray

swarmsim.sensors.BinaryFOVSensor.lineCircleIntersect(line, center, radius)[source]#

Determine if the line in the direction of the first argument intersects the circle defined by the second and third arguments.

Parameters:
  • line (tuple | np.ndarray) – Line

  • center (tuple | np.ndarray) – Center of circle

  • radius (float) – Radius of circle

Returns:

True if the line intersects the circle, False otherwise.

Return type:

bool

Functions

lineCircleIntersect(line, center, radius)

Determine if the line in the direction of the first argument intersects the circle defined by the second and third arguments.

project(a, b)

Project vector a onto vector b.

turn(p1, p2)

Compute the vector turn value from origin→p1 to origin→p2.

vectorize(angle)

Convert an angle to a representative unit vector.

Classes

BinaryFOVSensor([agent, parent, theta, ...])

A binary sensor for whether there are matching agents within the sensor's cone of vision.