Skip to content
Merged
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
4 changes: 4 additions & 0 deletions waybionic_bringup/scripts/camera_follower.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ def main():
if (rclpy.ok() or not str(error).startswith(
"Unable to convert call argument '0' to Python object")):
raise
except TypeError as error:
# tf2 can no longer read the lookup time once SIGINT has invalidated the context.
if rclpy.ok() or not str(error).startswith('time must have sec and nanosec'):
raise
finally:
node.destroy_node()
rclpy.try_shutdown()
Expand Down
17 changes: 16 additions & 1 deletion waybionic_bringup/scripts/joint_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

from diagnostic_msgs.msg import DiagnosticArray, DiagnosticStatus, KeyValue
import rclpy
from rclpy._rclpy_pybind11 import RCLError
from rclpy.executors import ExternalShutdownException
from rclpy.node import Node
from rclpy.qos import DurabilityPolicy, QoSProfile
from rclpy.time import Time
Expand Down Expand Up @@ -252,8 +254,21 @@ def main():
node = JointDemo()
try:
rclpy.spin(node)
except KeyboardInterrupt:
except (KeyboardInterrupt, ExternalShutdownException):
pass
except RCLError as error:
# SIGINT can shut down the context before spin recreates its wait set.
if rclpy.ok() or 'the given context is not valid' not in str(error):
raise
except RuntimeError as error:
# Jazzy's binding error when a subscription's context is invalidated during SIGINT.
if (rclpy.ok() or not str(error).startswith(
"Unable to convert call argument '0' to Python object")):
raise
except TypeError as error:
# tf2 can no longer read the lookup time once SIGINT has invalidated the context.
if rclpy.ok() or not str(error).startswith('time must have sec and nanosec'):
raise
finally:
node.destroy_node()
rclpy.try_shutdown()
Expand Down
29 changes: 29 additions & 0 deletions waybionic_teleop/test/test_sim_arm_drives_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
_camera_spec = importlib.util.spec_from_file_location('waybionic_camera_shutdown', CAMERA_PATH)
camera_module = importlib.util.module_from_spec(_camera_spec)
_camera_spec.loader.exec_module(camera_module)
_demo_spec = importlib.util.spec_from_file_location(
'waybionic_joint_demo_shutdown', CAMERA_PATH.with_name('joint_demo.py'))
joint_demo_module = importlib.util.module_from_spec(_demo_spec)
_demo_spec.loader.exec_module(joint_demo_module)

POSE = {'joint_1': 0.8, 'joint_2': -0.8, 'joint_3': 0.8,
'joint_4': 0.8, 'joint_5': 0.25, 'tool_grip': 0.8}
Expand All @@ -43,6 +47,7 @@
(sim_arm_drives_node, 'SimArmDrives'),
(joy_udp_receiver, 'JoyUdpReceiver'),
(camera_module, 'CameraFollower'),
(joint_demo_module, 'JointDemo'),
]


Expand Down Expand Up @@ -591,3 +596,27 @@ def test_binding_error_only_ignored_after_context_shutdown(module, class_name, m
module.main()
assert spin.call_count == 3
assert factory.return_value.destroy_node.call_count == 3


@pytest.mark.parametrize('module, class_name', [
(camera_module, 'CameraFollower'), (joint_demo_module, 'JointDemo')])
def test_tf_time_error_only_ignored_after_context_shutdown(module, class_name, monkeypatch):
factory = MagicMock()
error = TypeError('time must have sec and nanosec, or nanoseconds.')
spin = MagicMock(side_effect=error)
monkeypatch.setattr(module, class_name, factory)
monkeypatch.setattr(module.rclpy, 'init', MagicMock())
monkeypatch.setattr(module.rclpy, 'try_shutdown', MagicMock())
monkeypatch.setattr(module.rclpy, 'spin', spin)
monkeypatch.setattr(module.rclpy, 'ok', lambda: False)
module.main()

spin.side_effect = TypeError('unrelated type error')
with pytest.raises(TypeError, match='unrelated type error'):
module.main()
monkeypatch.setattr(module.rclpy, 'ok', lambda: True)
spin.side_effect = error
with pytest.raises(TypeError, match='time must have sec and nanosec'):
module.main()
assert spin.call_count == 3
assert factory.return_value.destroy_node.call_count == 3
Loading