s6.utils.waypoint_utilsΒΆ
Waypoint parsing and two-axis path generation utilities.
This module provides:
WaypointUtilsto parse waypoints from simple text or JSONL files.PathDriverto drive two robotic axes via the REST API client (s6.robotic.client.RoboticClient) and generate common motion patterns (grid, square spiral, circular spiral, random micro-steps).
All distances and offsets are expressed in axis distance units (e.g., mm)
as used by s6.robotic.stepper. Generators yield
s6.schema.primitives.Vector2D where indicated.
- class s6.utils.waypoint_utils.WaypointUtils
Bases:
objectParse waypoint files in plain-text or JSONL formats.
Each waypoint is a pair
(x, y)representing a 2D offset/position.- classmethod parse_txt(file_path: str) List[Tuple[float, float]]
Parse a whitespace/comma-delimited text file of
x ypairs.Each non-empty, non-comment line contains two numbers separated by whitespace or a comma. Lines beginning with
#and empty lines are ignored.- Parameters:
file_path (str) β Path to a text file.
- Returns:
Sequence of
(x, y)pairs.- Return type:
list of tuple[float, float]
- Raises:
ValueError β If a line has invalid format or non-numeric values.
- classmethod parse_jsonl(file_path: str) List[Tuple[float, float]]
Parse a JSONL file of objects with
{"x": ..., "y": ...}.Empty lines are ignored. Each line must parse to a JSON object with numeric
xandyfields.- Parameters:
file_path (str) β Path to a JSON lines file.
- Returns:
Sequence of
(x, y)pairs.- Return type:
list of tuple[float, float]
- Raises:
ValueError β If a line cannot be parsed as JSON or lacks required fields.
- classmethod parse_file(file_path: str) List[Tuple[float, float]]
Parse a waypoint file by extension.
- Parameters:
file_path (str) β Path to a file ending with
.txtor.jsonl.- Returns:
Sequence of
(x, y)pairs.- Return type:
list of tuple[float, float]
- Raises:
ValueError β If the file extension is not supported.
- class s6.utils.waypoint_utils.PathDriver(rpc_host: str = '10.20.0.2', rpc_port: int = 8000)
Bases:
objectHigh-level two-axis driver for grid/spiral/random patterns.
Uses
s6.robotic.client.RoboticClientto send motion commands to the running REST API. Maintains a simple internal target position used as the origin for relative patterns.- property current: Tuple[float, float]
Return the current target coordinates
(x, y)in axis units.
- move(x: float, y: float) None
Move to an absolute position by zeroing then applying offsets.
- Parameters:
x (float) β Target coordinates in axis distance units. Values are rounded to integers for the underlying client calls.
y (float) β Target coordinates in axis distance units. Values are rounded to integers for the underlying client calls.
- zero() None
Zero both axes and reset the internal position to
(0, 0).
- to_waypoint(name: str) None
Move to a named waypoint defined in configuration.
- Parameters:
name (str) β Waypoint identifier. The internal
currentis not modified.
- grid(nx: int, ny: int, dx: float, dy: float)
Yield a grid sweep of
nx Γ nypoints, spaced bydx, dy.Starting at the current position, this generates a serpentine scan over a rectangle centered at the origin of the grid. Motion commands are relative; axes are not zeroed.
- Parameters:
nx (int) β Number of samples along x and y.
ny (int) β Number of samples along x and y.
dx (float) β Spacing between adjacent samples in axis units.
dy (float) β Spacing between adjacent samples in axis units.
- Yields:
Vector2D β Each visited coordinate in grid order.
- spiral(step_size: float = 1.0, max_radius: float | None = None)
Yield an outward square spiral from the current position.
- Parameters:
step_size (float, default 1.0) β Distance per step along each leg.
max_radius (float, optional) β If provided, stop once the Euclidean distance from the start exceeds this radius.
- Yields:
Vector2D β Each visited coordinate.
- circular_spiral(step_size: float = 0.1, max_radius: float | None = None, dtheta: float = 0.05)
Yield an outward circular (Archimedean) spiral.
- Parameters:
step_size (float, default 0.1) β Radial growth per revolution (
binr = b * theta).max_radius (float, optional) β Maximum radius at which to stop emission.
dtheta (float, default 0.05) β Angular increment in radians per step.
- Yields:
Vector2D β Each visited coordinate along the spiral.
- list_waypoints()
Fetch the list of named waypoints from the server.
- Returns:
Each item contains keys
nameandpositions.- Return type:
list of dict
- random(r: float, repeat: int, waypoint: str | None = None, max_step_size: Vector2D | Tuple[float, float] | None = (0.5, 0.5))
Randomly explore a disc of radius
raround a named waypoint.The driver first moves to
waypoint. For each trial, it samples a random offset inside the disc and either moves in micro-steps (bounded bymax_step_sizeper axis) or performs a single jump. It then returns to the waypoint before the next trial.- Parameters:
r (float) β Disc radius in axis units.
repeat (int) β Number of random targets to sample.
waypoint (str, optional) β Name of a waypoint to use as the center. Must exist on the server.
max_step_size (Vector2D or (float, float), default (0.5, 0.5)) β Maximum per-step delta along
xandywhen micro-stepping. IfNone, performs a single jump to each target.
- Yields:
Vector2D β When micro-stepping, yields the cumulative offset from center after each micro-step (forward and return). When jumping, yields the full random offset.
- Raises:
ValueError β If the waypoint is not found on the server.