What is demonstrated working so far -
- ESP32 module with personally developed C program - esp-idf (only)
- SPI interface to MPU9250 reading gyro data at 8K samples/sec, accelerometer data at 1K samples/sec (dma)
- Low pass filter on accelerometer data and xyz to spherical trig conversion to calculate accelerometer based pitch and roll at 100Hertz (accelerometer data too noisy beyond this point)
- Complementary filter fusion - preserving high speed component of gyroscope data and and low speed component of accelerometer data
- PID control inner control loop integrals at 8K update rate, PID updates at 100Hz
- Servo outputs from inner control loop PIDs to four ESCs updated at 480Hz
- MPU9250 and ESC calibration functions
- Have had receiver working in both TCP/IP and ESPNOW modes
- In TCP/IP mode have hosted remote webpage with a couple virtual joysticks, unfortunately limited to ~5 packets/sec, maybe useful for some applications
- In ESPNOW mode can transact more than 100 packets per second with much higher download bandwidth for blackbox data, limited to about 200 feet so far.
- ESP8266 D1-mini module
- I2C bus reading ADS1015 analog to digital converter hooked up to two joysticks
- ESPNOW link to flight controller/receiver hard coded with MAC addresses, comes on quickly, can reestablish and no startup order
On my two axis testbed with two motors spun up to average throttle of 1450 (close to what it would hover at with 4 motors) seem to be enjoying a 1 sigma attitude control of better than 0.1 degrees after a half hour of playing with tuning. It is impressive how hard you have to push these things to get them to move. Also included a graph of what the recovery looks like in time with the contributions from the proportional, integral and derivative components of the PID control loop. In attached files have included a video of recovery from a pretty good push on my two axis test setup.
In gallery have included a closeup picture of flight controller board. The two other modules on the breadboard are the MPU9250 with SPI interface wiring back to the ESP. The ESCs required a 5 volt servo input and are being routed through a 4 port 3 to 5 volt level converter, with wires heading off to the four ESCs. The usb plug heads back to my desktop monitor where I can modify parameters (PID gains, throttle speed, etc) and monitor state.
So far I have learned a bit from this project, it's my first exposure to drones, but I do have other relevant experience and think this procedure an informative introduction to the subject. I feel pretty good about being able to make a flight controller at least as good as the CC3D that came with my drone kit. I have gathered info from the web but the code is 100% mine except for the device drivers contained in the esp-idf framework.
- Think up tethering scheme for 'safety conscious' indoor hover testing
- Free up other drone axis for actual flight (no more metal rod or testbed)
- Modify testing software for other 2 motors, yaw and altitude PID loops
- Integrate 4 inner PID loops (currently just using 1) into ESC servo commands
UPDATE -- Received my much nicer joysticks Saturday morning and mounted them in cigar box. I was expecting the process of getting these working to go smoother than it ended up being. Turns out the ESP8266 briefly uses more than an amp of current when transmitting wifi packets. This resulted in bad adc readings (~5% worst case) during wifi transmits. At first I tried to clean up the power supply going to a battery and further power filtering for the adc and joystick and managed to cut the errors only by less than half - I feel I could have done better with some good 1mF low esr caps which I don't have. Decided to try synchronize adc data acquisition to when wifi transmit is quiet and get rid of the wiring complexity of the filtering effort. The espnow example that I used to start my code with uses an event...Read more »