# building a quadcopter using STM32F3 Discovery board

how do you calculate the PID values and stabilise the quadcopter using the on board sensors The gyro accelerometer and magnetometer

welcome to the Robotics stack exchange! your question is very broad, so I will try to give you an overview of what you need to do:

• First determine orientation based on information from both the gyroscope and accelerometer. The accelerometer is accurate in the long term while the gyroscope is accurate in the short term, so you will need some kind of sensor fusion algorithm to determine the"true" orientation of the quad. The most popular one is the Kalman Filter but many others are available to choose from.

• The next thing you will want to do is build a simple rate controller where you try to match the rate of rotation on a certain axis to the rate commanded by the controller

• after you have a rate controller you can build a simple stabilized controller, where instead of commanding the rate you command a certain angle. You take the desired angle and the current angle and based on those values calculate a desired rate to close that gap and then feed that into the rate controller.

• You will probably need a RC controller and receiver set, you will need to read the PWM values from the receiver in order to take command input

Here is my favorite resource on the matter it helped me when I was making my first flight controller from scratch.

Good luck!
{"ft_lang_label":"__label__en","ft_lang_prob":0.9193565,"math_prob":0.49535966,"size":1390,"snap":"2020-24-2020-29","text_gpt3_token_len":273,"char_repetition_ratio":0.13275613,"word_repetition_ratio":0.0,"special_character_ratio":0.18776979,"punctuation_ratio":0.049808428,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.95022035,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-07-03T17:04:04Z\",\"WARC-Record-ID\":\"<urn:uuid:b66293ad-6b6b-46e1-867e-c4dc8d1288d1>\",\"Content-Length\":\"141787\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:cf717039-d158-4bf8-8100-cbfa9f09a8b3>\",\"WARC-Concurrent-To\":\"<urn:uuid:5330ec33-3a0b-4455-a019-3487f9bde4ca>\",\"WARC-IP-Address\":\"151.101.193.69\",\"WARC-Target-URI\":\"https://robotics.stackexchange.com/questions/7080/building-a-quadcopter-using-stm32f3-discovery-board\",\"WARC-Payload-Digest\":\"sha1:453DQ3CFQV6ALIQE7L6CWOEOYRHFPP2L\",\"WARC-Block-Digest\":\"sha1:3BD54IG7GX4WAYRHTHYP3EKZOHRFLYXY\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-29/CC-MAIN-2020-29_segments_1593655882634.5_warc_CC-MAIN-20200703153451-20200703183451-00475.warc.gz\"}"}