Example code of
Simultaneous Locomotion Mode Classification and Continuous Gait Phase Estimation for Transtibial Prostheses
Ryan R. Posh*
Recognizing and identifying human locomotion is a critical step to ensuring fluent control of wearable robots, such as transtibial prostheses. In particular, classifying the intended locomotion mode and estimating the gait phase are key. In this work, a novel, interpretable, and computationally efficient algorithm is presented for simultaneously predicting locomotion mode and gait phase. Using able-bodied (AB) and transtibial prosthesis (PR) data, seven locomotion modes are tested including slow, medium, and fast level walking (0.6, 0.8, and 1.0 m/s), ramp ascent/descent (5 degrees), and stair ascent/descent (20 cm height). Overall classification accuracy was 99.1% and 99.3% for the AB and PR conditions, respectively. The average gait phase error was less than 4% across all data. Exploiting the structure of the historical data, coumputational efficiency reached 2.91
- OS: Crossplatform, but tested on MacOSX or Linux (x86/x64 and/or ARM)
- C++ Compiler: g++ (recommended) or clang++
g++ compiled code in our test is 10~20% faster than the clang++ compiled one
- Eigen - (Optional) for implementation using Eigen library.
Eigen is a header library for linear algebra. It provides explicit vectorization for matrix operations and is better optimized. Therefore, it reduce the computation time of naive/plain approach to a fraction of pointer implementation. The setup script would tell makefile to skip Eigen implementation if no Eigen library is found.
- MATLAB - For converting, processing, and plotting data.
We use PopIn to read and converting .yaml format data in MATLAB. The setup script can automatically download it to directory
MATLAB/PopIn
Download this project
git clone https://github.com/ROAM-Lab-ND/SlidingWindowGaitEstimation.git
cd SlidingWindowGaitEstimation
Run the setup script and follow the instruction to configure compiler and Eigen.
./setup.sh
or specify a compiler and Eigen path (you must specify compiler then specify Eigen)
./setup.sh [COMPILER] [/PATH/TO/EIGEN]
make clean
to remove all compiling and executable files of this project.make all
to compile all.
- Run the script to test the C++ code:
./runtest.sh
The computation time would be output as
Start: Trick (moving window) - pointer implementation
Total Time (us): 10073
Time Per Data (us): 3.35767
- Or run the MATLAB script
MATLAB/SSE_without_savings.m
to run the MATLAB implementation. - Script
MATLAB/DebugTest/CPPClassificationTest.m
will compare the result between C++ and MATLAB implementation
We have four different implementations with two set of flags: Trick/Plain and Homemade/Eigen.
Suppose we have
-
Trick - using sliding window trick, time complexity
$\mathcal{O}(N\cdot M)$ , space complexity$\mathcal{O}(M\cdot N^2)$ . -
Plain - (a.k.a., Naive in paper) no computation save, compute SSE from scratch, time complexity
$\mathcal{O}(M\cdot N^2)$ , space complexity$\mathcal{O}(N\cdot M)$ . - Homemade - (i.e., pointer) store and compute array/matrix with pointer, probably less overhead.
- Eigen - store array/matrix with Eigen array type, and compute with Eigen function, better vectorization due to explicit AVX/SIMD call, cleaner expression.
Direct call C++ program via command line.
./build/SSExxxxx /DIR/OF/DATABASE/ /PATH/TO/EXPERIMENT/DATA/ INDEX_START INDEX_END /PATH/TO/RESULT/FILE
For example:
./build/SSEtrick ./Data/DataBase_CSV ./Data/Experiment_CSV/Multispeed_Walk_AB.csv 4000 7000 ./CPPResult/Test_Trick.csv
{
...
}