I nipped out this morning to see if I could get a good photo of Zoe in flight:

Zoe flight

Zoe flight

Turned out it was easy – she flew several 10s flights, during which she only drifted 10cm – by far the best set of flights yet.

Zoe the Zero – Appendix – What next?

If you’ve reached this stage, you’ve caught up with me, and I can’t help you any more with details, but here’s a list of things I’d like to try.

  • video your flights – there’s support for the PiCam built in to the code (use -v option), but I’ve not run it for a long time now – this requires an A+ rather than zero to get access to the CSI connector – so Phoebe or Chloe rather than Zoe.
  • tweak the flight plan to add horizontal motion steps between a couple of hovers – I’ve done a single test on this, and it worked reasonably with no code changes.
  • add a simple remote control by using a call with 0 timeout on stdin inside the FlightPlan() code – use the arrow keys to direct the flight laterally during a long ‘hover’ phase.
  • The DroTek board has a barometer and compass too, so you could add height and orientation control, and to some extent a further input to calculating angles based upon the change in location of the earth’s north pole compared to the quadcopter frame – similar to the integrated gyro data but with an immovable reference point and no integration drift.
  • A true remote control requires some more significant work to the code:
    • remove the X and Y velocity PIDs
    • replace them with angle PIDs
    • the angles are derived from GetAbsoluteAngles() and integrating the gyro – they are both quadcopter frame values.
    • you probably want to discard the GPIO edge_detect_wait() code, and instead, use to listen on both the data ready interrupt rising edge, and the incoming RC messages – looks at the GPIO/source/event_gpio.c for details
  • If you’re sticking with autonomous flight, then a USB GPS is a good next step once you have the compass working to allow the flight plan to be specified as absolute directions at fixed speeds with the GPS providing long term low resolution backup to the less accurate but high resolution compass settings.
  • With a GPS in place, you can do something awesome like the Hexo+, which controls the quad through a smart phone, using the differences between the phone and quad GPSs, combined with predefined set of flight plans to make the quad follow and video you autonomously while you do cools things like skiing or mountain biking!

There’s one big problem with all of these however: a single CPU Raspberry Pi running interpreted CPython is near its performance limit already.  This means adding more sensors risks missing readings from the IMU.  The autonomy relies critically on catching every sample to ensure acceleration integrates accurately to velocity.

There are two solutions to this performance problem, as long term followers will know: move over to PyPy or wait patiently for the A2; both will provide the spare CPU cycles required for further processing, but both have significant problems:

  •  The GPIO and RPIO use the CPython API to product libraries that CPython can import; PyPy doesn’t use these, instead using CFFI for provide direct access to ‘C’ function calls from Python.  I’d need to pull out the ‘C’ code from GPIO and RPIO and put that into a CFFI framework.  Trouble is, I’m fairly ignorant on how this works, and the fact the GPIO and RPIO code isn’t mine makes this more complicated.  And my confidence is not that high that it will produce the performance enhancements I’m looking for.
  • The alternative is to swap Phoebe over to (the yet to be announced) 4-core 1GHz 512MB RAM A2.  This will allow me to split motion processing and sensor reading across cores, leaving a couple spare for other sensors.  The problem here though is that the release of the PiZero at best has deferred creation of an A2, and at worst, cancelled its development altogether.

So for the mo, I’m stuck again.


Zoe the Zero – Appendix – Testing and Tuning

I did very little testing before I let Zoe loose – just two pieces:

With the LiPo not plugged in, I ran a flight; this checks that the sensors are working and  tuning data sampling rate to ensure all samples are caught.  Simply run

cd ~/Quadcopter
sudo ./ -f fp.csv

As a result you should see a 20s countdown, a 1.5 second warm-up, ascent (2s), hover (2s), and descent (2s).  Then the length of the flight is shown on screen.  The key here is that the internal timing for the steps through the flight plan is based only on the number of samples captured, and the data ready interrupt frequency; the total time printed at the end is the difference between calls time.time() before and after the flight.  It should read 7.5s with accuracy of 1% or less based upon the above flight plan.  If it is significantly more, then samples are being missed and you need to reduce the dri_frequency.  If it is significantly less, then the data ready interrupt is not working – have you installed the customized GPIO code?

With that passed, the other step is to check the PWM is working, and that the props, motors and ESCs are installed correctly:  the front left and back right props should spin anti-clockwise to match the code’s expectation.  Run

sudo python ./ --tc 1 -h 150

Each prop should spin in turn (front left, front right, back left, back right) for 10s.  Feel the down draft underneath each.  If the props are not turning the right way, swap any two wires on the ESC.  -h specified the PWM pulse size minus 1000 i.e. 150 is 1150us pulse.  This should be enough to get the props spinning but well below the takeoff speed of around 400+.

With those two tests done, she’s ready for a trial flight.  With the motors still powered up run

