How to Synchronize 4 Motors in Python with MINDSTORMS Robot Inventor Gelo @AntonsMindstorms
How to Synchronize 4 Motors in Python with MINDSTORMS Robot Inventor Gelo  @AntonsMindstorms
Uploaded February 2021 | Updated September 2026, 7 hours ago
Please like and ask any questions you have in the comments! Learned something? Support me here:
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

This Robot Dog looks like Boston Dynamics Big Dog. Programming the legs on the Boston Dynamics Dog is hard. Real robot dogs, like Boston Dynamics Spot, use inverse kinematics. Here I use a simpler approach where I control the relative positions of the motors.

----- Video contents -----
00:00 Final result
00:13 Introduction
01:18 Word Block Gelo Program
03:50 Boilerplate Python Program
10:37 Synchronizing two motors with Python
17:12 Synchronizing four motors
20:10 Using the external crank for control
24:08 Making Gelo Turn
31:18 Using the distance sensor to start turning
37:53 Summary: code overview

---- Links mentioned ----
Full Gelo code here:
antonsmindstorms.com/2021/01/27/python-motor-synchronization-coordinating-multiple-spike-or-mindstorms-motors

---- Description ----
In this video, I'm sharing some MINDSTORMS Python code to help you coordinate motor movements. Synchronized motors are essential when you make robots dance or walk. Legs and arms need to move in unison for the robot to advance. I have abstracted the process to control motor positions based on a single input parameter. This method makes it real simple for you to make all kinds of robots walk and move.

You can see in the video how I linked all motor movements to a single number. If I change that number with the external motor, you see the animation unfold. I use this method in the SPIKE Prime Ladybug, 51515 Tars, the Swing Monkey, and LEGO MINDSTORMS Gelo.
One point in time, one position for SPIKE Motors
The basic idea of the system is that every single point in time corresponds with a motor position. Based on that idea, I searched for mathematical functions that calculate this relation. I wanted functions that would take time as an input and give me a motor position in degrees as an output. Then I could scale this up to as many motors as the LEGO MINDSTORMS hub can support. If every motor has a time-function, I can steer each motor to its desired position at any point in time.
The Mechanism() class to control all LEGO MINDSTORMS/SPIKE motors
To control all motors with functions, I wrote a Python Mechanism class. It takes two lists as its input: a list of motors and a list of functions. Once you have set up the Mechanism, all you have to do is feed it the time. The class will then set all motor powers according to their distance from the desired position at that point in time. Make sure to either keep updating motor powers in a loop or stop them completely. If you stop updating them, they will keep running at the last calculated motor power.
How to think of LEGO motor functions
As motors rotate clockwise, their position keeps 'increasing.' After one revolution, a motor position is 360; after two revolutions, it is 720. Outwardly, it might look like it is in the same position again, but the motor has continued counting on the inside. The difference between the inside counter and outside position makes motor functions a bit hard in the beginning. To illustrate this, I have made some graphs with typical motor functions.

The linear motor function in LEGO Python
The legs of Gelo and the outer legs of the Ladybug have a linear function. Linear means the motors run at a constant rate. Every unit of time, they rotate a unit of rotation. In my Gelo python program, the motors rotate 360 degrees per second. That is 360º/milisecond or 0.36º/ms.
In this graph, I have plotted all Gelo motor functions. The slope of the line is a measure of the speed of the motor. Steeper is faster. If the line goes up, the motor runs forward. If the line goes down, it runs backward. The intersection with the Y-axis shows how far the motors are apart.
In this graph, you can see that motors A and C run backward. You can also see that motors A and B are 180 degrees apart. The same goes for motors C and D.
The Mechanism class 'pulls' motors to the right position at every point in time. If they are ahead, they will slow down or even reverse. If they are behind, they will increase the motor power.
The wave function for dancing LEGO robots
How to Synchronize 4 Motors in Python with MINDSTORMS Robot Inventor GeloRobot Inventor 51515 vs. 45678 LEGO SPIKE Prime: how to choose?Unboxing SPIKE Prime and Expansion set 45678 and 45680Welcome To Antons Mindstorms HacksOne-kit Rubiks Cube Solver with LEGO MINDSTORMS Robot InventorTouchscreen UI + LEGO Spike Prime = The Ultimate Control System!Building an EV3 Swingbot with moving arms and legsHow to connect a PS4 controller to a MINDSTORMS EV3 robot in under 5 minutes!How to remote control Robot Inventor Tricky for Sumo fight!Lego Mindstorms Light Gate For RacesHow to Remote Control LEGO MINDSTORMS, SPIKE and Pybricks robotsRemote Controlled Catfish Robot with LEGO MINDSTORMS
Antons Mindstorms |

How to Synchronize 4 Motors in Python with MINDSTORMS Robot Inventor Gelo

SHARE TO X SHARE TO REDDIT SHARE TO FACEBOOK WALLPAPER