payload.modes.PayloadColorStringApproachMode#

PayloadColorStringApproachMode: drive the payload toward a coloured target using HSV blob detection and a two-phase approach.

By default only vertically elongated blobs are tracked: the axis-aligned bounding box must satisfy height >= vertical_blob_min_hw_ratio * width. The largest qualifying contour supplies centroid and area; other HSV regions are ignored. Set use_global_hsv_centroid to use the full mask as before. Phase 1 (ALIGN): rotate in place until the blob centroid is within centering_threshold_px of the image centre.

Phase 2 (DRIVE): move forward with a reduced angular correction to stay on target. If the centroid drifts outside the threshold the mode falls back to Phase 1.

Terminates when the blob area exceeds stop_area pixels.

Classes#

PayloadColorStringApproachParams

PayloadColorStringApproachMode

Drive toward a coloured target using HSV blob detection.

Functions#

_vertical_blob_centroid_area(→ Optional[Tuple[float, ...)

Largest external contour with bbox height >= min_hw_ratio * width.

Module Contents#

_vertical_blob_centroid_area(mask: numpy.ndarray, min_hw_ratio: float, min_area: float, top_frac: float = 0.3) Tuple[float, float, int] | None#

Largest external contour with bbox height >= min_hw_ratio * width.

cx is computed from only the top top_frac of the bounding box so that steering targets the far end of the string rather than its perspective-distorted base. Area is computed from the full contour.

Returns (cx, cy, area) in pixel units, or None if no contour qualifies.

class PayloadColorStringApproachParams#

Bases: vehicle_common.mode_loader.ParamsBase

lower_hsv: list[int] = (0, 0, 30)#
upper_hsv: list[int] = (179, 40, 120)#
forward_speed: float = 0.08#
angular_gain: float = 0.003#
centering_threshold_px: int = 15#
drive_angular_scale: float = 0.3#
min_detect_pixels: int = 50#
stop_area: int = 5000#
lost_timeout_s: float = 3.0#
compressed: bool = False#
vertical_blob_min_hw_ratio: float = 2.0#
top_centroid_frac: float = 0.3#
use_global_hsv_centroid: bool = False#
class PayloadColorStringApproachMode#

Bases: vehicle_common.mode.Mode

Drive toward a coloured target using HSV blob detection.

required_vision_nodes = ()#
requires_camera = True#
transition_labels = ()#
initialize(node: rclpy.node.Node, vehicle: payload.payload.Payload, params: PayloadColorStringApproachParams) None#
_on_image(msg) None#
_get_bgr() numpy.ndarray | None#
_now() float#
_publish_debug(bgr: numpy.ndarray, mask: numpy.ndarray, cx: float | None, cy: float | None) None#
on_enter() None#
on_update(time_delta: float) None#
check_status() str#
on_exit() None#