sudo python ./ -f fp.csv

Be ready with control-C to kill the flight, and I’d strongly recommend running this flight outside on a soft surface (grass).  It should all be fine, but it’s very demoralising to trash your quad in a violent crash on the first flight!

Zoe the Zero – Appendix – Construction details

The frame and the PiZero are a perfect match for each other.  The fit is tight but there is just clearance to fit the PiZero and the PCB between the top and bottom plates, but because it’s tight, there are a couple of things to be aware of.

First, the velcro attaching the LiPo must be 20mm wide or less.  Before sticking the PiZero to the bottom plate, attach your LiPo to the underside with the velcro.  That then defines the length of double sided sticky foam tape between the velcro straps that the RPi is stuck to on the topside of the bottom plate.  Done like this, the two ends of the PiZero overlap the velcro, but the 40 pin connector does not.

Because the PiZero ends overlap the LiPo velcro, the underside of the PiZero needs to be flat at the ends; the mounting holes need to be countersunk from the underside and M2.5 countersunk bolts are used.

I’ve used some very thin non-branded velcro and that means I’ve used only 1mm foam tape to stick the PiZero down.  I have no idea where I got the thin hook-and-loop tape from, it was acquired sometime in the last 3 years of the project. If you use thicker velcro, you’ll need thicker double-sided foam tape and that might breach the height limit between the top and bottom plates – yes it really is that tight.  But there is a solution.

The 90° pins the ESC cables attach to are high profile; this was necessary for Phoebe and Chloe as the PCBs had wires on them; the pins needed to be raised over the wires.  Zoe’s PCB has no wires, so standard low-profile pins can be used.  This will buy you the couple of millimetres you need to use the thicker double sized tape to stick the PiZero down.

One final comment: the velcro tying the 5V battery bank to the top plate also needs to be less than 20cm wide.  That way, it passes over the MPU-9250 but between the ESC cable pins; any wider and it and the ESC cable pins will overlap and you won’t be able to plug the ESC wires in.

Zoe the Zero – 7 – BOM

Zoe went to the kids’ playroom for a maiden flight.  I did no tuning, she just inherited Phoebe’s PID tuning values.  The result was one perfect flight, one flight with horizontal drift, and one flight with a crash and a clipped prop (an unexpected reaction by the ESCs to ctrl-C mid-flight, I think) – replacement props are already on their way (£5 a pair).  Clearly there’s some tuning to do.

But at the same time, she is working amazingly well for a set of untuned maiden flights, so here’s the Bill Of Materials which comes to around £270 plus the unpriced bits and bobs that all cost less than a pound each.


Zoe the Zero – 6.2 – Construction

Just minutes after posting my previous blog entry, the postman arrived with the PCBs.  A couple of hours later, Zoe the Zero was built.

Zoe the Zero

Zoe the Zero

And within a few minutes of that, she’d passed her initial pre-flight tests: an unpowered flight to check the sensors were working as expected, and a powered test to check the PWM, ESCs and propeller rotation.

All that’s left now is to tighten up all the nuts and bolts, and see how she flies!

I’ve put the Eagle board design and gerber files of the PCB on GitHub.

Zoe the Zero – 6.1 – Construction

Space is critical here.  Zoe sits in the middle, the LiPo hangs underneath, and the 5V battery bank is on top.  Both batteries have a neoprene non-slip mat between then and the frame, and double sided velcro strips to tie them tightly to the frame.  It’s the placement of the battery bank on top which has forced me to remove the canopy pillar; this was the only suitable place for it.

Here’s Zoe with her PiZero installed and the LiPo slung underneath:

Zoe + Zero

Zoe + Zero


Next step is to add the filled PCB on top.  Sadly, Christmas has ground the UK postal service to a halt.  Hopefully it will arrive today, fingers crossed.

Zoe the Zero – 5.3 – T-DRONES SMART.X A frame



Not a lovely as Anakin, but the frame is designed to match the T-MOTOR Air Gear 200 props, motors and ESCs and the frame is strong and simple to build.

P.S. It’s the same banana, just showing its age.

P.P.S.  I do have one gripe: the cover is very light and flimsy, not a problem, but why have they used such a sturdy mounting pillar / split pin smack bang in the middle of the top plate to fix the cover in place?  Just some velcro would do.  I think I’ll remove the pillar and live without the cover for now.

Zoe the Zero – status update

Just a quick update:

  1. I’ve found a source for the T-DRONES SMART.X A frame, so that’s now on its way.  It’s designed to work with the T-MOTOR Air Gear 200 ESC, motor, props set, so I’m not expecting any hardware incompatibility problems like Anakin’s.
  2. I tried the T-MOTOR Air Gear 200 kits with Zoe and the A+ Beret PCB, and they work well.  That’s another hurdle crossed.

Together this means that with the arrival of the new PCB and frame, Zoe should be flying by the end of next week.