Ultra-low-cost educational self-balancing robot 🤖, capable of running a neural network to maintain balance and being wirelessly controlled 🖲️.
Developed for educational purposes to teach RL, ML, AI and control theory.
Stabilty | Ease of Assembly | 3D Printing Requirement | 3D Printing time | 3D printing diagram | Image | |
---|---|---|---|---|---|---|
V 0.7 (Recommended) | ⭐ ⭐ ⭐ | ⭐ ⭐ ⭐ | Yes |
|
0.7 3D stl | |
V 0.6 AKA:Wall-e | ⭐ ⭐ ⭐ | ⭐ | Yes |
|
0.6 3D stl | |
V 0.5 | ⭐ | ⭐ ⭐ ⭐ | Yes |
|
0.5 3D stl |
- Nozzle Thickness : 0.4 mm
- Layer Height : 0.3 mm
- Perimeters: 3
- Top and Bottom Solid Layer: 3
- Infill: 20%
- 3D print the respective model.
- Fit parts in their final position.
- Hold the motors in place with seals and/or glue.
- Connect the components following the wiring diagram.
First, the repository must be cloned. This can be done either by downloading the
as a .ZIP, or by running git clone https://github.com/UDESA-AI/balancio-kit.git
in console.
The installation has 3 main modules: Microcontroller, Simulation and Application. These are fundamental for the complete functioning of the project, but the installation of each of them can be done in different order.
Installing the IDE
To program and compile the ESP32 NodeMCU we will use the Arduino IDE 2 . To do this must be installed by following the steps specified in the following link: https://www.arduino.cc/en/software .Microcontroller Setting
Once the IDE is installed, the microcontroller we are going to use must be enabled. To do this, the following steps must be followed:-
In the IDE, go to 'File' → 'Preferences'.
-
In the "Additional Boards Manager URLs" field, add the following: https://dl.espressif.com/dl/package_esp32_index.json. (Then click 'OK').
-
Go to 'Tools' → 'Board: ' → 'Boards Manager...'.
-
Search for "esp32", and install "esp32 by Espressif Systems" by pressing the 'Install' button.
-
Indicate the IDE that we are going to use an esp32. Go to 'Tools' → 'Board:' → 'ESP32 Arduino' → 'NodeMCU-32S'.
-
In 'Tools' → 'Port', select the port corresponding to where the microcontroller is connected.
Arduino Libraries
We will then proceed to install the arduino libraries we are going to use:-
For that go to 'Sketch' → 'Include Library' → 'Manage Libraries...'.
-
Search for and install the following libraries, specifying the corresponding version:
- MPU6050 by Electronic Cats (version 1.0.0)
- PS3 Controller Host by Jeffrey van Pernis (version 1.1.0)
- EloquentTinyML by Simone Salerno (version 0.0.7)
Initial Run
To test the installation, we will run a test example: - go to 'File' → 'Examples' → 'WiFi' → 'WiFiScan'. - In the generated sketch, press the 'Upload' button 📲 - If everything worked correctly, you should see a 'Done uploading' message in the console.Possible errors:
- If the program fails to be uploaded to the microcontroller, try to hold down the "boot" button present on the board, while uploading. This should only be needed once.
- On GNU/linux if Arduino fails to open '/dev/ttyusb0' with error 'permission denied' try changing permissions of device.
- Serial errors on Arduino IDE 2 migth be solved by pip installing pyserial
The simulation is optional; it is not necessary for the robot's operation and assembly. You can skip directly to the calibration phase.
The simulation runs in Python 🐍, and uses several packages. For ease of installation, we will use Conda.
The following steps must be followed:
- To use and install conda, download miniconda (you can also install Anaconda), following the steps specified in the following link.
- We will create a conda environment, where we will host our packages. This can be done either from the console (in case you have downloaded Miniconda) or from a GUI (in case you have downloaded Anaconda). Respectively:
- Activate the created environment, called balance:
- Miniconda: Execute in terminal
conda activate balancio
. - Anaconda: In the environments tab, click on the environment you want to activate.
- Miniconda: Execute in terminal
- In the activated environment, execute the file setup.py:
python setup.py
- Test the installation by running the following script:
python pid.py
Mass without wheels: 0.244 kg
Position of the centre of mass relative to the axis of the engines and the symmetrical centre of the body:
- x = 1.55 mm
- y ~= 0 mm
- z = 31 mm
Inertia without wheels from centre of mass:
- Ixx = 0.0006945 kg.m²
- Ixy ~= 0 kg.m²
- Iyy = 0.0006536 kg.m²
- Ixz = -0.000013447 kg.m²
- Iyz ~= 0 kg.m²
- Izz = 0.0001937 kg.m²
Mass of a wheel: 0.029 kg
Position of the centre of mass relative to the axis of the engines and the edge of the grip:
- x = 0 mm
- y = 15.6 mm
- z = 0 mm
Inertia of the wheel from the centre of mass:
- Ixx = 0.000011729 kg.m²
- Ixy ~= 0 kg.m²
- Iyy = 0.000021531 kg.m²
- Ixz ~= 0 kg.m²
- Iyz ~= 0 kg.m²
- Izz = 0.000011729 kg.m²
The application is created in MIT App Inventor .
Simply go to the website and import the .aia en App Balancio . After that, the application can be used via bluethooth from a mobile phone.
These instructions assume knowledge of using the arduino IDE.
IMU Calibration
1. Open `Balancio-kit/Mcu/Src/imu_calibration/imu_calibration.ino` with the Arduino IDE 2.-
Place the robot with the IMU parallel to the floor and hold it steady.
-
Upload the program to the board and use the serial monitor to get the offsets from the IMU.
-
Modify the gyro offsets in the
balancio-kit/mcu/src/main/config.h
file in:
// IMU calibration parameters
#define X_ACCEL_OFFSET -1775
#define Y_ACCEL_OFFSET 756
#define Z_ACCEL_OFFSET 2706
#define X_GYRO_OFFSET 181
#define Y_GYRO_OFFSET 77
#define Z_GYRO_OFFSET 60
- For the accelerometers calibration the offsets should be calculated taking into account the gravity only calibrationg the offset when the gravity vector is perpendicular to the direction being calibrated.
Calibration of the balance angle
1. Open `balancio-kit/mcu/src/main/main.ino`.-
Hold the robot in the equilibrium position.
-
Upload the program to the board and use the serial monitor to obtain the angle offsets.
-
Modify the balance angle in the
balancio-kit/mcu/src/main/config.h
file on the line:
// Angle of (approximate) static equilibrium
#define STATIC_ANGLE -0.04 // Calibrated point
Calibrating the PID constants
-
Remove the 12v jumper on the driver.
-
Select PID parameters
-
modify the PID constants in the
balancio-kit/mcu/src/main/config.h
file on the lines:
// PID Constants for pitch control
#define KP 2000
#define KI 22000
#define KD 20.0
- Test the constants, if the jumper was removed you can test even with the cable connected. **Be careful when doing this!
Once the robot has been correctly configured, various configuration parameters can be selected in the corresponding file (config.h
).
Among them, you can select the type of controller you want to use to stabilize the Balancio.
For example, in case you want to use a PID controller:
// Control algorithm type
#define CONTROL_ALGO "PID".
In case you want to use a reinforcement learning agent:
// Control algorithm type
#define CONTROL_ALGO "RL"
- initial commit
- Develop bluetooth application
- Create RL agent
- Mechanical design
- Publish STL of mechanical design
- Publish STEP of mechanical design
- Create electronic diagram
- Clarify which data to get from imu calibration.
- Wheel spins on startup
Pull requests are welcome, for major changes, please open a issue to discuss the desired changes.