This past week I worked on updating the MuscleMemory application to include repetitions that were attempted but not fully completed, or rather half-completed reps. I also worked on updating my Bluetooth Arduino code to now keep track of all of a workout’s completed reps and half-completed reps in a matrix. Additionally, I worked on reading and working with data in the PhoneGap app that I’d sent via Bluetooth from the Arduino. Lastly, I wrote out the code for the bend sensor.
Half-completed Reps in the App
I began the week by updating the MuscleMemory App so it could keep track of half-completed reps as red circles in the table. The app previously displayed just the complete repetitions and its “updateTable” function would just update the next un-attempted rep in the matrix and then change all of the reps in a set to gold when the set was completed.
The updated MuscleMemory App now keeps track of half-completed reps and completed reps and its updateTable function looks entirely different. The updateTable function now also takes in a string of 0s (un-attempted reps), 1s (complete reps), and 5s (half-complete reps) that represent the order and progress of the workout. The updateTable function then fills in the table according to the information received from the string and checks if any sets have been completed with all complete reps, and if so then it changes the color of that set from green to gold.
Updating the Bluetooth Arduino Code
After updating the MuscleMemory App to account for half-completed reps, I needed to also update the Bluetooth Arduino code to account for half-completed reps. Previously the code that I had was just sending the number of completed reps to the application in the form of an int. However, now that I’m also keeping track of half-completed reps in the PhoneGap app, I needed the Arduino code to account for half-completed reps. Additionally, I needed the Arduino code to keep track of the order that the reps were completed in so all of the reps can be properly displayed in the table on the app as completed, half-completed, or un-attempted.
I changed my Arduino code so that it now uses a 2 dimensional array to keep track of all of the reps for the workout and if they were un-attempted, completed, or half-completed. The Arduino code then converts that 2-D array into a string and sends it when we need to send the workout via Bluetooth to the app. This code works great when the 2-D array called “workout” is initialized with ints like 3 and 8, but will not work when initialized with integer variables such as “numOfSets” and “repsPerSet”. Since the number of sets and reps could change every workout we’ll need to find a new way to represent the workout. One solution could be to use a very large 1 dimensional array that can hold a number of elements that is larger than the number of reps that any instructor would assign for a workout.
Reading and Working with Data in the PhoneGap App
After figuring out how to send the 2-D array to the PhoneGap app as a string of 0s, 1s, and 5s via Bluetooth, I worked on figuring out how to process the string in the PhoneGap app. I looked through the index.js file on the example app that I had been working with and through the “onData” part of the code for the app setup. At first I had taken a different approach in how I was going to process the string from the Arduino code and update my table and I thought that this “onData” part of the code would need to iterate through the string and for every 0 it would do nothing, for every 1 (completed rep) it would call my original updateTable function (from before I updated the app) to fill in the next circle in the table green, and for every 5 (half-complete rep) it would call an “updateTableHalfRep” function that worked like my updateTable function to fill in the next circle in the table red. I wasn’t yet able to get my app (iterate app with index.html) to update the tables from what it received from the Arduino but I was able to get string data from the Arduino and iterate through each character of the strings to print the 0s as a’s, 1s as b’s, and 5’s as c’s.
I eventually realized though that iterating through the string and using my old updateTable function and this updateTableHalfRep function would not be a good solution. I realized that if I sent the workout data from the Arduino multiple times during a workout then I would end up updating the table multiple times for the same reps which is not good. My solution to this was to get rid of the “updateTableHalfRep” function and just update my updateTable function to take in a string representing a matrice and match up every rep in my app’s table according to the string. Now instead of having to iterate through the string, I will simply pass the entire string to my newly updated “updateTable” function.
Bend Sensor Code
Now that John has a working bend sensor, we were able to tape it onto a knee sleeve and test it and I was able to write the code for the knee sleeve. The code works by having an athlete first set his or her starting squat position and target squat position. After setting those positions the code checks if the athlete has attempted a squat and the squat is ending by first checking if the person has squatted down at least 60% (this value may change during testing) from their starting position and is starting to come back up. The code keeps a count of the number of complete squats (squats where the sensor has been bent to or past its target value) and half-squats (squats where the sensor has been bent past 60%, but not quite to a full squat). When a squatter has started coming up to end a rep, the code waits until the athlete has reached 15% bend in the knee sleeve which indicates a squatter has come back up to his or her resting position for the next squat. After testing, the code appears to be working exactly how it is intended.
Plans for the coming week
The next steps on this project will be to update the Bluetooth code that sends the workout to use a 1 dimensional array of a fixed size rather than a 2-D array and then to merge that code with the bend sensor code so it’s all in one file. I’ll also need to work on sending and parsing packets so that I’ll be able to set the number of assigned reps for every workout from the PhoneGap app. I’ll also need to work on breaking up the script in the app for the table into a separate file and get the table to update with the Arduino code. I’m also going to be working on learning XBee and creating an ambient display that will allow squatters to look straight ahead at the changing colors of the NeoPixels rather than down at the side of the knee sleeve. This next week should be pretty busy.