Open-Cube, self-balancing robot

Nice toy to play with… uses internal gyroscope and accelerometer, see description below.

Segway is a robot that balances on two wheels using data obtained from an integrated IMU (three-axis gyroscope and accelerometer).

The tilt angle with respect to the horizontal axis of the robot is determined by fusing the gyroscope and accelerometer data using a complementary filter. A high-pass filter is applied to the gyroscope data and a low-pass filter is applied to the accelerometer data.

The position of the robot and the angle of rotation about the vertical axis are determined by the rotary encoders of the motors. The distance to the obstacle is measured by an NXT ultrasonic sensor.

The robot control is mediated by five PID regulators. The most important of these are the three cascaded position, velocity and tilt regulators, which result in desired power output on the motors. These regulators maintain the vertical position and allow translational motion. A fourth rotation regulator ensures that the robot maintains a constant rotation about the vertical axis and rotational motion. The fifth regulator allows deceleration and distance maintenance in front of an obstacle.

The robot can be controlled from a computer connected via Bluetooth to the ESP32 module in the cube. A Simulink model running on the computer is used to communicate with the cube. This way the robot states such as position, speed, tilt and more can be monitored in real time. Furthermore, the controller constants can be set remotely, which allows a quick experimental determination of these constants. It is also possible to send motion commands for forward motion and rotation.  In the left part of the Simulink model, controller constants can be set and motion commands can be entered, graphs can be displayed on the right, and a block in the middle provides wireless communication. In another configuration, the cube can be connected from a computer or mobile phone via Wi-Fi to a web server running on the ESP32. Using the web server buttons, translational and rotational motion commands can be sent to the robot and the current regulator action, current and reference position and velocity can be monitored.

You can check the code here: https://gitlab.fel.cvut.cz/open-cube/firmware/-/tree/main/programs/examples/robots

MATLAB Simulink – serial line (Bluetooth) connection to the Open-Cube via ESP32 module…
Some graphs from Simulink – first trace is requested and real position….
A simple web page created with ESP32 (only used for wireless communication in Open-Cube), buttons and other items are configurable with Python script from RP2040…
Segway with a final Open-Cube box version – azure blue PLA by PRUSA….
Segway with the Open-Cube second prototype… and NXT ultrasonic rangefinder for obstacle avoidance…
….with a big friend from Department of Control Engineering, FEE, CTU in Prague