Connecting to sources…

How to build Balancio-Kit

38 steps to build Balancio-Kit, with the source documents.

Balancio-Kit is an ultra-low-cost, self-balancing educational robot that runs a neural network to maintain balance and supports wireless control. The repository provides printable 3D parts, a component list, an electrical diagram, and mechanical assembly instructions.

Software

  • Install Arduino IDE 2

    Install Arduino IDE 2 by following the linked instructions to program and compile the NodeMCU ESP32.

  • Open Preferences

    Open “File” → “Preferences” in the Arduino IDE.

  • Add ESP32 board URL

    Add https://dl.espressif.com/dl/package_esp32_index.json to “Additional Boards Manager URLs”, then click “OK”.

  • Open Boards Manager

    Go to “Tools” → “Board:” → “Boards Manager…”.

  • Install ESP32 board package

    Search for “esp32” and install “esp32 by Espressif Systems” version 2.x by clicking “Install”.

  • Select NodeMCU-32S board

    Go to “Tools” → “Board:” → “ESP32 Arduino”, then select “NodeMCU-32S”.

  • Select microcontroller port

    Go to “Tools” → “Port” and select the corresponding port to which the microcontroller is connected.

  • Open Library Manager

    Go to “Sketch” → “Include Library” → “Manage Libraries…”.

  • Install MPU6050 library

    Install “MPU6050 by Electronic Cats” version 1.0.0.

  • Install PS3 Controller library

    Install “PS3 Controller Host by Jeffrey van Pernis” version 1.1.0.

  • Install EloquentTinyML library

    Install “EloquentTinyML by Simone Salerno” version 0.0.7.

  • Choose whether to run simulation

    Simulation is optional and is not needed to operate or assemble the robot; you can proceed directly to calibration.

  • Install Conda tooling

    Download and install Miniconda; Anaconda can also be installed.

  • Create the balancio environment

    In the Miniconda console, run `conda env create -f requirements.yml`, or import the repository's requirements.yml file from the environments tab in the Anaconda GUI.

  • Activate the balancio environment

    Run `conda activate balancio` in the Miniconda terminal, or click the balancio environment in the environments tab of Anaconda.

  • Run the simulation library setup

    Run the simulation library's setup.py file inside the activated environment.

  • Test the simulation installation

    Run the pid.py script to test the simulation installation.

  • Import the Balancio application

    Enter the MIT App Inventor website and import the Balancio-kit/app/app.aia file.

Calibrate and test

  • Open WiFiScan example

    Go to “File” → “Examples” → “WiFi” → “WiFiScan” to open the generated test sketch.

  • Upload WiFiScan sketch

    Press the “Upload” button in the generated sketch.

  • Confirm successful upload

    Check that the console displays the “Done uploading” message.

  • Hold Boot button during upload

    If the program cannot be uploaded, try holding the board’s “boot” button during the upload; this should be done only the first time.

  • Open the IMU calibration sketch

    Open Balancio-kit/Mcu/Src/imu_calibration/imu_calibration.ino with the Arduino IDE.

  • Hold the robot level and steady

    Place the robot with the IMU parallel to the floor and hold it steady.

  • Read the IMU offsets

    Upload the program to the board and use the serial monitor to obtain the IMU offsets.

  • Set the gyroscope offsets

    In balancio-kit/mcu/src/main/config.h, set the X, Y, and Z gyroscope offsets to 181, 77, and 60.

  • Account for accelerometer gravity

    Gravity must be considered when measuring the accelerometer offsets; measure them only with gravity perpendicular to that direction.

  • Open the balance main sketch

    Open balancio-kit/mcu/src/main/main.ino in the Arduino IDE.

  • Hold the robot at equilibrium

    Hold the robot in the equilibrium position.

  • Read the equilibrium angle offset

    Upload the program to the board and use the serial monitor to obtain the angle offset.

  • Set the static equilibrium angle

    Set STATIC_ANGLE to -0.04 in balancio-kit/mcu/src/main/config.h.

  • Remove the driver's 12V jumper

    Remove the 12V jumper from the driver.

  • Choose the PID parameters

    Choose the PID parameters to use.

  • Set the PID constants

    In balancio-kit/mcu/src/main/config.h, set KP, KI, and KD to 2000, 22000, and 20.0.

  • Test the PID constants

    Test the constants; after removing the jumper, testing is possible even with the cable connected. Be careful when doing this.

  • Select the PID controller

    In config.h, set CONTROL_ALGO to PID to stabilize Balancio with a PID controller.

  • Select the reinforcement-learning agent

    In config.h, set CONTROL_ALGO to RL to stabilize Balancio with a reinforcement-learning agent.

Use it

  • Use the application over Bluetooth

    After importing it, the application can be used from a phone over Bluetooth.

Common problems

  • A high center of mass and low rotational inertia undermine self-balancing stability #9
  • The current motor and wheel combination has unverified self-balancing feasibility #2
  • READMEs mislabel calibration as simulation and differ between languages #13 #19
  • An incorrect switch image in the blueprint can cause wiring mistakes #18
  • Builders lack the battery-protector reset procedure for some battery replacements #15
  • Reinforcement-learning training and model saving are cumbersome and hard to reproduce #10
  • ESP32 2.x code is incompatible with breaking changes in the 3.x library #16

Documents