Section 4: Flight-Control-Functions.

==================== xxxxxxxxx =====================

.......... Flight-Control Code Discussion ..........

Below table shows the full list of Flight-Control .ino source-code files:

Full list of .ino-Files.

=========== Flight Control Blinking LED's =============

There are 5 colored LED's as follows connected to the PCA9685 board:
Green LED Pin 0
White LED Pin 2
Blue LED Pin 4
Yellow LED Pin 6
Red LED Pin 11

The purpose of the LED's is to give the user information about the performance or status of critical control processes.

At start of the Set-Up phase all 5 leds are blinking 5 times to check their connection. The green LED will continue to blink as confirmation that all sensors have been found and their I2C addresses are OK i.e. PCA9685 => 0x40, MPU6050 => 0x68, MAG3110 => 0x0E and BMP280 => 0x76. If not all Sensors are found the RED control LED on Pin 11 is Switch-ON. Further execution of the code is stopped (a delay of 100.000sec is invoked).
During the gyro drift calculation the yellow LED is blinking.

The main loop is controlled by flags. Coming from Set-Up the main loop is entered with the flag set to Flag=0. With this value the GPS position is read out and checked if the calculated flight-distance is within the user set max.reach. When OK the flag is set to: Flag=10. At this point, the green LED is switched off and the motors revved-up close to take-off power. The control flag is set to: Flag=20, and the phase of Directional Climing and Cruise to Target is started. Full flight control is active to autonomouly guide the drone to the target.
Note: In case of prototype testing, the motor power should be controled with the transmitter, In this way, and in case the drone gets out of control, the rpm can be reduced, and landing be forced.

In each loop cycle the G_Value is calculated from the calibrated accelerometer readings. In case this calculated value exceeds a certain user set threshold value i.e. the accelerometer readings are expected to be inaccurate, flight control is switched over from accelerometer readings to gyro readings. When the gyro takes over control the white LED is blinking.
When based on the GPS reading the Flight_Distance is within reach the Green LED blinks. The blue LED blinks when the Target is beyond reach (possibly based on an erroneous GPS reading).

Free-Drones Company 2022