Disclaimer: I haven't actually piloted a drone before but I have
(non-professional) experience in control systems, robotics, electronics, and
embedded software development.
Have there been any projects that aimed at writing either:
I haven't heard of any so far.
low level firmware for speaking to the rotors
This is trivial to do. The motors powering the rotors are always attached to a
ESC (Electronic Speed Controller) that has some form of processor in it that
controls (using a PID controller or similar) the motor; the microcontroller only
has to command them using PWM (Pulse Width Modulation). Most microcontrollers
has hardware support for PWM and writing an API to control the rotor (forwards,
backwards, speed) can be done in probably about 100 LoC.
in general enabling flight
This is a way more complicated. Now we are talking about interacting with
sensors, which you have to calibrate beforehand, and running a (PID) controller,
which you have to "tune" beforehand, all with possibly real time requirements,
so you may want to throw in a real time OS (RTOS), just to get your drone
hovering still in the air without crashing to the ground just because of an
occasional breeze.
Now we are in the order of thousands of LoC that involve not only software
development but control engineering.
high level libraries that allow for writing autonomous flight programs
What sort of autonomy are we talking about here? "Follow this predetermined
path", "Follow this predetermined path minding your surrounding so that you
don't actually crash with an obstacle", or "Follow this person around".
Hardware-wise, the first two seem doable with just one microcontroller if they
don't involve a camera. Anything that involves a camera will probably require an
additional processor running at hundreds of MHz. Algorithm-wise, the first
seems like a solved problem; for the other two you probably want to look into
some recent research on path planning and image processing.
Also, the goal is to get a discussion started around writing or contributing
to these areas.
I'd suggest the same thing as @mwm: Focus on a single existing platform and get
something working (a monolithic application is fine) before thinking about
supporting other boards, micros, sensors, etc or even building high level
libraries.
This is how I would go around developing a MVP.
Disclaimer: I haven't wrote a flight controller before.
-
Pick a platform, a flight controller. I'm talking about the elecronics. Pick
something with an ARM Cortex-M processor in it because that's what Rust
supports right now. I'd also recommend a processor with hardware support for
floating point math as lots of math are involved in the control system. The
actual rotors, motors and ESCs seem less important as they all are controlled
in the same way. Having the same microcontroller and sensors is more
important.
-
Write code to manipulate the registers. The so called register maps. This
involves a lot code but thankfully it can be automatically generated from SVD
files using a tool like svd2rust or svd-mmap.
-
Write drivers for the sensors and the ESC. This is going to involve dealing
with peripherals like I2C, SPI and PWM but you only have to read the reference
manuals to do this part. At this point a blocking API is fine.
-
Then look into the calibration of the sensors and the ESC. Calibrating the ESC
is easy as there is a predetermined protocol for it. Calibrating the sensors
is more involved as it requires quite a bit of math (matrices).
-
Develop digital filters for your sensors. This will likely require "real time"
plotting of the readings to get a better feel of the amount of noise in them.
-
Look into and implement an algorithm to compute the 3D orientation of the
board / quadcopter using the sensors as inputs. Something like this.
-
Develop a wireless communication channel between the quad and your laptop.
Serial over Bluetooth (RFCOMM) should be enough. Something minimal just to
send commands to the microcontroller.
-
Look into open loop control to get familiar with the flight mechanics: All the
rotors spinning at the same speed should move the quadcopter up, down or keep
it still. Figure out what those speeds are. You'll have to input the speeds
manually using the wireless comm developed in the previous step. This also can
be used to confirm the calibration of the ESC was successful: sending the same
PWM signal to the four ESC should make all the rotors spin at the same speed.
You'll probably need a tachometer for all this.
-
Look into closed loop control just to keep the quadcopter hovering still in
the air in presence of small perturbations. At this point you want to turn all
your sensor reading APIs from blocking to async.
-
Look into stable vertical flight: take off and landing. Probably using a
barometer to get feedback about the height.
-
Look into small sideways movements without crashing and losing height. This
part scares me the most and will probably be the trickiest to get right.
-
Build a slightly higher level wireless controller. Just using the terminal
seems fine with commands like left
to e.g. move a bit in the minus X axis.
At that point the project would be mature enough to be called a MVP, IMO, though
it's nowhere near done.
IMO the hardest part is the control engineering: figuring out the right
algorithms for stable flight, the digital filters, the calibration of the
sensors and the tuning of the PID controller. The firmware development part,
writing drivers/API for the sensors, seems trivial compared to the rest of the
work that needs to be done.