How to animate your Robot Inventor Moc with Keyframes in Python @AntonsMindstorms
How to animate your Robot Inventor Moc with Keyframes in Python  @AntonsMindstorms
Uploaded February 2021 | Updated September 2026, 2 days ago
In this video, I will be using Tars, the famous tin robot from Interstellar, to show you the power of Keyframe animation. With just a few lines of code, you can create a full walking cycle.

Please like and ask any questions you have in the comments!
Link to article: antonsmindstorms.com/2021/02/20/keyframe-motor-animation-with-python-for-mindstorms-and-spike-robots

Get the T-Shirt on: https://shop.spreadshirt.nl/antons-mindstorms/
Support my work on: patreon.com/antonsmindstorms
For complete building instructions and in-depth articles go to:
antonsmindstorms.com

--- chapters ---
00:00 - Final result
00:12 - Overview
01:57 - Setup
03:40 - Defining the keyframes
21:35 - Looping the animation
22:50 - Conclusion

-- more description --
Animating LEGO MINDSTORMS robots with Keyframes using Python
Have you ever wished you could animate your robot like a stop-motion puppet? Did you want to animate a real robot like a 3D model? I did. And I built a keyframe system in Python to help me do it. That system was the key to make GELO do consistent hand-plants. Keyframes were also essential for my Tars project. The SPIKE Prime Ladybug uses keyframes too in its Python program.
In my previous article, I showed how to run multiple motors in sync by defining their time functions. Time functions are a good start, but they have limited flexibility. Sometimes you need more control over timing.
Take the walking animation for Tars. First, Tars has to drop his shoulders and swing back slightly. In the next 200ms, Tars has to swing his body forward while lifting the shoulders. And so on. To time and define every motor position, I used keyframes. Get the complete program and building instructions for Tars in the digital downloads section.
Keyframes like Pixar for your Robot Inventor creations
Animators who make movies use keyframes for this. Keyframes are certain positions where the movie characters have to be at a specific point in time. Those keyframes can be seconds apart, and computers calculate all the frames in-between for a smooth movement. Movies can have up to 60 frames per second, so it's a good thing we have computers. Walt Disney had to draw every frame manually. Pixar uses keyframes and computers to render their fantastic movies.
A keyframe for a MINDSTORMS Motor in Python
I don't want to have to define every motor position 20 times per second for my robots. I want to define just a few moments in time and their corresponding motor positions. Then I want my programming code to do all the calculations in-between. This combination of timing and position is what I call a keyframe.
Interpolation of Keyframes in Python
Next comes the challenge of calculating everything in between the keyframes. The calculation of a frame between two other frames is called interpolation. You don't have to worry about the precise calculation because my code does that for you. What is more interesting now is how to use that
The principle is the same as with the time functions for synchronizing a mechanism. You create a function that returns a motor angle if you feed it a moment in time. Only this time, the parameters for creating that function are keyframes. In Python, it looks like this:
Edge handling of the interpolated keyframes
What if you define keyframes and time runs beyond your last keyframe moment? Or it runs before the first keyframe? In that case, we have an edge situation. I have built three ways of handling the edges in my interpolation code: constant edges, wrapping, and wrapping with accumulation.
The simplest of these three is constant edges. This means the function returns the angle of the keyframe at the closest edge. Here's a graph of the result. I never actually used it, but it might be handy one day.
The second type of edge handling is wrapping. This means the function copies and infinitely repeats the set of keyframes, both forward and backward in time. It is what I use for Tars.
The third type of edge handling is wrapping with accumulation. This is the same as plain wrapping, except that I add a constant value after each wrapping.
Keyframe transformation convenience for walking robots
Apart from handling edges, I also wanted to conveniently manipulate the keyframes. When to motors are mounted in a mirrored fashion, the interpolation function allows you to invert the keyframe values. The interpolation system can also create a time offset. This is handy for Gelo's front and hind legs: they have a time difference of half the loop time. With one set of keyframes, inversions, and offsets, you can now configure GELO's complete walking movement.
How to animate your Robot Inventor Moc with Keyframes in PythonRataplan - EV3 front steering robot remote controlled with PS3 sixaxis gamepadCan two micro:bits be connected wirelessly and serve as a remote?24 november 2022Mindstorms robot plots a perfect circle on my door...PDF Building Instructions for AT-ST + mindstorms Robot Inventor (51515 + 75322)FPV Drone car with LEGO MINDSTORMS and DroneMask2Primecuber - The LEGO SPIKE Prime Rubiks cube solverUnboxing LEGO MINDSTORMS 51515 and First Build with PS4 controller!EV3 MotorbikePython programmed Robot Snake with LEGO MINDSTORMS Robot InventorHow to program the Technic EV3 Lizard - full tutorial
Antons Mindstorms |

How to animate your Robot Inventor Moc with Keyframes in Python

SHARE TO X SHARE TO REDDIT SHARE TO FACEBOOK WALLPAPER