Architecture
The package does two things: it reads frames from the sensor, and it shows them live as a demonstration. Recording, pressure calibration and robot integration are not in this package. Build them on the Python API in your own project.
Modules
Section titled “Modules”| File | Responsibility |
|---|---|
src/eskin/protocol.py |
Constants of the wire format, FrameParser, encode_frame, decode_payload, rotation_map. No I/O. |
src/eskin/frame.py |
The Frame dataclass. |
src/eskin/reader.py |
EskinReader: serial I/O, baseline, blocking mode and background mode, port discovery. |
src/eskin/cli.py |
The eskin command (argparse). |
src/eskin/viz/server.py |
HTTP server with Server-Sent Events. Standard library only. |
src/eskin/viz/index.html |
The page: canvas heatmap and 3D surface. No build step. |
Data flow
Section titled “Data flow”serial port ──bytes──> FrameParser ──tuples of 2304 ints──> EskinReader │ rotate, subtract baseline, apply threshold ▼ Frame ──> your code / on_frame callbacks │ ▼ viz server ──SSE (JSON)──> browser pageDecisions
Section titled “Decisions”One runtime dependency
Section titled “One runtime dependency”The reader needs only pyserial. A frame is a tuple of Python integers, so the package works without NumPy.
NumPy is an optional extra for Frame.as_array(). The visualiser uses only the standard library on the Python side.
Reason: the package must install without problems on robot computers and in environments that already pin their scientific packages.
Only one thread reads the serial port
Section titled “Only one thread reads the serial port”pyserial raises an error when two threads read one port.
In background mode, the reader thread owns the port. Other threads send a request and wait: calibrate() puts a request in a queue, the reader thread does the calibration between two frames, and sets an event.
Blocking reads from other threads raise RuntimeError.
An earlier version called calibrate() directly from the web server thread. The reader thread stopped without a message. The current design and the test test_calibrate_while_thread_running prevent this.
The reader thread reports why it stopped
Section titled “The reader thread reports why it stopped”When an exception stops the reader thread, the thread stores it in EskinReader.error and logs it. Calibration requests that wait get the same error.
An exception in an on_frame callback is logged and does not stop the thread.
Baseline is the maximum, not the mean
Section titled “Baseline is the maximum, not the mean”The baseline of a taxel is its maximum over the calibration frames. Resting noise then stays at or below zero, and the threshold can be small. The cost is a small negative offset: light pressure reads a little too low.
Rotation in the reader
Section titled “Rotation in the reader”rotate is applied to the raw tuple with a precomputed index map, before the baseline. All users of a frame then see the same orientation, and the baseline is stored in that orientation.
Server-Sent Events with JSON
Section titled “Server-Sent Events with JSON”The visualiser sends each frame as one JSON event. At 56 frames per second this is less than 1 MB/s on the local machine. This format needs no library in the browser and no build step. It is not efficient enough for a network link or for recording, and it is not intended for them.