LAM package¶
Submodules¶
LAM.debug module¶
- class LAM.debug.GridPlot¶
Bases:
objectDisplay occupancy grid.
- __init__()¶
- update(grid)¶
Update occupancy grid plot.
- Parameters:
grid (numpy.ndarray) – Occupancy grid
- view(grid)¶
Create occupancy grid plot.
- Parameters:
grid (numpy.ndarray) – Occupancy grid
- class LAM.debug.Plot¶
Bases:
objectDisplay plot of estimated position.
- __init__()¶
Create plot and figure.
- _setAxes()¶
Set axis labels and layout.
- clear()¶
- plotAveragePosition(x, y)¶
- plotEstimatedPosition(x, y)¶
- plotMarkerRadius(x, y, r)¶
- plotNoisyMarkerRadius(x, y, r)¶
- updateCanvas()¶
- LAM.debug.generateTestOccupancy(size=(125, 125))¶
Create a PIL greyscale image with black circles representing randomly placed cubes and robots.
- Parameters:
size (tuple, optional) – Tuple with grid dimensions, defaults to (125, 125)
- Returns:
Greyscale occypancy grid image
- Return type:
PIL.Image.Image
LAM.localisation module¶
- class LAM.localisation.Anchor(marker, debug=False)¶
Bases:
objectA fixed point in 2D space, its distance from the robot, and bearing in radians; used for pose estimation.
- __bool__()¶
Does the anchor exist?
- Returns:
False if the anchor is not a wall or tower marker, True if it is
- Return type:
bool
- __contains__(point)¶
Check if a given point lies on or within an anchor’s range.
- Parameters:
point (tuple) – A point in the format (x,y)
- Returns:
True if the point lies on or within the radius of the anchor’s range, False if it’s outside
- Return type:
bool
- __eq__(other)¶
Compares two anchors to see if they occupy the same position in space.
Intended for use to find the mean of distances measured from a tower where two markers are visible at a time.
- Parameters:
other (localisation.Anchor) – Another anchor
- Returns:
True if the anchors’ X and Y coordinates are equal, False otherwise
- Return type:
boolean
- __init__(marker, debug=False)¶
Define new anchor from marker.
- Parameters:
marker (sr.robot3.markers.Marker) – A detected marker
- __repr__()¶
Human-readable anchor details.
- Returns:
A string containing the anchor ID, type, X-Y position, and distance
- Return type:
str
- _getMarkerCoords(id)¶
Get known coordinates for the centre of a given anchor by its ID.
- Parameters:
id (int) – Marker ID
- Returns:
X and Y coordinates, and bearing in degrees, for the anchor in the format (x,y,t)
- Return type:
tuple[int,int,int]
- _getType(id)¶
Identify anchor type by ID.
- Parameters:
id (int) – Anchor ID
- Returns:
If ID between 0 and 27 then return “wall”, if between 195 and 199 then return “tower”, otherwise None
- Return type:
str
- _markerCoords = {'0': [718, 0, 180], '1': [1436, 0, 180], '10': [5750, 2872, 270], '11': [5750, 3590, 270], '12': [5750, 4308, 270], '13': [5750, 5026, 270], '14': [5026, 5750, 0], '15': [4308, 5750, 0], '16': [3590, 5750, 0], '17': [2872, 5750, 0], '18': [2154, 5750, 0], '19': [1436, 5750, 0], '195': [2125, 2125, None], '196': [3625, 2125, None], '197': [3625, 3625, None], '198': [2125, 3625, None], '199': [2875, 2875, None], '2': [2154, 0, 180], '20': [718, 5750, 0], '21': [0, 5026, 90], '22': [0, 4308, 90], '23': [0, 3590, 90], '24': [0, 2872, 90], '25': [0, 2154, 90], '26': [0, 1436, 90], '27': [0, 718, 90], '3': [2872, 0, 180], '4': [3590, 0, 180], '5': [4308, 0, 180], '6': [5026, 0, 180], '7': [5750, 718, 270], '8': [5750, 1436, 270], '9': [5750, 2154, 270]}¶
- _markerRanges = {'tower': range(195, 200), 'wall': range(0, 28)}¶
- _resolveAnchor(type, x, y, d, orientation)¶
Correct the range of a given anchor by compensating for distance from marker face to centre.
- Parameters:
type (str) – Anchor type - one of “wall” or “tower”
x (int) – Anchor centre X coordinate
y (int) – Anchor centre Y coordinate
d (float) – Marker face range
orientation (sr.robot3.markers.Marker.orientation) – Marker orientation object
- Returns:
Returns corrected distance to anchor centre
- Return type:
_type_
- file = <_io.TextIOWrapper name='/home/runner/work/HWSF-Student-Robotics-2026/HWSF-Student-Robotics-2026/src/LAM/assets/posmarkers.json' mode='r' encoding='UTF-8'>¶
- class LAM.localisation.Localiser(robot, debug=False)¶
Bases:
objectClass for determining and tracking robot’s position in arena.
(0, 0) is in corner 0, (5750, 5750) in corner 2.
- __init__(robot, debug=False)¶
Define new localiser for robot.
- Parameters:
robot (sr.robot3) – Robot to interface with
debug (bool, optional) – Debug mode, defaults to False
- _angulate(anchors)¶
Work out bearing of robot based on observed markers.
param anchors: A list of
localisation.Anchorobjects :type anchors: list[localisation.Anchor,…] :return: Bearing :rtype: float
- _multilaterate(anchors, leastsquares=True)¶
Calculate approximate robot position using detected anchors.
- Parameters:
anchors (list[localisation.Anchor,...]) – A list of
localisation.Anchorobjectsleastsquares (bool, optional) – If True, uses least squares to calculate point of best fit for more than two anchors; otherwise, uses mean from calculating intersects of every permutation of anchors, defaults to True
- _processMarkers(markers)¶
Convert a list of markers to a list of resolved anchors.
- Parameters:
markers (list) – List of detected
sr.robot3.marker.Markerobjects- Returns:
List of
localisation.Anchorobjects- Return type:
list
- recalculate(markers)¶
- property zone¶
Current zone of the arena the robot is in.
- Parameters:
usb (bool, optional) – If True, uses the zone provided by the competition USB. Only recommended for using right after game start, defaults to False
- Raises:
ValueError – Current robot position is out of arena bounds
- Returns:
Zone number 0-3, clockwise from (0,0)
- Return type:
int
- LAM.localisation.main()¶
LAM.mapping module¶
- class LAM.mapping.Grid(span=5750, div=46)¶
Bases:
objectHandles occupancy grid.
- __init__(span=5750, div=46)¶
Create new occupancy grid with given size.
- Parameters:
span (int, optional) – The size of the graph to approximate, defaults to 5750
div (int, optional) – The size of each cell relative to the graph, defaults to 46
- Raises:
ValueError – div is not a factor of span
- _cartToGrid(coords)¶
Convert from cartesian graph coordinates to grid cell.
- Parameters:
coords (tuple[int, int]) – Graph coordinate tuple
- Returns:
Indices of containing cell
- Return type:
int, int
- _decay(factor=2)¶
Causes the probabilities in the grid to decay. Higher values decay slower, lower values decay faster. 1 remains 1 and 0 remains 0.
- Parameters:
factor (int, optional) – The decay factor, defaults to 2
- _loadFromImage(imageobject)¶
Load a greyscale PIL image into the occupancy grid, overwrites all existing cells except for ones containing a 1.
- Parameters:
imageobject (PIL.Image.Image) – PIL image object
- _newEmpty(width, height, div)¶
Creates new empty NumPy array with specified width and height, divided into div cells on each axis.
- Parameters:
width (int) – Grid width
height (int) – Grid height
div (int) – Cell size
- Returns:
NumPy zeros array
- Return type:
numpy.ndarray
- _populateStatic()¶
Populate occupancy grid with known static markers.
LAM.pathfinder module¶
- LAM.pathfinder.AStar(grid, start, goal)¶
Finds a low-cost path from start to goal in a 2D occupancy grid.
- Parameters:
grid (numpy.ndarray) – Occupancy grid
start (tuple[int, int]) – Start X and Y cell indices
goal (tuple[int, int]) – End X and Y cell indices
- Returns:
List of path cell indices
- Return type:
list[tuple[int, int], …]
- LAM.pathfinder.dijkstra(grid, start, goal)¶
Compute the shortest path between two points on a weighted 2D grid using Dijkstra’s algorithm.
- Parameters:
grid (numpy.ndarray) – Occupancy grid
start (tuple[int, int]) – Start X and Y cell indices
goal (tuple[int, int]) – End X and Y cell indices
- Returns:
List of path cell indices
- Return type:
tuple[tuple[int, int], …]
- LAM.pathfinder.inflateObstacles(grid, weight=0.75, max=10)¶
Increases the cost of cells near obstacles.
- Parameters:
grid (numpy.ndarray) – Occupancy grid
weight (float, optional) – How strongly to penalize proximity (0.0-1.0), defaults to 0.75
max (int, optional) – How far to look for obstacles (in cells), defaults to 10
- Returns:
Inflated grid
- Return type:
numpy.ndarray
- LAM.pathfinder.main()¶
- LAM.pathfinder.pathfind(grid, start, goal)¶
Find the path between a start and end point using Dijkstra’s algorithm with A* as a fallback.
- Parameters:
grid (numpy.ndarray) – Occupancy grid
start (tuple[int, int]) – Start X and Y cell indices
goal (tuple[int, int]) – End X and Y cell indices
- Raises:
RuntimeError – Both Dijkstra and A* fail or return empty
- Returns:
List of path cell indices
- Return type:
tuple[tuple[int, int], …]
- LAM.pathfinder.rdp(path, epsilon=1.0)¶
Simplify a path using Ramer-Douglas-Peucker.
- Parameters:
path (tuple[tuple[int, int], ...]) – Path to simplify
epsilon (float, optional) – Max perpendicular distance to allow, defaults to 1.0
- Returns:
Simplified path
- Return type:
tuple[tuple[int, int], …]