RC Airplane Remote Control/Gyroscope - Stabilizer Flight Controller
by abdelrazzac10 in Circuits > Arduino
346 Views, 1 Favorites, 0 Comments
RC Airplane Remote Control/Gyroscope - Stabilizer Flight Controller
In this instructable, I am making a remote control for RC airplanes. The proposed remote control has stabilization capabilities, making it a true flight controller. The remote control is based on Arduino Uno and Arduino Nano, the MPU6050 accelerometer/Gyroscope, and the NRF24L 2.4 GHz RF transceiver. Switching between regular control mode of the airplane, stabilized control mode, and control surface trimming mode is made easy using several switches on the transmitter.
In the regular control mode, the user can control the elevator, the rudder, and the ailerons of the airplane, as well as the throttle of the motor using two joysticks.
Once the Trim switch is toggled, the remote control enters the trimming mode. In this mode, the user can change the zero angles of the control surfaces: elevator, rudder, and ailerons. The user uses the same joystick to trim its corresponding control surface, making trimming easy and straight forward. Once the Trim switch is toggled again, the new zero angles are saved, and any deviation in the regular control mode is made from the new zero angles.
An index finger switch is used to activate the stabilized mode. Once this switch is toggled, the elevator and the ailerons are moved automatically to ensure the fuselage is maintained parallel to the ground. This is made possible by measuring the airplane angles using the MPU6050 sensor and applying corrective moves to return the airplane to its stable position. While in the stabilization mode, if the user moves the ailerons/elevator joystick the airplane responds to these moves as intended. If the user leaves this joystick, the airplane is stabilized automatically. So to activate the automatic stabilization, the user has to switch the Stabilization switch on, and leaves the aileron/elevator joystick untouched.
Supplies
In this project, I used an Arduino Uno microcontroller for the transmitter, and an Arduino Nano microcontroller for the receiver.
Three 9g servomotors are used to control the three control surfaces of the airplane: elevator, rudder, and ailerons. A 30A ESC and a brushless DC motor should be used for the throttle of the airplane. However, I am not using it now seeking simplicity (However, throttle control is included in the transmitter and receiver codes).
Two NRF24L01 RF transceiver modules. I used the one with power amplifier and a Low-Noise Amplifier (LNA) which has a theoretical range of 1.1 Km (https://electropeak.com/learn/interfacing-nrf24l01-wireless-2-4-ghz-transceiver-module-with-arduino/).
An MPU6050 Gyroscope/Accelerometer to measure the deviation angles (attitude angles) of the airplane and perform corrective moves in the stabilized mode.
Two joystick modules.
A plastic box to house the remote control. In my case, I used an old cash register toy from my kids' supply!
The Transmitter
The first step in the transmitter is to connect the RF module. I followed the steps presented by JD_K in his instructables page entitled "DIY Arduino Adapter for the NRF24L01". The link of the page is: https://www.instructables.com/DIY-Arduino-Adapter-for-the-NRF24L01-1/
I used the no-voltage regulator circuit, but connected the CE pin of the NRF24L to pin 8 of the Arduino Uno, and the CSN pin of the NRF24L to pin 10 of the Uno. In the pictures above, I am showing the first attempt of the NRF24L adapter using the RF module without power amplifier. I made two adapters of the same type, and tested/trimmed/calibrated them until I was able to transmit and receive packets. I then swapped the regular NRF24L with the module with power amplifier.
The joystick modules have 5 pins each: 5v, Gnd, x-axis, y-axis, and the push button. I connected 5v-Gnd from the Arduino Uno to the power pins of both joysticks. The throttle of the airplane (x-axis or y-axis according to the orientation of the first joystick) is connected to channel A2 of the Uno (2nd analog channel). The yaw of the airplane (the second axis of the the throttle joystick) is connected to A1. For the second joystick, its first axis is connected as ailerons to A4; while its second axis is connected as elevator to A5. Two digital switches are added to choose Trim mode and stabilize mode. These switches are connected to D3 and D4 of the Uno (Digital inputs 3 and 4).
Once everything is connected, I took my dremel and made two holes in a plastic box (a toy cash register in my case) to form the case of the transmitter.
For the code, after tinkering with it for a long time I decided to use the code provided by "kendin yap" in the following link:
https://www.rcpano.net/2020/04/09/how-to-make-6-channel-radio-control-for-models-diy-proportional-rc/
However, I am using the auxiliary channels as digital inputs (for the Trim and stabilize mode) instead of one digital and one analog channels. The changed code can be found below. The last figure above shows the NRF24L and the channel connections as presented by kendin yap.
The Receiver
The first step in the receiver/Gyroscope is to connect and test the MPU6050 gyroscope/accelerometer. I made the connection using a prototype board with Arduino Nano. After testing the sensor successfully, I needed to connect the NRF24L RF transceiver and the servomotor connections.
I am a big LAZY, so instead of updating the prototype board I found an easier way to realize the receiver. A friend of mine has designed and printed on PCB a MultiWii flight controller for quadrotors using 4 ultrasonic sensors, MPU6050, and NRF24L. However, he found some flaws in the design and PCB printing, so the design and the boards were discarded. My friend has given me one of his discarded boards, I made some changes to it, and used it as the receiver of my project.
For the MPU6050 connections, Vcc to Nano 3v3, Gnd to Nano Gnd, SDA to Nano A4, and SCL to Nano A5.
For the NRF connections, CE -> Nano D7, SCK -> Nano D13, MISO -> Nano D12, CSN -> Nano D8, MOSI -> Nano D11, IRQ -> Not connected.
The servomotors and the ESC are connected to the following Nano PWM pins: Throttle -> Nano D3, Ailerons -> Nano D5, Rudder -> Nano D9, Elevator -> Nano D10.
Now for the codes... I am also using the receiver code from "rcpano.net" but made many changes in order to incorporate the trimming mode and the stabilization mode.
To use the MPU6050, you need first to calibrate it! you need to measure its offset values and include them in your code. You need to run the code "Nano_CalibrateMPU.lnk" and register the offset values and include them in the FindAttitude function. The code can be found below; make sure the sensor or the receiver is parallel to the ground while performing this task. For me, the offsets were very large because the MPU6050 was not placed according to the axes drawn on it, so the transformation values were very big. Below you can find the offset values I am using:
// Added by ABD
// Horizontal Nano board
mpu.setXGyroOffset(40);
mpu.setYGyroOffset(58);
mpu.setZGyroOffset(-47);
mpu.setXAccelOffset(-7400);
mpu.setYAccelOffset(-4704);
mpu.setZAccelOffset(2740);
You need to get the offset values from the output of the code "Nano_CalibrateMPU.lnk" and replace these values in the lines above. In the testing video below, you can realize that I am placing the receiver perpendicular to its real axes, so a change in the roll angle (according to the pseudo airplane made of cardboard) excites the stabilization of the pitch angle of the airplane (and the change of the elevator instead of the aileron servomotor). I should have placed the receiver correctly according to the pseudo airplane for better interpretation.
If you use the "FindAttitude" function inside a long code (the function that finds the airplane angles using the gyroscope) the function will returns "FIFO overflow" error and the angles cannot be read correctly. This is because the FIFO register that contains the angle/acceleration data is updated very quickly but your code is reading these values slowly. To solve this problem, the MPU data update rate should be made slower and some changes should be made in the MPU6050 library. Locate the "MPU6050_6Axis_MotionApps20.h" file in the "MPU6050" library, and change line 261 from
02, 0x16, 0x02, 0x00, 0x00 // D_0_22 inv_set_fifo_rate
to
02, 0x16, 0x02, 0x00, 0x04 // D_0_22 inv_set_fifo_rate
The last byte (changed from 0x00 to 0x04) slows down data rate. Second, add these lines at line 272 of the same file:
#ifndef MPU6050_DMP_FIFO_RATE_DIVISOR
#define MPU6050_DMP_FIFO_RATE_DIVISOR 0x04
#endif
The final code is "ReceiveNRF24Trim-Stabilize.ino" below and it is also based on the code provided by rcpano.net
Testing Video
A video showing the working of the transmitter/receiver/gyro can be found on Youtube: https://youtu.be/gI3lxvVLKn4