nnspike.utils.recorder

Sensor Data Recorder Module

This module provides a class for recording ETRobot sensor status and control data to CSV files. It’s designed for high-performance logging during robot operation without impacting frame rates.

Classes

SensorRecorder([output_dir, timestamp])

High-performance CSV recorder for ETRobot sensor data and control information.

class nnspike.utils.recorder.SensorRecorder(output_dir='storage/sensor_data', timestamp=None)[source]
High-performance CSV recorder for ETRobot sensor data and control information.

This class manages CSV file creation, writing, and cleanup with optimizations for

real-time robot operation at high frame rates (30fps+).

Features: - Single file open/close for entire session - Buffered writing for performance - Periodic flushing for data safety - Automatic cleanup on program exit - Comprehensive sensor and control data logging

__init__(output_dir='storage/sensor_data', timestamp=None)[source]

Initialize the sensor recorder.

Parameters:
  • output_dir (str) – Directory to store CSV files

  • timestamp (str | None) – Custom timestamp for filename, auto-generated if None

start_recording()[source]

Start CSV recording session.

Creates output directory, opens CSV file, writes headers, and sets up cleanup.

Return type:

None

log_frame_data(spike_status, mode=None)[source]

Log sensor data for a single frame.

Parameters:
  • spike_status (SpikeStatus) – SpikeStatus object with sensor data

  • mode (Mode | None) – Current behavior mode (e.g., Mode.LEFT_EDGE_FOLLOWING)

Return type:

None

stop_recording()[source]

Stop CSV recording session and close file properly.

Return type:

None

get_filename()[source]

Get the current CSV filename.

Returns:

Full path to the CSV file

Return type:

str

get_frame_count()[source]

Get the current frame count.

Returns:

Number of frames recorded

Return type:

int

__enter__()[source]

Context manager entry.

Return type:

SensorRecorder

__exit__(exc_type, exc_val, exc_tb)[source]

Context manager exit.

Return type:

None