Skip to content

Architecture

sebastiano cocchi edited this page May 19, 2023 · 2 revisions

DroneIno software architecture is organized with two main files: Config.h and main.c.

The main.c file

The main file is the skeleton of the software. It has three configurations: -SETUP: used to save in the processor memory the orientation of the controller levers and verify the orientation of the gyroscope in space. -CALIBRATION: utilized to verify the correct reading of all the sensors, verify the right rotation of the props, calibrate the weight of the props, and, finally, train the neural network. -FLIGHT_CONTROLLER: is the actual flight controller and manages all the features defined in the previous chapter.

The functions are all defined in the /include directory, while the /lin/BPNN library defines the neural network's functions.

The Config.h file

Overview

Take a look at the Config.h file where you can set the hardware components, the battery minimum voltage, the sensors you use and others.

Pinmap

Check that your pinmap corresponds to the one defined in the pinmap folder, otherwise change it. The define board you use by defining PINMAP: (ESP32_D1_R32, ESP32_DEVKIT).

Sketch configuration

There are three type of sketched that can be uploaded on DroneIno: SETUP, CALIBRATION and FLIGHT_CONTROLLER. They have to be uploaded in the following order: * define UPLOADED_SKETCH as SETUP, upload the sketch and follow the instruction appearing in the serial monitor; * define UPLOADED_SKETCH as CALIBRATION, upload the sketch and write, using the commands suggested in the documentation, the sensor or the the part of the drone you want to check. Propellers calibration. The readings will be printed on the Web Serial (see docs for connection). Dial, one at a time, in the web serial 1, 2, 3 and 4 (each number corresponds to a specifics motor: 1) right front CCW, 2) right rear CW, 3) left rear CCW, 4) left front CW, 5) all motors together. On the web serial will compare the accelerometer readings. The lower these number, the stabler the props. Use them to calibrate (i.e. add scotch) to the propeller in order to make them more balanced; * define UPLOADED_SKETCH as FLIGHT_CONTROLLER and upload the sketch. DEBUG mode enables the Serial for debugging, otherwise, no serial monitor. To start the drone: move the left stick to the bottom left. To stop the drone: move the left stick to the bottom right.

AUTOLEVELING

Set to true, if you want to compensate the drone oscillations, accordingly to the gyroscope readings. Set to false, if you are not intend to autolevel.

ALTITUDE

Set the name of the barometer sensor you are using. For now, only BMP280 is allowed.

GPS

Set GPS type, if you got, or leave OFF if you are not using a GPS at all. I recommend to use a baud rate about 9600, it is sufficient. Set you current UTC time zone (e.g. for UTC+2 set 2) to adjust the time readings to your region.

BATTERY

In this part you set the battery specs, the resistances R1 and R2 you have used for the voltage divider, and more. Battery readings can be useful to compensate the voltage lowering, but, until now, this feature is not stable, thus leave BATTERY_COMPENSATION false.

TELEMETRY

DroneIno uses WiFi for telemetry. It involves the NATIVE ESP32 WiFi access point (AP). Using this, you can easily set PID parameters for the PID adjustment (without continuing stopping and uploading the code). Remember to write the PID changing on a paper or whatever. Indeed, when you turn off the drone, the PID parameter changed are NOT saved anywhere. On the other hand, as said in the documentation, it is preferable to configure an external ESP32-CAM. This choice will bring: * video streaming; * SD card storage for PID parameter savings and flight data recordings.

Setup

Uncomment the line "#define UPLOADED_SKETCH SETUP" (and comment out the other two defining UPLOADED_SKETCH CALIBRATION and UPLOADED_SKETCH FLIGHT_CONTROLLER) in the Config.h and upload the sketch to your board. This step, battery remains still disconnected.

  • in the first part of the SETUP you need to turn on the RC controller and place the trims on the center to estimate the mid point position of the levers. Then, following the instructions printed on the serial, extend the levers to all their extensions.

  • the second part of the SETUP check gyroscope address, and the orientation of DroneIno.

  • the third part controls the LEDs and saves the relevant informations on the EEPROM.

Calibration

If the setup sketch succeeds, leave uncommented only the line "#define UPLOADED_SKETCH CALIBRATION" in the Config.h and upload the sketch. To check the propellers direction and the propeller calibration you can connect the battery to the motors.

Note: DO NOT connect the battery to the board (but only to the motors) in this configuration since the USB is connected.

Send the following characters to the serial monitor:

  • 'r' to check if the transmitter signal is decoded correctly; move the trim and check that:
    • throttle: low 1000us| full 2000us;
    • roll: left 1000us| right 2000us;
    • pitch: left 1000us| right 2000us;
    • yaw: left 1000us| right 2000us;
  • 'g' to verify that the gyroscope is set up correctly (the angles should be between approximately [-45°, 45°]):
    • nose down: negative angle;
    • left down: negative angle;
    • yaw left: negative angle;
    • nose up: positive angle;
    • left up: positive angle;
    • yaw right: positive angle;
  • '1', '2', '3' or '4' to check the rotation direction (see figure at the top):
    • 1: CCW;
    • 2: CW;
    • 3: CCW;
    • 4: CW;
  • '5' to use all the motors.

If the motors rotate in the opposite direction, just exchange one of the three cables between the ESC and the motor.

Note: if CALIBRATION sketch is uploaded, you can also check the readings of:

  • the altitude sensor (send 'a' on serial);
  • battery readings (send 'b');
  • blinking leds (send 'l');
  • printing the EEPROM memory (send 'e');
  • GPS (send 's').

ESCs calibration

Calibrate the ESCs without propellers. You'd be better to find out how to calibrate your ESCs. Usually this is done as in this video.

Propellers calibration

With calibration sketch still uploaded, calibrate the propellers. Send the number of the motor to the serial and read the accelerometer measurements which are printed on the serial. Try to lower these numbers by adding some scotch.

Flight controller

Finally, uncomment the "#define UPLOADED_SKETCH FLIGHT_CONTROLLER" line in the Config.h and upload the sketch.

Try first without the propellers!

Start and stop commands

Turn on the battery and the RC-controller, and wait until all the calibration is done (signaled by the led blinking). Move the left stick:

  • to the bottom-left to start the motors;
  • to the botom-right to stop the motors.

If this is done correctly, move to the following step. Otherwise, you may have problem in the RC signals, thus check it using the CALIBRATION.