Skip to content

Ralung/Control-and-fly-a-mini-drone-with-computer-keyboard

Repository files navigation

Control-and-fly-a-mini-drone-with-computer-keyboard

In this project, I used a laptop and a 4-in-1 board to fly a mini drone by keyboard keys.
The advantages of this way are that it is not needed to modify the drone and original transmitter and it can also be copied by other drones quickly.
I am really appreciate to goebish, multiprotocol project and pascallanger!

flowDiagram

Contents:

  1. Flash the firmware of 4-in-1 module
  2. Set up a Python code
    a. Binding process
    b. Initial value adjustment and Remote controlling commands

In this project, I used a E016H model from Eachine drone company and it used the protocol, "PROTO_E916HV2"

1. Flash the firmware of 4-in-1 module

Step 1. Download the Multiprotocol firmware flashing file

Please go to the following web address to download the firmware flashing file, and ensure the version is v1.3.1.92 or later. https://github.com/pascallanger/DIY-Multiprotocol-TX-Module/releases/tag/v1.3.1.92

Step 2. Modifications of several files

There are four different files needed to be modified in this step, and these files can be found in the firmware flashing file downloaded in previous step.

  1. Pins.h Please replace USART2_BASE with USART1_BASE in line 357 and line 358

  2. Multiprotocol.ino
    a. Add “#define arm” in line 27.
    2-a
    b. Add “void __irq_usart1(void);” in line 66.
    2-b
    c. Replace “usart2_begin” with “usart1_begin” in line 2110 and line 2117, replace “USART2_BASE” with “USART1_BASE” in line 2111 and line 2118, and comment out the line 2122.
    2-c
    d. Add the codes from line 2154 to line 2161 in the following picture.
    2-d
    e. Replace “USART2_BASE” with “USART1_BASE” in line 2212.
    2-e
    f. Replace “__irq_usart2” with “__irq_usart1” in line 2448.
    2-f
    g. Replace “USART2_BASE” with “USART1_BASE” in line 2456, and there are to places needed to be modified in this line.
    2-g

  3. Multiprotocol.h
    Please change the protocol numbers of “PROTO_Q303” and “PROTO_E016HV2”, the original protocol number of former is 31 and it is in line 60;the original protocol number of the latter is 80 and it is in line 108.
    After modification, “PROTO_Q303” should have 80 as its new number and “PROTO_E016HV2” should have 31 as its new number.

  4. Usart_f1.c
    In this file, please comment out the codes in line 203 to line 205. Please note that this file should be under the folder of Arduino IDE program files whose file path is depend on different computers.

Step 3. Flash firmware with Arduino IDE

  1. Install the Multi 4-in1 STM32 Board in the Arduino IDE. In this paper, the version number is 1.2.1. [13]
  2. Get in the folder downloaded in step 1 and open “multiprotocol.ino” file in Arduino IDE. Choose the developing board as “4-in-1 STM32”, the Debug option as “no” and the USB support as “Disabled”. The COM port depends on user computer situation.
  3. Let Arduino IDE to compile the programs and upload to the 4-in-1 moduel.

2. Set up a Python code

Step 1. Binding process

Please use the file, "1drone_KBcontrol_Binding.py" to test whether the binding process is successful.
Note:
a. The file "stm32flash.exe" should be put with the Python file.
b. Check the number of protocol is correct.
c. Check the number of COM port is correct.
d. Set all the "globals" as 1500 if it's the first try.
e. The LED would flash fast if the 4-in-1 board starts its binding mode.
f. In this step, the E016H drone would only start its propellers and get into ready mode for 20 seconds.
g. Once the propellers are rotating, this step is over.

Step 2. Initial value adjustment and Remote controlling commands

Initial values represent the initial balance when the drone takse off and they would also effect the balance when the drone is hovering.
Remote controlling commands are used to control the one-term distance once the keys are pressed.
These two thing should be set up at the same time and need some time to adjust them.
If the initial values do not be set up properly, the drone would be out of control.
Many factors would effect the initial balance of a drone such as battery power, the balance of fuselage, the weights of different batteries, initial values, etc.
Although the initial values can make a big effection to the balance, but same values cannot ensure the drone be always very stable.
Therefore, initail values should be modify depends on different situations.

Remote controlling commands need to be set up before the suitable range of initail values be checked because these commands can help the drone to avoid the crash.
Remote controlling commands would look like two loops which have same number of laps.
One loop is to increase the values step by step and the other loop is to decrease the values step by step and make sure it return to the initial values.
The values mean the number in different channels such as A, E, T and R.
When the values return to initail values, the drone can be hovering and wait for next command.

If 4-in-1 board doesn't send a new singal to the drone more than 70ms, the connection would be disconnected. As the result, the hovering function is needed.

In "1drone_KBcontrol_Ini-value&Ctrl-command.py", the drone can be controlled by keys like the following diagram.
KBcontrol

Note:
a. If 4-in-1 board doesn't send a new singal to the drone more than 70ms, the connection would be disconnected. As the result, the hovering function is needed.
b. The amount of increasement or decreasement can not be too less or too many. Too less makes the drone non-moving and too many makes the drone moving too fast and the slow reaction of commands.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages