cdpr-simulator / tests /test_robots.py
JoeTach's picture
Initial commit: cdpr Phases 1-7 + deployment scaffolding
5f38e95
Raw History Blame Contribute Delete
1.38 kB
"""Catalog smoke tests: each reference robot is consistent and runnable."""
from __future__ import annotations
import numpy as np
import pytest
from cdpr.kinematics.inverse import cable_lengths
from cdpr.kinematics.jacobian import structure_matrix
from cdpr.robots import cogiro_class, ipanema_class, planar_translational, point_mass_3d
@pytest.fixture(
params=[point_mass_3d, planar_translational, ipanema_class, cogiro_class],
ids=["point-mass", "planar", "ipanema", "cogiro"],
)
def reference_robot(request):
return request.param()
def test_cable_count_matches_anchors(reference_robot):
assert reference_robot.geometry.anchors.shape[0] == reference_robot.n_cables
assert reference_robot.geometry.attachments.shape[0] == reference_robot.n_cables
def test_redundancy_nonnegative(reference_robot):
assert reference_robot.redundancy >= 1
def test_lengths_positive_at_home(reference_robot, home_pose):
L = cable_lengths(home_pose, reference_robot)
assert (L > 0).all()
def test_structure_matrix_full_rank_at_home(reference_robot, home_pose):
W = structure_matrix(home_pose, reference_robot)
assert np.linalg.matrix_rank(W) == reference_robot.dof
def test_inertia_present_and_positive_definite(reference_robot):
I = reference_robot.inertia.inertia
assert np.allclose(I, I.T)
assert (np.linalg.eigvalsh(I) > 0).all()