This post follows the ‘Finding where we left off’ post, focused on locomotion sim2real. In that post I tried to generalise and smooth the leg angle servo movements in their -PI/2 to PI/2 range.
I will likely try extracting kMPs, before this is all over, which from a skim read, and look at the pictures, are like, just taking a single slice of the wave data, and repeating that. Or, taking consecutive periodic waves, and extracting the average / normalized movement from them.
https://becominghuman.ai/introduction-to-timeseries-analysis-using-python-numpy-only-3a7c980231af
It’s now December 6th 2021, as I continue here…
This paper is very relevant, “Realizing Learned Quadruped Locomotion Behaviors through Kinematic Motion Primitives”
Some Indian PhDs have summed up the process. Unfortunately I’m not quite on the exact same page. I understand the pictures, haha.
Here’s where this picture comes from, which is useful for explaining what I need to do: (Short paper)
In 2014, also, same thing, Kinematic primitives for walking and trotting gaits of a quadruped robot with compliant legs
They just used PCA. (Principal Component Analysis). That’s like a common ML toolkit thing.
See now this is where they lose me: “The covariance matrix of the normalized dataset”. Come on guys. Throw us a bone.
I found this picture, which is worth 1000 words, in the discussion on stackexchange about PCA and SVD:
So, I’m not quite ready for PCA. That is two dimensions, anyway. Oh right, so I need to add a ‘time’ dimension. numpy’s expand_dims?
I played around with Codex, to assist with finding the peaks, and to find the period length.
And I separated them out to different plots… and got the peaks matching once I passed in ( , distance=80).
I had to install these, and restart the Jupyter kernel (and I think close and restart the Chrome tab.) in order to get some matplotlib widgets.
Error message: Jupyter Lab: Error displaying widget: model not found !pip3 install --upgrade jupyterlab ipympl %matplotlib widget
I started on a slider widget to draw a vertical line on top of the leg data, but I need to fix the refresh issue. Anyhow, it’s not quite what i want. What do I want?
So, I want the kMPs. The kMPs are like, a gif of a basic action, e.g. robot taking a full step forward, on all legs, which we can run once, twice, etc.
We can ‘average’ or ‘normalise’ or ‘phase’ the waves, and assume that gives us a decent average step forward.
I think there’s enough variation in this silly simulation walk that we should start with just the simplest, best single wave.
But since they ran PCA, let’s run it to see what it does for the data. We have a single integer value, which is 1D. To make it 2D, so we can run PCA on it… we add a time dimension?
But also, so I measured the period a few programs up, to be
67 steps (front right),
40 steps (front left),
59 steps (back right),
42 steps (back left).
So, as a starting point, it would be nice to be as close to servos at 90 degrees as possible. If I iterate the values, and track the lowest sum diff, yeah… is that it? I’m looking at this link at SO.
Ideally I could visualise the options..
Repeating a slice. Averaging the slices.
Ok, so I need a start index, end index, to index a range.
After some investigation, the index where the legs are closest to 90 degrees, is at 1739
Computer Enhance
So that’s kinda close to our ideal kMPs, from about 1739 to about 1870 maybe, but clearly the data is messy. Could be tweaked. Wavetable editor, basically.
Alright, let’s make an app. We can try run a Flask server on the Pi, with Javascript front end using chart.js.
pip3 install flask
Save the test web app, kmpapp.py
from flask import Flask app = Flask(__name__) @app.route('/') def index(): return 'Hello world' if __name__ == '__main__': app.run(debug=True, host='0.0.0.0')
python3 kmpapp.py
Ok good start. We need to get the x and y data into JSON so Javascript can plot it, in chart.js
That’s looking good. Maybe too many points. Ok, so I want to edit, save, and run the KMPs on the robot.
Well it took a day but it’s working, and is pretty cool. Used smooth.js to allow smoother transitions. Took another day to add save and load features.
I’ll upload this to the project repo.
Many improvements added. Will update repo again closer to MFRU.