libstp.robot.geometry ===================== .. py:module:: libstp.robot.geometry .. autoapi-nested-parse:: Robot geometry calculations for sensor and wheel positions. This module provides dataclasses for representing sensor and wheel positions, and a mixin class for computing distances and angles between elements. Example usage: from libstp.robot.geometry import RobotGeometry, SensorPosition, WheelPosition class Robot(GenericRobot, RobotGeometry): width_cm = 15.0 length_cm = 22.0 rotation_center_forward_cm = 0.0 rotation_center_strafe_cm = 0.0 _sensor_positions = { defs.front_left_ir_sensor: SensorPosition(forward_cm=8.8, strafe_cm=3.75), } _wheel_positions = { defs.front_left_motor: WheelPosition(forward_cm=6.0, strafe_cm=9.5), } robot = Robot() pos = robot.sensor_position(robot.defs.front_left_ir_sensor) print(f"Sensor at: {pos.forward_cm}cm forward, {pos.strafe_cm}cm left") wheel_pos = robot.wheel_position(robot.defs.front_left_motor) print(f"Wheel at: {wheel_pos.forward_cm}cm forward") Classes ------- .. autoapisummary:: libstp.robot.geometry.SensorPosition libstp.robot.geometry.WheelPosition libstp.robot.geometry.RobotGeometry Module Contents --------------- .. py:class:: SensorPosition Position of a sensor relative to robot geometric center. .. attribute:: forward_cm Distance forward from center (positive = front of robot) .. attribute:: strafe_cm Distance left from center (positive = left side of robot) .. attribute:: clearance_cm Sensor clearance/detection radius .. py:attribute:: forward_cm :type: float .. py:attribute:: strafe_cm :type: float .. py:attribute:: clearance_cm :type: float :value: 0.0 .. py:class:: WheelPosition Position of a wheel relative to robot geometric center. .. attribute:: forward_cm Distance forward from center (positive = front of robot) .. attribute:: strafe_cm Distance left from center (positive = left side of robot) .. py:attribute:: forward_cm :type: float .. py:attribute:: strafe_cm :type: float .. py:class:: RobotGeometry Mixin class providing geometry calculations for robot positioning. This class should be used as a mixin with GenericRobot. Subclasses must define the following class attributes (typically generated by codegen): - width_cm: Robot width in centimeters - length_cm: Robot length in centimeters - rotation_center_forward_cm: Offset from geometric center to rotation center (forward axis) - rotation_center_strafe_cm: Offset from geometric center to rotation center (strafe axis) - _sensor_positions: Dict mapping sensor objects to SensorPosition instances - _wheel_positions: Dict mapping motor objects to WheelPosition instances The mixin provides computed methods for: - Getting sensor/wheel positions - Computing distances between sensors - Computing distances from sensors to rotation center - Computing angles from center to sensors .. py:attribute:: width_cm :type: float :value: 0.0 .. py:attribute:: length_cm :type: float :value: 0.0 .. py:attribute:: rotation_center_forward_cm :type: float :value: 0.0 .. py:attribute:: rotation_center_strafe_cm :type: float :value: 0.0 .. py:method:: sensor_position(sensor: Any) -> Optional[SensorPosition] Get the position of a sensor relative to robot center. :param sensor: The sensor object (pass defs.sensor_name) :returns: SensorPosition if found, None otherwise .. py:method:: wheel_position(motor: Any) -> Optional[WheelPosition] Get the position of a wheel by its motor object. :param motor: The motor object (pass defs.motor_name) :returns: WheelPosition if found, None otherwise .. py:method:: distance_between_sensors(sensor_a: Any, sensor_b: Any) -> float Calculate the Euclidean distance between two sensors. :param sensor_a: First sensor object :param sensor_b: Second sensor object :returns: Distance in centimeters :raises ValueError: If either sensor is not found in geometry .. py:method:: sensor_to_rotation_center(sensor: Any) -> float Calculate the distance from a sensor to the rotation center. This is useful for arc calculations during turns. :param sensor: The sensor object :returns: Distance in centimeters :raises ValueError: If sensor is not found in geometry .. py:method:: sensor_to_geometric_center(sensor: Any) -> float Calculate the distance from a sensor to the geometric center. :param sensor: The sensor object :returns: Distance in centimeters :raises ValueError: If sensor is not found in geometry .. py:method:: sensor_angle_from_center(sensor: Any) -> float Calculate the angle from geometric center to a sensor. The angle is measured in radians, with 0 being forward and positive angles going counter-clockwise (to the left). :param sensor: The sensor object :returns: Angle in radians (0 = forward, π/2 = left, -π/2 = right) :raises ValueError: If sensor is not found in geometry .. py:method:: sensor_angle_from_rotation_center(sensor: Any) -> float Calculate the angle from rotation center to a sensor. The angle is measured in radians, with 0 being forward and positive angles going counter-clockwise (to the left). :param sensor: The sensor object :returns: Angle in radians (0 = forward, π/2 = left, -π/2 = right) :raises ValueError: If sensor is not found in geometry .. py:method:: all_sensors() -> Dict[Any, SensorPosition] Get all sensor positions. :returns: Dictionary mapping sensor objects to their positions .. py:method:: all_wheels() -> Dict[Any, WheelPosition] Get all wheel positions. :returns: Dictionary mapping motor objects to their positions