payload.modes.PayloadRetreatMode#

PayloadRetreatMode: drive to the edge of the DLZ and turn 180° to face the center.

Two-phase behaviour:
  1. drive_to_edge — drive forward until white DLZ coverage in the lower image drops below edge_threshold, confirming the payload has reached the zone boundary.

  2. turn_180 — spin in place until π radians have been accumulated, leaving the payload facing back toward the center of the DLZ.

Designed for a white DLZ on a green/grass background. No AprilTag library required.

Attributes#

Classes#

PayloadRetreatParams

PayloadRetreatMode

Drive the payload to the edge of the DLZ, then turn 180° to face the center.

Module Contents#

_WHITE_LOWER#
_WHITE_UPPER#
class PayloadRetreatParams#

Bases: vehicle_common.mode_loader.ParamsBase

forward_speed_mps: float = 0.12#
edge_threshold: float = 0.3#
edge_stable_frames: int = 5#
edge_min_pixels: int = 10#
edge_invalid_max_frames: int = 30#
turn_angular_speed: float = 0.5#
turn_direction: int = 1#
turn_angular: float = 3.141592653589793#
turn_speed: float = 1.85#
compressed_image: bool = False#
camera_debug: bool = False#
class PayloadRetreatMode#

Bases: vehicle_common.mode.Mode

Drive the payload to the edge of the DLZ, then turn 180° to face the center.

Phase 1 (drive_to_edge): move forward at forward_speed_mps while watching the lower half of the camera image for white coverage. The edge is confirmed once white_ratio drops below edge_threshold for edge_stable_frames consecutive frames — meaning the white DLZ floor has given way to the surrounding ground.

Phase 2 (turn_180): spin in place at turn_angular_speed rad/s (direction set by turn_direction: +1 = CCW, -1 = CW) until π radians are accumulated.

Publishes DriveCommand to the payload’s own namespaced command topic.

required_vision_nodes#
transition_labels = ()#
initialize(node: rclpy.node.Node, vehicle: payload.payload.Payload, params: PayloadRetreatParams) None#
on_enter() None#
on_exit() None#
on_update(time_delta: float) None#
check_status() str#
_image_cb(msg) None#
_edge_metrics(bgr: numpy.ndarray) Tuple[float, int]#

Lower half of the image: compute white_ratio and white_count.

white_ratio = white_pixels / total_lower_pixels. A low ratio (< edge_threshold) means the white DLZ floor has given way to the surrounding ground — the payload has reached the zone edge.

_draw_debug(bgr: numpy.ndarray, white_ratio: float, white_count: int, at_edge: bool) None#
_publish_drive(linear: float, angular: float) None#