An Open Source UAV Autopilot that is Arduino Compatible with 32 Bit Multitasking
I’ve been experimenting with my own autopilots now for several years. My goal has long been to build an Open Source UAV autopilot. My first autopilot was a simple GPS with rudder navigation and an infra red sensor based stabilizer system. I soon realized it had a problem with cold and cloudy weather conditions and was ready to move on.
My next IMU based autopilot I called the UAX, you can see the code for it here the UAX. The UAX used a Netburner MOD5213. I was able to get a linear two axis Kalman filter working on it, but it suffered from an occasional glitch – plus the fact the Netburner IDE is proprietary led me to abandon it development as a development platform.
Around January of 2011 I became aware of the LeaflLabs Maple System . The project seemed a little immature at first, but by summer they had quit a nice system with an RTOS, hardware SPI I2C,and a good SD driver . I acquired a Maple R5 from sparkfun and soon was getting readings from a IMU-3000. Then I soon got the DCM from the DiyDrones code working on it .
From my previous experience, I knew there were a few things that would be necessary for a truly reliable, robust, highly responsive autopilot:
- An external mux/fail safe – Anytime you rely upon your CPU for RC pass through you are asking for trouble.
- A Watchdog timer – The Mars rovers have it ,why not your $900+ investment.
- RTOS -This gives the ability to have real time responsiveness. Multiple concurrent prioritized processes and Interrupts.
I have the DCM code , reading a MPU-6050 via I2C(400khz) and outputing the DCM at 200hz . I have a concurrent loop outputting the solution to USB every 40 loops of the DCM giving 5 Hz reading to the computer. I used a queue to pass the information between the two tasks. FreeRTOS is what the Maple uses and they have a ton of info on FreeRTOS and RTOS in general on their site FreeRTOS.
I have an ISR attached to the int pin on the MPU. The mpu can output a precisely timed pulse on the int pin which triggers every time the MPUis done sampling. This integer triggers an ISR on the CPU that passes a semiphore to a waiting task that reads the I2C bus and calculates the DCM. It then puts the solution into a FIFO buffer . The second task waits for the FIFO to have data, then outputs to serial. The real trick here is the serial output task has a lower priority then the DCM task. This means that if the serial output task does not complete before a new sensor reading it will yield to the higher priority DCM task and allow the sensor to be read .
I have many future plans and I will be ingratiating great circle navigation with cross track error and PID loops for the servos. I will be looking at using some magnetic encoders for the gimbal control. I have built the maple pilot so the hobby UAV community can have a high performance highly responsive opensource autopilot.
Get the latest code at the google code project page for maplepilot
This is what I have for a basic outline for the sensors etc.
- STM 32F103RET6 CPU
- 8 channel pwm out for servos
- Mpu 6050 imu
- hmc 5883l magnotometer
- micro sd card
- bmp 085 absolute pressure
- ublox lea-5h gps
- 8 channel servo mux/failsafe
Maplepilot is an open source project your involvement is essential .
I’m building exactly the same using chibios without maple bootloader. I’m using a maple mini and a freeimu(MPU6050, MS5611 and HMC5883L).
My code is available on https://github.com/trunet/trunetcopter.
But it’s far from being complete.
Wagner,
I had a chance to look over your code . pretty interesting .looks like your running a traditional kalman filter using quats . I like the general structure of your program seems very similar to mine , having the MPU read loop blocked by a semaphore (chibi uses “event flags”), which is set by an ISR attached to the INT output on the MPU . Now that is how its done . The truth is besides my buddy Zak who does the web development for me this is a one man show . I am interested in finding an individual who is interested is a career making autopilots . Probably something more then an employee . The goal of the maplepilot is an autopilot geared toward the student or hobbyist . I think sticking to a processing / wiring environment for the IDE is crucial to making it easy for the neophyte .