Sheloby: Explaining a Self-balancing Hexapod

Marta Bernardino
7 min readApr 6, 2023

--

This is Sheloby, a self-balancing hexapod robot that balances itself on tilted surfaces. This project had the purpose of exploring inverse kinematics on a multi-limbed hexapod. This is a six leged-robot based on the Arduino Mega development board and the MPU6050 accelerometer-gyroscope module.

For my goal, I got a FreeNove Arduino Hexapod, this is a robot kit compatible with Arduino IDE and Processing IDE. The kit is assembled with the following hardware:

Acrylic parts structure;
  • ESP8266 Wi-Fi Module x1;
  • Freenove Crawling Robot Controller x1;
  • Cable Tidy x75cm;
  • Servo x18.
FreeNove assembled kit;

The kit provides the complete code and its respective libraries:

These functions can control the robot for a variety of movements as shown in the GIF below. This works follows the kinematics and physics that I explained in my last article: Dismantling Hexapod’s Locomotion

Hexapod moving forward and turning left;

The kit can also be directly controlled by the IO ports on the control board. In detail, to control the robot a Laptop or desktop with a Wi-Fi adapter, a phone, and a Remote (Freenove Remote Control Kit, FNK0028) can be used. For the Wi-Fi connection between the robot and the typical devices it uses an ESP8266 module, and for the connection between the robot and the remote it uses an NRF24L01 module.

_________________________________________________________________

To give a step ahead on the project I implemented an MPU6050 accelerometer-gyroscope module externally, which didn’t come with the kit. This way the hexapod could climb upon tilted surfaces without falling down.

MPU6050 platform

Let me try to explain how it works:

Physics

On a tilted surface, the robot has to be able to compensate its pivot point depending on the degrees of inclination. In terms of physics, we can think about it as a 3-link pendulum, each leg acting as one. The body of the hexapod is considered the top link and the legs as the bottom ones.

Example of the needed end-effector position and the respective movement required to achieve it.

To balance the hexapod, the MPU6050 senses the displacement parameters of the hexapod body. The PID controller on the software is used to process that given data and generate corrective actions to maintain the balance. A PID controller has three components: Proportional, Integral, and Derivative. Used to calculate the error between the current orientation and the desired one. If you would like to know more about this controller watch my last project:

In a simple analogy, we can imagine the physics working as this model:

Precision-motion-platform

The stability of the hexapod is divided into two categories: static stability and dynamic stability. To be statically stable, the robot needs to be stable during its entire gait cycle, without the requirement of any force to balance the robot. While the robot is statically stable, the vertical projection of its center of mass (COM) is located within the support polygon which is formed between the legs that are in the stance phase. In the case of COM being positioned on the border or outside the support polygon, the robot falls over unless it is dynamically stable. In this case, the robot is balanced while walking due to the inertia caused by the motion and is statically unstable when it stops moving.

Support Polygon that is formed During Tripod Gait
The center of mass (COM) is located within the support polygon, where the Bottom View of the Support Polygon Decomposed into Sub-triangles

The area of the convex pattern between Leg 1, Leg 5, and the projection of COM is calculated by:

S1=  1/2 |(X1-Xc)*(Y5-Yc)-(X5-Xc)*(Y1-Yc)|                             (1)

The distance between the two ground contact points of Legs 1 and 5, is then calculated by:

|L1|=√((X5-X1)^2+(Y5-Y1)^2 )                                           (2)
h1=(2*S1)/|L1| (3)

Since the area of a triangle is the product of base and height divided by two, the perpendicular distance, from the vertical projection of COM to L1 is given by equation 3.

Heights of the sub-triangles

Then, the same process is repeated to calculate S2, h2, S3, and h3. The stability margin (SM) is the shortest distance between the position of the COM projection and the support polygon borders. In this case, the SM is equal to the mathematical expression for SM given by:

SM=min⁡(h1,h2,h3)                                                       (4)

The state of the variable indicates whether or not the robot is statically stable. The mathematical expression for is then given by:

T=1 if Sk=A                                                            (5)
T=0 if Sk≠A (6)

Here ‘A’ is the area of the entire support polygon. The variations in SM while the robot follows the body path that is used in the experiments shown in red:

Variation in the SM while the robot is following the given body path

When the robot navigates on an inclined surface as it is demonstrated in the vertical projection of the COM is closer to the borders of the support polygon, making the robot more likely to be statically unstable.

COM closer to the borders of the support polygon, and COM in the middle of the borders of the support polygon

Software

This is achieved by a geometric approach where the roll angle of the body was measured by the MPU6050 sensor. Then, the output from the sensor is added to or subtracted from θ3 that is calculated by the inverse kinematic equations, depending on the direction of the robot.

To achieve balance, the hexapod uses a combination of translational and rotational movements. The pitch & roll parameters in the code have six parameters: xMove, yMove, zMove, xRotate, yRotate, and zRotate. These variables control the movement and orientation of the hexapod in 3D space.

Loop function

In the loop function, the PID controller computes the error signal based on the difference between the current orientation of the robot and the desired one. This error signal is then used to adjust the joint angles of each leg through the pitch & roll parameters, which calculates the inverse kinematics of the hexapod.

The pitch parameter controls the translational movement of the hexapod in the x, y, and z directions, to shift the hexapod's center of mass and maintain balance. And the roll parameter controls the rotational movement of the hexapod around the x, y, and z axes, to tilt the hexapod in the opposite direction to its current tilt angle and return it to its upright position.

The output is calculated with the input of the desired position and orientation of the end effector (foot) and becomes the joint angles required to achieve that position and orientation. By adjusting the joint angles of each leg, the position of the robot's center of gravity can be shifted to maintain balance in the left/rightFront/Middle/Back.writecommands.

Posture Control — Block Diagram.

Project goal

Being hexapod robots the most efficient in terms of outdoor locomotion. Having a PID controller is crucial to handle all kinds of terrains. Especially when carrying packages, the balance control comes to allow the task to have more stability and fewer risks.

This is the before and after the MPU implementation:

FreeNove and Sheloby climbing

With the PID controller, the robot was able to climb up on a surface tilted more 20º than previously.

The goal was achieved, because, if we take a closer look, we see that the robot’s body and the end-effector make a 90º angle. Meaning the robot now keeps it self stable while climbing on rough terrain:

Sheloby- side view while climbing

References

Hexapod dynamics libraries: https://github.com/topics/hexapod-robot

Building tutorial: https://youtu.be/nivTZeGthf4

Remote control tutorial: https://youtu.be/fK7IHMA60F4

GitHub — hexapod’s code: https://github.com/OttoDIY/PLUS_Hexapod

Programming the hexapod: https://www.youtube.com/playlist?list=PLXTrmSGPbzrRLA5vsn1hAaPLZvaXSVDq3

Stability control: https://hackaday.io/project/21904-hexapod-modelling-path-planning-and-control/log/62326-3-fundamentals-of-hexapod-robot

--

--

Marta Bernardino

Robotics innovator| Activate at The Knowledge Society | High school finalist | Poet amateur Street artist amateur https://linktr.ee/martabernardino