astro-pi / python-sense-emu

An emulator for the Raspberry Pi Sense HAT
https://sense-emu.readthedocs.io/
Other
40 stars 25 forks source link

Headless emulator #28

Closed allxone closed 4 years ago

allxone commented 4 years ago

Hi, I'm using your great emulator to test a ROS package to interact with the SenseHat. It really helps both development and testing avoiding much of the mock stuff.

I'm working with Docker to eventually deploy the application via Balena Cloud. Testing would be much easier if I could start the emulator without the GUI and all the related system dependencies. Do you have any suggestion about doing this?

Thanks, Stefano

waveform80 commented 4 years ago

It should be possible to make a headless/mock server relatively easily. A long-time goal of mine (when I get a spare moment) has been to make a TUI/curses front end for the emulator. The emulator code itself is deliberately separate from the GUI for just this purpose, but that equally lends itself to making a programmatic / mock front end for it.

allxone commented 4 years ago

Thank you! Looking better through the tools I understand sense_play is basically doing something similar to what I need, starting from an .hat file. I could probably simply start a prerecorded sensor session just before running any test, no? If this is correct, are you aware of any publicly available source of .hat files? If not do you think I can try to handcraft them manually starting from your CSV format and reversing the sense_csv logic? I know I can record them on my own but I need to play with the hardware to do that.

Many thanks for your support.

Stefano

waveform80 commented 4 years ago

Yes, sense_play is essentially what you're looking for provided you're happy with playing back a pre-recorded session. The intention is indeed to start sense_rec, then "do something" with the HAT (dropping it, swinging it round, breathing on it, etc.) so the results can be played back against a script later. I suppose you could even have something generate the recorded output and pipe it to sense_play to construct a headless emulator on the command line!

A bit of background: this was something I threw in as a last minute addition to the suite (it wasn't in the contract, hence why there's no fancy GUI for it or anything). Having had the idea though, we had a vague notion that it could be used in the Astro Pi mission, e.g. for recording readings from the IMU during a boost manoeuvre on the ISS which could then be played back by people entering the competition to test their entries against "real" data from the ISS (which they wouldn't otherwise have any chance of gathering or accurately simulating themselves).

Whether any such recordings were ever produced or are available, I've no idea. Be nice to get some examples to include in the suite, though!

The CSV conversion was largely thrown in for ease of debugging (so I could quickly dump a recording into something like veusz to graph it).

allxone commented 4 years ago

I finally ended up using sense_play to support tests via pre-recorded trace files I produced with sense_rec and an actual Sense HAT device. You can find them here

Thanks, Stefano