Self-Balancing Cube
This project is a the construction of a 3D printed cube, which balances itself on one of its edges via a Gyroscope and a control loop that regulates a flywheel.
Supplies
Components
- 1 Gimbel Motor iPower GBM4108H-120T Gimbal Motor
- 1 Encoder AMT103-V
- 1 Motor Controller Board SimpleFOCShield
- 1 IMU (Inertial Measurement Unit) GY-521
- 1 Microcontroller Nucleo F411RE
- 1 Lithium-polymer accumulator Dilwe 11.1 V LiPo
- 1 DCDC converter XL6009 DC-DC
Material
- Cable ties
- Solder
- Steel pins
- Adhesive tape (Powerstrip)
- Screws:
- 8x cylinder head M6x10
- 6x standard M3x9
- 3x standard M3x6 and 3x matching Nuts
- 1x standard M8x45
3D Print Files and Code
Components
Motor and Motor control
The motor in use is an iPower GBM4108H-120T gimbal motor, which has high torque but low maximum speed, making it well suited for the task at hand. To accurately determine the rotor position and rotation speed, the motor is equipped with an AMT103-V encoder. This information is crucial for controlling the gimbal motor. The system utilizes a SimpleFOCShield controller, which relies on the encoder data to measure the motor’s angle and speed—key inputs for the control algorithm responsible for balancing the cube.
Microcontroller
The microcontroller is a Nucleo F411RE. This was chosen for its good processor clock speed and its large programme memory space, which meets the minimum requirement of 49,704 bytes. In addition, an Arduino Uno header should be available in order to be able to mount a standard Arduino shield.
Inertial Measurement Unit (IMU)
The IMU in use is a GY-521, featuring an MPU6050 chip, which is employed to determine the angle relative to Earth. It is crucial to ensure that the connection to the I2C pin between the IMU and the microcontroller uses a short cable. If the cable is too long, connection issues can arise, potentially causing the entire program to enter a deadlock. The issue most likely originates from the motor causing electromagnetic radiation, so it also helps to keep the IMU away from the motor.
Basic framework
The basic frame of the cube consists of two base plates (17x17cm) on which the open cube can stand. These are connected to each other by three inner walls (16x8.1cm) which are plugged in and can be additionally secured by bolts if necessary. The other components such as the motor, microcontroller, IMU, battery and flywheel are mounted or taped onto these inner walls. There are extra bolts for the microcontroller (front right) and recesses for the motor (controller) (front left).
Flywheel
The flywheel has a diameter of 14cm and is equipped with 8 holes for the M6x10 screws. These increase the weight of the flywheel.
Power supply
The power supply is provided by a lithium-polymer rechargeable battery with 1500mAh capacity, 11.1V voltage and 40C. To keep the battery requirements low in terms of voltage and weight, a DCDC converter is used. This converts to 20V voltage with up to 2A current, which are needed in order to power the motor.
Assembly
The prerequisite for following this section is the successful 3D printing of the components and soldering of the controller board (see picture).
- Engine inner wall
- Screw cylinder head screws M6x10 into flywheel
- Fasten engine to inner wall of engine with two M3x9 bolts and corresponding nuts
- Fasten flywheel to engine with remaining four M3x9 bolts with washers
- Push the M8x45 screw through the flywheel and hollow shaft of motor (alternatively, there is a 3D print component to substitue for the screw)
- Set the DIP switch in the encoder to 1010 (see picture)
- Tape the encoder to the back of the motor with the screw pushed through
- Inner wall of board
- Insert the board bolt into the inner wall of the board
- Fix the microcontroller with the three M3x6 screws
- Plug the controller board onto the microcontroller
- Plug IMU onto controller board (PINs SCL and SDA)
- Inner wall
- Glue battery to inner wallFix DCDC converter with cable ties
- Insert the inner walls between the two base plates and secure them with metal pins if necessary.
Wiring
The wiring is done as shown in the pictures. The switch can optionally be soldered between the DCDC converter and the battery.
Programming
For the programming we used the Arduino FOC library to control the motor and to get various data from the encoders. In addition, the i2cdevlib library was used to control the IMU.
Adaptive Angle Adjustment
Low-computation, low-memory, moving average filter for adaptively calculating the cube's angle of balance. This enables the cube to smoothly adjust the angle it balances around to be more accurate and at the same time it can compensate for slight differences in weight distribution.
Linear-quadratic controller
The LQ controller or linear-quadratic controller, also called Riccati controller, is a state controller for a linear dynamic system whose feedback matrix is determined via the minimisation of a quadratic cost functional. This control loop is what regulates the motor speeds based on the motors speed, the angluar velocity of the cube and the cubes angle to ensure the cube stays in balance.