How many push-ups can you do? A team from Stupid Hackathon, a hackathon at the Pomeranian Hackerspace, wanted to build an application with the Aidlab chest strap that encourages people to lead active, healthy lifestyles.
We'll show you how to make a very simple app that will communicate with Aidlab through the Aidlab SDK. When you’re finished, your Python script will present the ocurrence of workout events in the console, including:
Prerequisites: Connecting with Aidlab requires a Bluetooth compatible machine.
Start with these three steps:
- Create an empty directory with a
- Install the AidlabSDK with
pip install AidlabSDK
Basic activities counting is a relatively simple task as only two components are needed. Firstly, the accelerometer signal, which shows the changes in acceleration during the exercise/movement execution. The second is the orientation.
To successfully detect an activity, tiny acceleration changes during the workout are measured along with the information on whether the person is facing the floor. This is exactly what Aidlab does behind the scenes if we subscribe to the
if __name__ == '__main__': signals = [Signal.motion, Signal.orientation] workout_detector = WorkoutDetector() workout_detector.connect(signals) while True: pass
Getting the correct orientation is a bit tricky, fortunately though, subscribing to the
orientation signals starts the workout detection automatically (through a co-processor known as workout detector), meaning we don't have to reinvent the wheel. Workout detector has many useful functions, one of them being a push-up counter.
To handle the workout events we have to create a
WorkoutDetector class. That class should derive from
import Aidlab class MainManager(Aidlab.Aidlab): def did_connect(self, aidlab): print("Connected to: ", aidlab.address) def did_disconnect(self, aidlab): print("Disconnected from: ", aidlab.address) def did_detect_exercise(self, aidlab, exercise): print(exercise)
Now, the callback from workout detector is invoked every time a new activity is recognized.
For further experimentation, we encourage you to play with the raw motion data (accelerometer and quaternion of orientation) in order to build your own workout detector.
The full code is available here, in the