Skip to content

Latest commit

 

History

History
323 lines (224 loc) · 13.9 KB

README_EN.md

File metadata and controls

323 lines (224 loc) · 13.9 KB

Balancio-Kit

license_MIT   stars   language_sp language_en


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.

Models

Stabilty Ease of Assembly 3D Printing Requirement 3D Printing time 3D printing diagram Image
V 0.7 (Recommended) ⭐ ⭐ ⭐ ⭐ ⭐ ⭐ Yes
  • Batteries 47m
  • Structure 2:36 h
0.7 3D stl
V 0.6 AKA:Wall-e ⭐ ⭐ ⭐ Yes
  • Underside 5:25h
  • Upperside 5:11h
  • Under structure 58m
  • Upper Structure 55m
  • Head 3:19 h
0.6 3D stl
V 0.5 ⭐ ⭐ ⭐ Yes
  • Rim 49m
  • Structure 4:42h
0.5 3D stl

Printing settings

  • Nozzle Thickness : 0.4 mm
  • Layer Height : 0.3 mm
  • Perimeters: 3
  • Top and Bottom Solid Layer: 3
  • Infill: 20%

Assembly 🔧

Component Component Image
Base plate (3D printed structure)
NodeMCU ESP32 microcontroller
IMU MPU 6050
2 - 6v gear motors with wheel "for Arduino"
H-Bridge L298N
2 - 18650 batteries with corresponding battery holder
Battery charger
BMS FCD-2S-2
Switch
10 - DuPont wires
1m electrical wire (2x50 cm each)

Wiring Diagram

Mechanical Assembly

  1. 3D print the respective model.
  2. Fit parts in their final position.
  3. Hold the motors in place with seals and/or glue.
  4. Connect the components following the wiring diagram.

Installation 💾

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.

Microcontroller

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:
  1. In the IDE, go to 'File' → 'Preferences'.

  2. In the "Additional Boards Manager URLs" field, add the following: https://dl.espressif.com/dl/package_esp32_index.json. (Then click 'OK').

  3. Go to 'Tools' → 'Board: ' → 'Boards Manager...'.

  4. Search for "esp32", and install "esp32 by Espressif Systems" by pressing the 'Install' button.

  5. Indicate the IDE that we are going to use an esp32. Go to 'Tools' → 'Board:' → 'ESP32 Arduino' → 'NodeMCU-32S'.

  6. 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

Simulation

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:

  1. To use and install conda, download miniconda (you can also install Anaconda), following the steps specified in the following link.
  2. 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:
    • Miniconda: Execute the following command in the console: conda env create -f requirements.yml. Where requirements.yml is the file found inside the repository and already downloaded.
    • Anaconda: In the Anaconda GUI: In the environments tab, click on import and specify file in file.

  1. 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.
  2. In the activated environment, execute the file setup.py: python setup.py
  3. Test the installation by running the following script: python pid.py

Physical Variables of version 0.7

Structure

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²

Wheel

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²

Application

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.

Calibration

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.
  1. Place the robot with the IMU parallel to the floor and hold it steady.

  2. Upload the program to the board and use the serial monitor to get the offsets from the IMU.

  3. 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
  1. 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`.
  1. Hold the robot in the equilibrium position.

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

  3. 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
  1. Remove the 12v jumper on the driver.

  2. Select PID parameters

  3. 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
  1. 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"

TODO

  • 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.

Known Bugs

  • Wheel spins on startup

Contributions

Pull requests are welcome, for major changes, please open a issue to discuss the desired changes.

License

MIT