{"id":116,"date":"2023-01-14T11:23:22","date_gmt":"2023-01-14T16:23:22","guid":{"rendered":"http:\/\/leapfrog.hopto.org\/wolfy\/?page_id=116"},"modified":"2023-01-14T21:16:09","modified_gmt":"2023-01-15T02:16:09","slug":"gait-tracking","status":"publish","type":"page","link":"https:\/\/leapfrog.hopto.org\/wolfy\/?page_id=116","title":{"rendered":"Gait Tracking"},"content":{"rendered":"\n<p>The idea is to record and classify the accelerations of an ankle during various gaits. The accelerometer is worn in a band just above the ankle, and the five connector wires extend upwards to the waist where they lead into an Arduino with an attached micro-SD card. Power is provided by a battery pack and travels to the Arduino through a USB cable.<\/p>\n\n\n\n<p>Pro tip: Remember to put a micro SD card into the adapter before testing. It can save an hour or so of debugging time. \ud83d\ude10<\/p>\n\n\n\n<p>As a reference the Z acceleration (dots) is about 1 G more than the X and Y accelerations. Not much analysis has gone into this, but you can clearly see the forward &#8220;snap&#8221; of the knee as the pace speeds up.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"194\" src=\"https:\/\/leapfrog.hopto.org\/wolfy\/wp-content\/uploads\/2023\/01\/Screenshot-from-2023-01-14-11-22-57-1024x194.png\" alt=\"\" class=\"wp-image-117\" srcset=\"https:\/\/leapfrog.hopto.org\/wolfy\/wp-content\/uploads\/2023\/01\/Screenshot-from-2023-01-14-11-22-57-1024x194.png 1024w, https:\/\/leapfrog.hopto.org\/wolfy\/wp-content\/uploads\/2023\/01\/Screenshot-from-2023-01-14-11-22-57-300x57.png 300w, https:\/\/leapfrog.hopto.org\/wolfy\/wp-content\/uploads\/2023\/01\/Screenshot-from-2023-01-14-11-22-57-768x146.png 768w, https:\/\/leapfrog.hopto.org\/wolfy\/wp-content\/uploads\/2023\/01\/Screenshot-from-2023-01-14-11-22-57.png 1533w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h5 class=\"wp-block-heading\">Packaging<\/h5>\n\n\n\n<p>The Arduino and the micro SD card.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1008\" height=\"756\" src=\"https:\/\/leapfrog.hopto.org\/wolfy\/wp-content\/uploads\/2023\/01\/20230114_113732_resized.jpg\" alt=\"\" class=\"wp-image-127\" srcset=\"https:\/\/leapfrog.hopto.org\/wolfy\/wp-content\/uploads\/2023\/01\/20230114_113732_resized.jpg 1008w, https:\/\/leapfrog.hopto.org\/wolfy\/wp-content\/uploads\/2023\/01\/20230114_113732_resized-300x225.jpg 300w, https:\/\/leapfrog.hopto.org\/wolfy\/wp-content\/uploads\/2023\/01\/20230114_113732_resized-768x576.jpg 768w\" sizes=\"auto, (max-width: 1008px) 100vw, 1008px\" \/><figcaption class=\"wp-element-caption\">The Arduino and micro SD card.<\/figcaption><\/figure>\n\n\n\n<p>The accelerometer. In the next incarnation I&#8217;ll use bent pins to allow the package to be thinner.  Legos work pretty well!<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1008\" height=\"756\" src=\"https:\/\/leapfrog.hopto.org\/wolfy\/wp-content\/uploads\/2023\/01\/20230114_113709_resized.jpg\" alt=\"\" class=\"wp-image-128\" srcset=\"https:\/\/leapfrog.hopto.org\/wolfy\/wp-content\/uploads\/2023\/01\/20230114_113709_resized.jpg 1008w, https:\/\/leapfrog.hopto.org\/wolfy\/wp-content\/uploads\/2023\/01\/20230114_113709_resized-300x225.jpg 300w, https:\/\/leapfrog.hopto.org\/wolfy\/wp-content\/uploads\/2023\/01\/20230114_113709_resized-768x576.jpg 768w\" sizes=\"auto, (max-width: 1008px) 100vw, 1008px\" \/><\/figure>\n\n\n\n<h5 class=\"wp-block-heading\">Wiring<\/h5>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"432\" src=\"https:\/\/leapfrog.hopto.org\/wolfy\/wp-content\/uploads\/2023\/01\/Screenshot-from-2023-01-14-11-10-59-1024x432.png\" alt=\"\" class=\"wp-image-115\" srcset=\"https:\/\/leapfrog.hopto.org\/wolfy\/wp-content\/uploads\/2023\/01\/Screenshot-from-2023-01-14-11-10-59-1024x432.png 1024w, https:\/\/leapfrog.hopto.org\/wolfy\/wp-content\/uploads\/2023\/01\/Screenshot-from-2023-01-14-11-10-59-300x127.png 300w, https:\/\/leapfrog.hopto.org\/wolfy\/wp-content\/uploads\/2023\/01\/Screenshot-from-2023-01-14-11-10-59-768x324.png 768w, https:\/\/leapfrog.hopto.org\/wolfy\/wp-content\/uploads\/2023\/01\/Screenshot-from-2023-01-14-11-10-59.png 1435w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h5 class=\"wp-block-heading\">Arduino Code<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>\n\/**************************************************************\n * Accelerometer Thread Created By: Tauseef Ahmad\n * Created On: 8th January, 2022\n * Modified by: Michael Graham, 14 January, 2023\n * \n * How To Interface ADXL335 Analog Accelerometer Sensor With Arduino\n * Tutorial: https:\/\/youtu.be\/HrIBGJep-1o\n * Tutorial pages: https:\/\/arduinogetstarted.com\/tutorials\/arduino-write-variable-to-sd-card\n * https:\/\/create.arduino.cc\/projecthub\/electropeak\/sd-card-module-with-arduino-how-to-read-write-data-37f390\n**************************************************************\/\n\n\/\/ initializations for save to microSD\n#include &lt;SD.h&gt;\n#define PIN_SPI_CS 4\nFile myFile;\nint Precision = 3;\n\n\/\/ Initializations for accelerometer A\n#define xPinA A0\n#define yPinA A1\n#define zPinA A2\n\/\/calibrated minimum and maximum Raw Ranges for each axis\nint xMinA = 249;\nint xMaxA = 394;\nint yMinA = 255;\nint yMaxA = 396;\nint zMinA = 260;\nint zMaxA = 401;\n\n\/\/ Take multiple samples to reduce noise\nconst int samples = 10;\n\n\/\/ Interval is how long we wait\n\/\/ add const if this should never change\nconst int interval=100;\n\n\/\/ Tracks the time since last event fired\nunsigned long previousMillis = 0;\n\nString data_string;\n\nvoid setup() \n{\n  Serial.begin(115200);\n  while (!Serial) {\n    ;\n  }\n\n  pinMode(4,OUTPUT);\n   \n  if (!SD.begin(PIN_SPI_CS)) {\n    Serial.println(F(\"SD CARD FAILED, OR NOT PRESENT.\"));\n    while (1); \/\/ don't do anything more:\n  }  \n  SD.remove(\"gait_dat.txt\");\n}\n\n\nvoid loop() \n{\n\n  \/\/ Get snapshot of time\n  unsigned long currentMillis = millis();\n\n  \/\/ How much time has passed, accounting for rollover with subtraction!\n  if ((unsigned long)(currentMillis - previousMillis) &gt;= interval) {\n\n    \/\/Read raw values\n    int xRaw=0,yRaw=0,zRaw=0;\n    for(int i=0;i&lt;samples;i++)\n    {\n      xRaw+=analogRead(xPinA);\n      yRaw+=analogRead(yPinA);\n      zRaw+=analogRead(zPinA);\n    }\n    xRaw\/=samples;\n    yRaw\/=samples;\n    zRaw\/=samples;\n    \/\/-------------------------------------------------------------\n    \/\/Convert raw values to 'milli-Gs\"\n    \/\/Convert value of RawMin to -1000\n    \/\/Convert value of RawMax to 1000\n    long xMilliG = map(xRaw, xMinA, xMaxA, -1000, 1000);\n    long yMilliG = map(yRaw, yMinA, yMaxA, -1000, 1000);\n    long zMilliG = map(zRaw, zMinA, zMaxA, -1000, 1000);\n\n    \/\/ unused--------------------------------------------------\n    \/\/ re-scale to fractional Gs\n    float x_g_value = xMilliG \/ 1000.0;\n    float y_g_value = yMilliG \/ 1000.0;\n    float z_g_value = zMilliG \/ 1000.0;\n    \/\/-------------------------------------------------------------\n    \n    Serial.print(xRaw);\n    Serial.print(\"\\t\");\n    Serial.print(yRaw);\n    Serial.print(\"\\t\");\n    Serial.print(zRaw);\n    Serial.println();\n    \n    myFile = SD.open(\"gait_dat.txt\", FILE_WRITE);\n    if (myFile) \/\/ it opened OK\n    {\n      data_string = String(x_g_value,Precision) + \",\" +            String(y_g_value,Precision) + \",\" + String(z_g_value,Precision);\n      myFile.println(data_string);\n      myFile.close();\n    } else \n      Serial.println(\"Error opening gait_dat.txt\");\n      \n    \/\/ Use the snapshot to set track time until next event\n    previousMillis = currentMillis;\n  }\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The idea is to record and classify the accelerations of an ankle during various gaits. The accelerometer is worn in a band just above the ankle, and the five connector wires extend upwards to the waist where they lead into an Arduino with an attached micro-SD card. Power is provided by a battery pack and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-116","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/leapfrog.hopto.org\/wolfy\/index.php?rest_route=\/wp\/v2\/pages\/116","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/leapfrog.hopto.org\/wolfy\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/leapfrog.hopto.org\/wolfy\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/leapfrog.hopto.org\/wolfy\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/leapfrog.hopto.org\/wolfy\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=116"}],"version-history":[{"count":13,"href":"https:\/\/leapfrog.hopto.org\/wolfy\/index.php?rest_route=\/wp\/v2\/pages\/116\/revisions"}],"predecessor-version":[{"id":145,"href":"https:\/\/leapfrog.hopto.org\/wolfy\/index.php?rest_route=\/wp\/v2\/pages\/116\/revisions\/145"}],"wp:attachment":[{"href":"https:\/\/leapfrog.hopto.org\/wolfy\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=116"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}