Last October on an impulse I ordered a F450 quadcoptor drone - complete with motors, escs, cc3d flight controller - actually under $50 from a chinese supplier. I had never really thought about or used a drone before, but figured building one from scratch would be a good way to learn. While the drone was being shipped I purchased an extra $8 cc3d to help debug initial software and a couple 3S-25C batteries with charger from amazon - $30.
First step was to build a transmitter, for this used two analog joysticks, a four channel adc module and an esp8266 D1-mini module to send the throttle, yaw, pitch and roll commands. At the receiver end an esp32 module was used to interface to the cc3d flight controller using the sbus input channel. Initially, communication between the transmitter and receiver was over a wifi connection with tcp protocol - realized quickly that was limited to about 3 packets per second, so switched over to an espnow communication protocol. With the ESPNOW comms could get to 100 packets/second - but was still limited to about 100 feet (but without the need for local wifi lan router).
After the F450 kit arrived we built it up and did some test flights. The CC3D flight controller programmed up pretty easily with Cleanflight and we did a few spins around the front yard.
From the beginning I was planning on implementing the flight controller within the esp32 - so I quickly ditched the cc3d and started writing my own flight control software. I like the esp-idf tools and a simple design environment - vim and git in linux. The software modules that I developed (pretty much from scratch) include a dma’ed spi interface to the mpu6500/mpu9250 (bought a few of the mpu9250 but they turned out being mpu6500 - without magnetometer), i2c programs for the bmp280 and qms5883l, esp analog input to measure battery voltage and the esp pwm interface for the ESC outputs for the hardware interfaces. An IMU task was written to fuse the xy gyroscope and acceleromter measurements (1KHz sample rate) through a complimentary filter into high bandwidth low-latency drone attitude tilt error outputs, these are feed into PID control loops to generate motor speed commands for each of the four motors updated at 475Hz. Throttle and yaw PID loops are fed with error values derived from bmp280 and qmc5883l readings gathered at 10Hz. A program to fine tune PID and filter variables has been implemented via the transmitter esp console interface, blackbox data stored in transmitter. To improve transmitter/receiver range nrf24+lna+antenna modules have been added (still going to use esps even though wifi not being used instead of starting over).
To put this all together PCBs have been ordered for the transmitter and the integrated receiver/flight controller. The PCBs have been taking a very long time to show up (chinese new year '20), so to fill some time I breadboarded my major IMU components and added an oled display to make a portable handheld IMU. The unit reports measured tilt (pitch and roll), height and heading. Data reporting is done to the oled display on the portable, the unit also hosts a data reporting webpage with graph showing data over time. Prior to finally integrating all these components this little unit will help me understand the drone control limitations of my attitude measurements and how to apply these to control the drone and to help me think out takeoff/landing/failsafes.