giulionyakunga
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    2
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # How to Build a Flight Controller using a Microcontroller ![Picture of ATmega328P](https://raw.githubusercontent.com/giulionyakunga/Quad-Flight-Controller/main/ATmega328P.jpg) *By Julio Nyakunga (Open Skies Fellow)* In this post I will demonstrate how to build a flight controller using an Atmega328p Microcontroller. ### Why am I doing this Before we begin this lets see why we need to learn how to build a flight controller. This might sound weird to some people but for enthusiasts in technology it is good news. Below are the reasons for building a flight controller * It helps you to have a low level understanding on how drones work. * It can help you understand how to perform drone maintenance. * Making your own flight controller gives you full access to its feature so you can modify its setting whenever you want. * It is a good use of available electronics devices that are cheaper and easy to get. ### Steps on how to make a flight controller 1. Circuit designing 2. Circuit printing and assembling 3. Coding and circuit programming 4. Flight controller PID tuning and testing I will go through each step for you to understand what it means and what needs to be done. ### 1. Circuit Designing Before on start designing the circuit must figure out what are the circuit rewquirements: what functions it is going to perform 1. How many inputs and what type of inputs it will receive? 2. How many outputs and what type of outputs it will produce? and 3. What kind of processing will be needed? Having the answers for these questions will help one choose the right electronic devices for the circuit, for example one should know the number of inputs and outputs needed so the he/she can select a microcontroller of a given number of input and putput digital and analog pins. Below is the list of input and output signals in my flight controller: | Signal name | Signal Type | Direction | | -------- | -------- | -------- | | Throttle | PPM analog | input | | Rudder | PPM analog | input | | Elevator | PPM analog | input | | Aileron | PPM analog | input | | ESC 1 | PWM analog | output | | ESC 2 | PWM analog | output | | ESC 3 | PWM analog | output | | ESC 4 | PWM analog | output | | I2C Clock | digital | output | | I2C Data | digital | input/output | From the table we can see that 8 digital pins are needed for PPM PWM signal generations and 2 analog piins are needed for I2C communications. At this point, I know which microcontroller and electronic devices will be used to make the flight controller. Below is the list of electronic devices I used to make my flight controller circuit. 1. Atmega328P Microcontroller 3. 16Mhz Crystal Oscillator 4. 2 22p Ceramic Capacitor 5. 1 Push Button Switch 6. 1 10K Resistor 7. 3 200/220 Resistor 8. 3 LED Diode 9. 1x8 Female Pin header 10. 2x4 Female Pin header 11. 1x4 Female Pin header 12. Microcontroller chip Holder 13. MPU-9265 (Gyroscope, Accelerometer and Magnetometer) ##### The Atmega328P Microcontroller ATmega328P Microcontroller is a general purpose microcontroller with 14 digital pins and 6 analogy pins. This is a programmable integrated circuit (IC), which one can use to perform and automate different tasks. I used this microcontroller to make the flight controller circuit. The Microcontroller circuit will be connected to some peripheral electronic components with which it can effectively control the drone. The microcontroller will receive control signals from RF Transmitter through RF Receiver, and decode the signals, will also read and process gyroscope and accelerometer data for drone balancing. Finally the Microcontroller will control the speed of motors using electronic speed controllers (ESC) using PWM (Pulse Width Modulation) signals. ##### What is IMU? IMU stands for Inertial Measurement Unit, it is a collection of a number of sensors (measurement tools) and their embedded software that process sensor raw data. IMU is installed in a device (drone) and is used to capture device's movements. IMUs contain sensors such as accelerometer, gyroscope, and magnetometer. ##### How does an IMU work? IMU can measure a variety of factors including speed, directions, acceleration, angular rate, and magnetic field surrounding the device (drone). Each sensor/toot in an IMU is used to measure different factors about the device (drone): ##### The Gyroscope The gyroscope is part of IMU used to measure angular acceleration and velocity. Gyroscope can measure angular acceleration on the X, Y and Z axis. Using its raw output data angular acceleration and angular displacement can be calculated. Using the gyroscope, the roll, pitch and yaw angle of the drone can be measured. The gyroscope is very accurate but has its shortcomings, one being the gyro drifting due to its high sensitivity to mechanical vibrations. Gyro drifting is the tendency of the gyro angle to drift from it's true value when there are mechanical vibrations in the system. ![Flight Controller Circuit](https://raw.githubusercontent.com/giulionyakunga/Quad-Flight-Controller/main/gyro.png) ##### The Accelerometer Accelerometer is part of IMU used to measure linear acceleration and velocity. Accelerometer can measure linear acceleration along X, Y and Z directions. Using its raw output data, linear acceleration and so orientation of the drone can be determined. The accelerometer is less accurate for short time angular measurement but very reliable for long time measurement and not highly affected by mechanical vibrations (noises) as gyroscope. But the shortcoming of an accelerometer is you can not use it to measure yaw angle. ![Flight Controller Circuit](https://raw.githubusercontent.com/giulionyakunga/Quad-Flight-Controller/main/accelerometer.png) ##### The Magnetometer The magnetometer is part of IMU used to measure magnetic field surrounding a device and so can be used to establish directional heading of a the device (drone). I used Magnetometer in my flight controller circuit to fix the head of the drone in one direction. Each of these sensors have their strengths and weaknesses, for example gyroscope it very accurate for short time angular measurement but very vulnerable to mechanical shock and high frequency vibrations (leading to gyro drifting), while accelerometer is not accurate for short time angular measurement but its advantage is it is not vulnerable to mechanical shock and high frequency vibrations (noises), also accelerometer can not be used to measure yaw angle. In short I can say output from an individual sensor in the IMU system is by itself not reliable and not useful unless other sensors' outputs are used. Due to these advantages and disadvantages of IMU sensors, the IMU system rationally combines outputs from different sensors (mentined above) to produce an accurate and reliable output. This technique is called sensor fusion. So I did a fusion of gyroscope angle and accelerometer angle to get an accurate roll and pitch angle. NOTE > In my flight controller circuit the I used MPU-9265 to implement the IMU hardware system. MPU-9265 is a multi-chip module (MCM) consisting of two dies integrated into a single Quad Flat No-lead (QFN) package. One die houses the 3-Axis gyroscope and the 3-Axis accelerometer. The other die houses the AK8963 3-Axis magnetometer. So I all the gyroscope, accelerometer and magnetometer in one chip. ##### Schematic Circuit Diagram I used Proteus Software to make this schematic circuit diagram. You can use any software of your choice to make your schematic circuit diagram. ![Flight Controller Schematic Circuit Diagram](https://raw.githubusercontent.com/giulionyakunga/Quad-Flight-Controller/main/Flight%20Controller%20Schematic%20Circuit%20Diagram.png) NOTE > Not all electronic devices need to be included in your schematic circuit diagram, some need to just connect to the circuit using jumper wires and pin headers, so only pin headers are included in the diagram. ##### PCB Designing Using Proteus Software I made the PCB design of the circuit. Below is the picture of my PCB design ![Flight Controller PCB Design](https://raw.githubusercontent.com/giulionyakunga/Quad-Flight-Controller/main/Flight%20Controller%20PCB%20Design.jpg) ### 2. Circuit Printing and Assembling After finishing my design I had to order a printing service from <a href="https://bafredo.com/">Bafredo Electronics</a> in Dar es Salaam, where I printed and assembled my circuit board. PCB assembling is all about soldering work with respect to the design diagram made. #### PCB, before assembling ![Flight Controller Circuit](https://raw.githubusercontent.com/giulionyakunga/Quad-Flight-Controller/main/Drone%20Circuit%20(edited).jpeg) ![Flight Controller Circuit](https://raw.githubusercontent.com/giulionyakunga/Quad-Flight-Controller/main/Drone%20Circuit%202%20(edited).jpeg) #### PCB, after assembling ![Flight Controller Circuit](https://raw.githubusercontent.com/giulionyakunga/Quad-Flight-Controller/main/Drone%20Circuit%204%20(edited).jpeg) ![Flight Controller Circuit](https://raw.githubusercontent.com/giulionyakunga/Quad-Flight-Controller/main/Drone%20Circuit%208%20(edited).jpeg) #### The Flight Controller Circuit (mounted on the DJI F450 Frame) ![Flight Controller Circuit](https://raw.githubusercontent.com/giulionyakunga/Quad-Flight-Controller/main/the%20flight%20controller_1.jpg) ### 3. Coding and Circuit Programming After I was done with hardware work I had to sit for programming. I wrote the program (sketch) for the flight controller using Arduino Software (IDE) using a C and C++ based language. I used Arduino IDE to program the Circuit. ```Arduino Code``` for the circuit is in the folder named Quadcopter_Flight_Controller in my Github Repository, [View Code](https://github.com/giulionyakunga/Quad-Flight-Controller/blob/main/Quadcopter_Flight_Controller/Quadcopter_Flight_Controller.ino) ### 4. Flight Controller PID Tuning and Testing Before testing the flight controller I had to tune PID values for the drone. PID stands for Proportional Derivative and Integral, in drone control system we normally use a PID controller which is a piece of embedded systems code that controls drone responsiveness to change in its angular orientations. So PID tuning is the process of finding constant values for this piece of code. The constant values are required for both roll, pitch and yaw angle control and each of these angle controls need an individual value for its proportional, derivative and integral terms. PID tuning is a trial-and-error process but it is funny once you understand what is PID Controller, what does each term in the controller mean, what is the effect of change each term in the controller and once you understand what your doing. Here are some links to read more about PID Controllers <a href="https://www.technik-consulting.eu/en/optimizing/drone_PID-optimizing.html">Link_1</a>, <a href="https://visaya.solutions/de/article/pid-controller-small-quad-copter-drones">Link_2</a> and <a href="https://oscarliang.com/quadcopter-pid-explained-tuning/">Link_3</a> After hard work of PID tuning I went on testing my flight controller {%youtube afa5Onz6GLc %} Click <a href="https://youtu.be/afa5Onz6GLc">here</a> to view my YouTube video when I was testing the flight controller. #### The Drone ![The Drone](https://raw.githubusercontent.com/giulionyakunga/Quad-Flight-Controller/main/the%20drone.jpg) ### Challenges Throughout the implementation of this project I have faced lots of challenges. The major challenge is instability of the drone. ### Conclusion The instability of the drone is mainly caused by existance of mechanical vibrations and poor tuned PID controller. So the instability of the drone can be improved by improving my IMU code (IMU software implementation), improving drone vibration damping system and well tuning the PDI constants. Improved IMU code will help to come out with a system that can filter out mechanical vibrations produced by spinning motors and propellers. Also PID tuning will also help providing better results. **Thank You for Reading ** <iframe src="https://docs.google.com/forms/d/e/1FAIpQLSf1_AhFcTi6SYMriSi_kF4F_8MxMUFwIOkK8R9t2RS27lpSdg/viewform?embedded=true" width="640" height="408" frameborder="0" marginheight="0" marginwidth="0">Loading…</iframe> --- ### Open Skies Fellows This project was fully supported by Open Skies Fellows (OSF). Open Skies Fellows is a fellowship program led by OpenMap Development Tanzania, Uhurulabs and the Humanitarian OpenStreetMap Team, with aim to support youth and give them a chance and responsibility to gain social-technological skills to leverage their potential to solve community challenges using frontier technologies. <p align="center"> <img width="460" height="300" src="https://i.imgur.com/Uea2Uas.png"> <p align="center"> Open Skies Fellow "We Design, We Build and We Fly"</p> </p> --- ### About Me ![The Drone](https://raw.githubusercontent.com/giulionyakunga/Quad-Flight-Controller/main/Julio%20Hackmd%20Profile.jpg) Name: Julio Nyakunga Graduate Engineer, Telecommunications Engineering College of Information and Communication Technologies University of Dar es Salaam, 2019 Email: giulionyakunga@gmail.com Mobile Phone: +255672120941, +255766032160 Physical address: Kijitonyama, Dar es Salaa, Tanzania ---

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully