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
9 changes: 9 additions & 0 deletions src/controller/alpasim_controller/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ def __init__(
self._solve_time_ms: float = 0.0
self._last_mpc_time_us: int | None = None

def close(self) -> None:
"""Close the CSV log file handle.

Callers must close before removing ``log_file`` on Windows, where open
files cannot be deleted.
"""
if not self._log_file_handle.closed:
self._log_file_handle.close()

def _dynamic_state_to_cg_velocity(
self, dynamic_state: common_pb2.DynamicState
) -> np.ndarray:
Expand Down
3 changes: 3 additions & 0 deletions src/controller/tests/test_create_system_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def test_create_system_via_registry(mpc_impl: MPCImplementation) -> None:
"""create_system() returns a System with a controller from the plugin registry."""
with tempfile.NamedTemporaryFile(mode="w", suffix=".csv", delete=False) as f:
log_file = f.name
system = None
try:
initial_state = _make_initial_state()
system = create_system(
Expand All @@ -46,5 +47,7 @@ def test_create_system_via_registry(mpc_impl: MPCImplementation) -> None:
assert hasattr(system, "_controller")
assert hasattr(system._controller, "compute_control")
finally:
if system is not None:
system.close()
if os.path.exists(log_file):
os.unlink(log_file)