Add Xiaozhao arms and head models, device selection, and fresh GetPose queries with configurable end links. Reset polling, commands, and plots on device changes. Expose MoveJ jerk and joint zero calibration, improve joint naming and plot handling, and cover model switching and request lifecycles with regression tests. Update AprilTag generation to default to PDF and include the refreshed exports, model meshes, and existing workspace artifacts.
79 lines
2.7 KiB
Python
79 lines
2.7 KiB
Python
import unittest
|
|
from threading import Event
|
|
from types import SimpleNamespace
|
|
from unittest.mock import patch
|
|
|
|
from PyQt5 import QtCore
|
|
|
|
from ui.app import JointStateWorker, PoseWorker
|
|
|
|
|
|
class FakeChannel:
|
|
def __init__(self):
|
|
self.closed = Event()
|
|
self.entered = Event()
|
|
|
|
def close(self):
|
|
self.closed.set()
|
|
|
|
|
|
class RobotPollingStopTests(unittest.TestCase):
|
|
def check_stop(self, worker_type, blocked_rpc):
|
|
channel = FakeChannel()
|
|
sampled = Event()
|
|
joint_response = SimpleNamespace(
|
|
state=SimpleNamespace(name=["joint1-left"], position=[1.0], velocity=[2.0])
|
|
)
|
|
pose_response = SimpleNamespace(
|
|
pose=SimpleNamespace(x=1.0, y=2.0, z=3.0, rx=0.1, ry=0.2, rz=0.3)
|
|
)
|
|
|
|
class FakeStub:
|
|
def __init__(self, _channel):
|
|
pass
|
|
|
|
def call(self, _request, timeout):
|
|
channel.entered.set()
|
|
if blocked_rpc:
|
|
channel.closed.wait(5.0)
|
|
raise RuntimeError("RPC cancelled")
|
|
return joint_response if worker_type is JointStateWorker else pose_response
|
|
|
|
getJointState = call
|
|
getPose = call
|
|
|
|
kwargs = {} if worker_type is JointStateWorker else {
|
|
"base_link": "base_link", "ee_link": "tcp-right",
|
|
}
|
|
worker = worker_type("unused", "right_arm", interval=10.0, **kwargs)
|
|
worker.updated.connect(lambda _data: sampled.set(), QtCore.Qt.DirectConnection)
|
|
with patch("ui.app.grpc.insecure_channel", return_value=channel), patch(
|
|
"ui.app.rpc.ArmServiceStub", FakeStub
|
|
):
|
|
worker.start()
|
|
try:
|
|
self.assertTrue(channel.entered.wait(1.0), "Worker did not start polling")
|
|
if not blocked_rpc:
|
|
self.assertTrue(sampled.wait(1.0), "Worker did not finish its first sample")
|
|
worker.stop()
|
|
self.assertTrue(worker.wait(1000), "Stopping waited for RPC/interval expiry")
|
|
self.assertTrue(channel.closed.is_set())
|
|
finally:
|
|
worker.stop()
|
|
channel.close()
|
|
worker.wait(12000)
|
|
|
|
def test_stop_cancels_inflight_rpc(self):
|
|
for worker_type in (JointStateWorker, PoseWorker):
|
|
with self.subTest(worker=worker_type.__name__):
|
|
self.check_stop(worker_type, blocked_rpc=True)
|
|
|
|
def test_stop_interrupts_long_poll_interval(self):
|
|
for worker_type in (JointStateWorker, PoseWorker):
|
|
with self.subTest(worker=worker_type.__name__):
|
|
self.check_stop(worker_type, blocked_rpc=False)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|