Cramp Detector
- 3 Devlogs
- 24 Total hours
Uses EMG, Sweat, Temp, and IMU sensors with an trained AI model to predict and prevent cramps.
Uses EMG, Sweat, Temp, and IMU sensors with an trained AI model to predict and prevent cramps.
CRAMP DETECTOR (POWERTHRU) - DEVLOG 3 note: scroll to see images—————————————————————————————————————————— This time, I began to focus more my design and prototype than actually coding the model – but I did make some improvements to the model and am doing some cool coding things. ————————————————————————————————————————— This was my first breadboard prototype, it uses an MPU-6050, AD8232, 10K Thermistor, GSR, a LED, random (for fun) water sensor (maybe sweat alt), and a pancake vibration module. I used an old kit I had from a while back which had most wires and resistors and basic supplies. While I have an ESP32 I’m so scared that I am going to break it so for now I am using the Arduino MEGA board (bigger and easier) that came with the kit (the newer one I believe). The hardest part was honestly connecting everything – I had no clue how the route all the wires – and honestly it looks like a mess (below). —————————————————————————————————————————— The items that kind of just barely worked were the EMG (proper values maybe a little “out of tune”) and the GSR which didn’t seem to detect sweat as much as I expected (it kept spiking with movement but that just means it needs to be secured better). The MPU just simply wasn’t working mainly because the pins needed to be soldered and I (am scared of) couldn’t solder so there were apparent air gaps where the information was being lost triggering an [Error -240] and 0’s across the Accel and Gyro values. The thermistor didn’t hold very steady and kept shifting – I wanted to use the DHT11 (bad but whatever) but it broke. The LED just didn’t work 😩. But one of my favorite parts of the system was the vibration module, whenever the cramp score (for now EMG biased) I made it so the pin state was set to HIGH effectively creating a cramp warning. Also, the water sensor just didn’t work and I probably won’t be using it in the future. —————————————————————————————————————————— I want to combine an ECG and EMG on the same AD8232 simultaneously but I was told that that might not be possible bc of positioning and frequency and other things. So the next steps are for me to maybe buy better parts (I did some research, how do these sounds?: MyoWare 2.0 for EMG, MPU-6050 (budget) or ICM-42688 (better), MLX90614 (non-contact) or TMP117/MAX30205 (contact), same GSR, and maybe I’ll throw in a MAX30102 (ECG). And I need to make sure I can integrate them for the future. —————————————————————————————————————————— I’ve been lazy and I haven’t really done any work on building my own pcb other than downloading KICAD – will update soon. —————————————————————————————————————————— Apparently BiLSTM isn’t going to be the most effective for cramp detection; CNN + GRU is better. A BiLSTM’s backward pass needs future timesteps (t5 to help classify t2) – fine for offline analysis of a complete pre-recorded window, but a live wearable predicting “cramp incoming” at t2 doesn’t have t5 yet. GRU is forward-only by construction; the CNN front end is made casual too (left-padded only) so nothing in the model ever depends on a future sample. So I just finished the first version of that: just swap the bidirectional lstm for the CNN + GRU combo and I got one of the better accuracy markers in a while (below). And later I want to combine the sensors into my dashboard in the last devlog so I can broadcast the prediction in real time—————————————————————————————————————————— Thanks for reading!
CRAMP DETECTOR (POWERTHRU) - DEVLOG 2—————————————————————————————————————————— To start, I used scikit - learn, Tensorflow, NumPy, pickle, and Pytorch to create a prototype for the BiLSTM model. I created two forms of the model: one that processes data that I generated (40,000 rows) and one that uses a WESAD dataset (https://ubi29.informatik.uni-siegen.de/usi/data_wesad.html). I had to modify some WESAD variables to fit my ideal sensors. Also, it uses Leave-One-Subject-Out (LOSO) cross validation. —————————————————————————————— ISSUES: My WESAD model is pretty bad (to what I expected as the other one was pretty good ~65 but that data is also generated so…) having accuracy of only 51.73 +/- 20.59%. But later when I combined oversampling + focal loss + class weights together over-corrected and overall accuracy dropped to ~45 +/- 20 (hoping on the plus side – how do you make it more reliable like less std_acc I swear it’s impossible). Thus, I think that it would be wise to turn oversampling off by default so that I have a gentler correction – if recall is too low with this combo, I will re-enable it or find some alt. Also, I created a diagnoses_subjects.py that expands the data of each subject to detect if there are any problems with the raw data in each. And alas, subject 14 (15% accuracy) had a eda_std roughly 15-35x lower than the reference subjects – nearly flatlined – leading me to believe that there was a loose / disconnected electrode. Subject 17 (17% accuracy) also had very low eda_std levels and an unusually narrow temp range – possibly due to physiological variability and not fully the model’s fault. So I added an EXCLUDE_SUBJECTS list that updates the loading of subjects to remove subjects with issues (e.g. 14 and maybe 17 if it doesn’t correct). —————————————————————————————————————————— I also create a dashboard.py script that uses plotly, streamlit, and pandas to create a visual and real-time dashboard for the levels. My parts are almost here (ESP32 mcu, way too basic dht11 temp, AD8232 emg, GSR sweat, MPU-6050 accel, Pancake Vibration motor, and batteries and supporting components) so in the meantime I used 2 interchangeable settings: Simulated random data mode, for demoing the UI without hardware (for now) and Live hardware mode; which uses ports connected over USB. I think the live visualization will be cool and will definitely transfer over to my app.————————————————————————————————————————Overall, this week was really about building the machine learning pipeline, diagnosing any quality issues, and creating software infrastructure that can (will) connect the hardware real-time interface (app). ——————————————————————————————————————— I am also really interested in building my own pcb – the idea just popped up while I was looking at other devlogs. Am I even able to integrate everything into one board? Idk, but if I remember I’ll do some research (Is Kicad the best?). Before I build anything I want to create a breadboard with each component to see if they fit together. Maybe I’ll test then run a mile then test again. Thanks for reading.—————————————————————————————————————————— Below I attached the dashboad, the result of my overcomplicated model, and the diagnose subjects that allowed me to eliminate 14 from my list. PS. I’m new to hardware related stuff – so if anyone is really skilled at it, could you help me bc I have a bunch of questions and am too lazy to watch youtube videos.
CRAMP DETECTOR - DEVLOG 1————————————————————————— — —— I started by working on the backend software for processing multimodal sensor data (EMG, sweat conductivity, temperature, and IMU signals) by generating sample datasets to train my own BiLSTM model. This took some time since I’m still relatively new to coding, but ig I am learning. ——————————————————————————— — I also did my best to attempt to create a 3D model in Onshape (For some reason I can only show one image). I really struggled to use the features, it’s pretty difficult to learn. But it’s coming together, and I’m still refining a few design ideas and making adjustments.——————————————————————————–For the future, I really want to finish the software pipeline, improve the CAD, and begin assembling the hardware components that I found. I’m excited to move from the designing toward building a functional prototype. Also, the name of the project is Powerthru. ——————————————————————————–Overall–I think–not too bad of a start for a beginner in this type of work.