Sleep trackers provide valuable information about the quality of one's rest, and help to demonstrate the effects on sleep caused by one's diet, routine, etc. Unfortunately the most common and cheap sleep tracker available- a writst-mounted fitness tracker- is also uncomfortable and requires enough battery power to work.
Using a Walabot board we can capture similar data without the inconvenience of actually having to wear an annoying rubber band. This project demonstrates the feasibility of that idea.
SetupFirst we need to install the Walabot SDK on our Raspberry Pi. To do this we first grab the installer for Raspberry Pi from this page on the Walabot site. Then we follow the instructions found on this other page in order to run it and complete the installation of the Walabot SDK:
python -m pip "/usr/share/walabot/python/WalabotAPI-1.0.21.tar.gz"
Now we can verify that we are able to interface with the Walabot Pro board using the demos that come bundled with the SDK. If they don't work or we receive a device-not-found error, a simple reboot of the Raspberry Pi (with the Walabot still connected) is all it takes to fix things. Now we need to clone the walabot-sleep-tracker repository with the following command:
git clone https://github.com/ckuzma/walabot-sleep-tracker.git
At this point we're 99% done! Just need to put the whole setup somewhere with a clean line-of-sight to the bed and start the Python tracking app. For the sake of this tutorial we are assuming that our Raspberry Pi has already been set up to operate as a headless device, so stashing it somewhere secure but difficult to reach is a good idea.
Once we've found a good spot for our Walabot sleep tracker, just start the tracking program before bed. The program accepts a single parameter for where to save the output CSV data, giving us a program initialization command that might look something like this:
python tracker.py sleep-15MAY2017.csv
That's it! To stop the tracker, simply press Control
+ C
on your keyboard. (Ignore any warning messages.) The output data can now be imported into an app such as Microsoft Excel, at which point it can be graphed for easier analysis:
The CSV contains time-stamped data sampled once per second. Each sample has a movement measurement as well as the accompanying sleep state (0 = awake, 1 = light sleep, 2 = deep sleep).
How to ModifyFine tuning can be accomplished by modifying lines 12-14 in tracker.py
:
SAMPLE_DELAY = 1
DEEP_THRESHOLD = 2.0
LIGHT_THRESHOLD = 5.0
The values in the file are once that worked for my setup, but you may find that you need to modify these in order to achieve accurate results.
Challenges and Future WorkWhile full of features and tunable parameters, the Walabot SDK doesn't have the most robust of target tracking. As such, a person being tracked might have somehow cause anywhere from 0 to 3 targets to register. How those points in space map to a person's body isn't always clear, but could be solved by applying a bit of machine learning. This would especially be useful when tracking two persons at once.
Additionally, automatic detection of sleep-start and sleep-end events would be very useful for automatic report generation. An early version of the sleep tracker merely determined whether or not the bed was "deployed" (the test bed is a Murphy-style bed that folds onto the wall) and then initiated sampling. This feature is likely to come back in the coming few weeks.
CodeAll of the project code can be found on GitHub here: https://github.com/ckuzma/walabot-sleep-tracker
Comments