Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import logging
import math
import math
from typing import List, Sequence, Tuple, Union

from rai.types import Quaternion
Expand Down Expand Up @@ -46,7 +47,22 @@ def __init__(
The target rotation expressed as a quaternion (x, y, z, w).
"""
super().__init__(logger=logger)
self.obj_types = obj_types
if not obj_types:
raise ValueError("obj_types must be a non-empty list")
if not all(isinstance(x, str) and x.strip() for x in obj_types):
raise ValueError("obj_types must contain non-empty strings")
comps = (
float(target_quaternion.x),
float(target_quaternion.y),
float(target_quaternion.z),
float(target_quaternion.w),
)
if not all(math.isfinite(c) for c in comps):
raise ValueError("target_quaternion components must be finite")
norm = math.sqrt(sum(c * c for c in comps))
if not math.isfinite(norm) or norm < 1e-6:
raise ValueError("target_quaternion must have non-zero norm")
self.obj_types = list(obj_types)
self.target_quaternion = target_quaternion

@property
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,23 @@ def test_calculate_error_above_threshold() -> None:
# The rotation error is 10°, so it exceeds the 5° threshold.
assert correct == 0
assert incorrect == 1

import pytest


def test_reject_empty_obj_types() -> None:
target = Quaternion(x=0.0, y=0.0, z=0.0, w=1.0)
with pytest.raises(ValueError):
RotateObjectTask([], target_quaternion=target)


def test_reject_non_finite_quaternion() -> None:
target = Quaternion(x=float("nan"), y=0.0, z=0.0, w=1.0)
with pytest.raises(ValueError):
RotateObjectTask(["apple"], target_quaternion=target)


def test_reject_zero_norm_quaternion() -> None:
target = Quaternion(x=0.0, y=0.0, z=0.0, w=0.0)
with pytest.raises(ValueError):
RotateObjectTask(["apple"], target_quaternion=target)
Loading