Major quadcopter crash, dodgy propeller

2013-05-04 12.07.49

I had a major quadcopter crash a few weeks ago – and it wasn’t due to my dodgy flying skills. One of my propellers broke in mid-air; one blade snapped off from a prop at the hub. The prop was one of two new bright orange coloured ones I’d bought to help keep track of the direction of the aircraft, which worked very well for me until it crashed. Looking more closely at these new orange props I now notice that they are much thinner where they attach to the hub. My other props thicken out as they approach the hub making them much stronger. The orange ones are much weaker – bending them quickly results in white crease lines at the hub, which doesn’t happen with my black ones. Lesson learned, don’t buy cheap props (actually, they weren’t any cheaper, so the lesson is to understand how to recognise crap props).

At the time the prop snapped, I was about 20 metres up in the air, traveling horizontally at quite some speed. When it broke, which made a “ping” sound, I panicked and dropped the throttle and then realised that was wrong and throttled back up to try and cushion the landing. I’m not really sure to what extent that helped, but it hit the grassy ground hard. I was flying it in a field near my house and was prevented from immediately retrieving it by a group of curious horses that went to investigate this UFO crash landing site. Luckily they decided against trampling or eating it and eventually lost interest.

It was still powered up when I got to it, though unarmed. Annoyingly I’d decided against flying with the camera this time so didn’t have any dramatic footage of the accident.

2013-05-04 12.09.18

The battery looks too badly damaged to use. It’s not quite punctured, but it’s bashed up and misshapen. I may try recharging it out of curiosity, but I expect it to set on fire, explode or quantum leap or something – who knows with these lipo things. Quantum lipo. A friend has loaned me two new batteries, which are higher capacity (3900mAh) but weigh more – so we’ll see how that works out for performance and flight time.

A couple of the other props got damaged, but the motors, ESCs, and controller stuff seem all fine.

The two arms where it hit the ground were bent quite badly.

2013-05-04 12.06.50

Rebuild

It’s taken me about a month to get around to it, but I’ve finally rebuilt it. The new frame is pretty much the same design as before but with a couple of minor modifications. I mounted the arms less closely to the middle of the base, so there is more space for cables, and I mounted the motors about 1cm closer to the end of the arms. So the result is that the motors are about 2-3cm further away from the base, which I expect to change the behaviour slightly and gives me more headroom between the props and the base – they were quite close before and prevented me from mounting some bits close to the edge of the base.

2013-06-16 15.33.02Since my first build I’ve acquired a power drill mounting and I built a wooden jig to keep the two bases in place, which meant I was able to drill holes much more accurately. I also drilled lots of extra holes which I knew would be handy, so more places to run cables and pass through tie-clips. It’s much tidier now.

Lastly, in an effort to isolate vibration better, I put patches of neoprene where the arms are bolted to the base plates, and where the motors are bolted to the arms. The neoprene was an old laptop “skin” I cut up. I had to remove it from the motors as it meant they weren’t mounted perfectly square, so the craft was spinning a bit. I’m not really certain how effective this is as I don’t really have any data to back it up so it’s a bit cargo culting atm. I may experiment with this more scientifically at some point.

I bought some much sturdier carbon-fibre reinforced propellers too – I’ll write about my efforts to balance them properly later.

In summary, crashed it due to cheap propellers and I took the opportunity to rebuild the frame with some improvements. No horses were harmed.

Heroku tcp session information leakage

The Linux kernel exposes lots of interesting information via the /proc filesystem. For example, /proc/net/tcp and /proc/net/udp expose information about all tcp and udp sessions on the server.

In the usual Linux kernel style, these files are freely readable by all users on the Linux system. This becomes a bit of a problem on a multi-tenant system like Heroku. Heroku deploy many customers apps on each of their Amazon EC2 servers. So if you create an app skeleton, deploy to Heroku and shell out and you can see all the other apps tcp and udp sessions:


$ heroku run console
Running `console` attached to terminal... up, run.1971
irb(main):001:0> system("netstat | grep ESTAB | head -n 10")
tcp 0 0 22d87d80-deb7-415:33113 ip-10-40-86-97.ec:27018 ESTABLISHED
tcp 0 0 22d87d80-deb7-415:57256 ip-10-60-122:postgresql ESTABLISHED
tcp 0 0 22d87d80-deb7-415:59268 domU-12-31-3:postgresql ESTABLISHED
tcp 0 0 22d87d80-deb7-415:38536 collector6.newrelic:www ESTABLISHED
tcp 0 0 22d87d80-deb7-415:54459 ip-10-189-243-92.:27017 ESTABLISHED
tcp 0 0 22d87d80-deb7-415:50495 ip-10-151-25-11.ec:6242 ESTABLISHED
tcp 0 0 22d87d80-deb7-415:53192 ip-10-114-25:postgresql ESTABLISHED
tcp 0 0 22d87d80-deb7-415:47405 72.21.215.154:https ESTABLISHED
tcp 0 0 22d87d80-deb7-415:39011 collector6.newrelic:www ESTABLISHED
tcp 0 0 22d87d80-deb7-415:52237 ip-10-218-31-147.:42002 ESTABLISHED
=> true
irb(main):002:0>

If the netstat command (or system method) is not available, you can just read and parse the file in Ruby.

It’s an information leak, so I think it is quite low risk but still a hint that Heroku’s process separation still isn’t as strict as one might hope (I still remember David Chen’s pretty shocking discovery back in 2011)

There are a few ways to fix this kind of problem. Mandatory access control systems, like AppArmor can prevent processes reading these files. The Grsecurity security patches have lots of protections against proc based information leaking too, these files included.

Heroku’s response

I reported my findings to Heroku’s security team back in September 2012. I had some problems getting timely responses at first but after whining on Twitter (in March 2013) I got lots of attention from them (and an apology for lack of response). Complaining on Twitter is a clearly a powerful tool and to be used only wisely; and maybe sometimes when drunk.

Anyway, it seems they had been working hard on this and just failing to update me; it is quite a major change for them and a low priority bug imo. They’ve fixed it by properly virtualising networking too. It’s mentioned on their change log but it doesn’t go into too much detail. Important point is that it’s fixed.

Quadcopter training game

It turns out that whilst I have the ability to build a quadcopter (it’s actually not that hard) I don’t quite have the ability to fly the thing around without risking crashing it into nearby fleshy things, or trees.

And whilst there is a little glee involved in a crash (it gives you things to fix, yay!) it slows the learning process somewhat and the propeller smashing can be expensive.

I tried to get the flightgear simulator working so I could practice on my computer, but it’s really complicated and I had little success.

Quadcopter training game

So I wrote a game to help me practice. It’s a 2D top-down quadcopter simulator. It makes no attempt to seriously simulate real physics or even a real a quadcopter. Instead, it aims to just help you become familiar with the transposing of controls as the aircraft rotates around. It’s meant to be controlled using your real radio control, via an ArduPilot controller.

You can see it in action here:

It doesn’t really have a goal at the moment, you just fly around the screen. Once it a while it randomly perturbs the aircraft, sending it spinning off in some direction as if it clipped the ground or something and you have to rectify it. The perturbing is interesting, because I do fine flying around slowly but panic when I clip something.

I was very bad when I first started playing, but I’ve been getting better and it’s definitely translated to better real-world flying.

I wrote it in Ruby, using the Gosu game library (which has a few native dependencies). I’ve only tested it on Linux (Ubuntu). The code is on github. Works for me.

Several test flights later

Quadcopter
I’ve been doing a few test flights of my Arducopter-based quadcopter over the last couple of weeks, when it wasn’t snowing. The first flight test wasn’t so successful. Whilst it flew, I couldn’t get it much above about 1-2 metres off the ground even at full throttle. This turned out to be due to miscalibrated ESCs, which didn’t know what a full throttle signal from my transmitter looked like.

Once recalibrated, it flew pretty well but my inexperience led to a few crash landings and a few broken propellers (no major damage though). It also drifted around quite a bit, but I improved that by recalibrating the accelerometers much more carefully.

I tested out the “return to launch” (RTL) feature a few times too. The idea is that the quadcopter remembers the gps coordinates of the launch point, and when RTL mode is enabled, it flies home automatically. The exact behaviour involves it flying up to a safe altitude (above any possible trees and such), then flies home, holds it’s position there for 5 seconds and then lands.

The first time I tested this, it seemed to work but instead of holding its position, it flew off into a nearby tree. I tested it a couple more times and it worked once, but veered off again another time. I later discovered reported problems with gps accuracy with the Arducopter firmware version I was using (2.9.1). Upgrading to 2.9.1b seems to have improved the behaviour a lot, but RTL isn’t yet something I’m comfortable trusting.

I did discover that the arducopter firmware keeps quite detailed telemetry logs of its flights, along with gps coordinates and altitude. Very good for figuring out what went wrong afterwards.

Control-wise, a major breakthrough for me was realising I didn’t necessarily need to keep pointing the “front” of the aircraft where I wanted to fly. It can go in any direction at any time, you just need to keep track of where the front is pointing to know where roll and pitch will get you. This is admittedly a bit hard to keep track of, so I think I’ll paint the legs or something to help with that. When it’s up high, especially with the light behind it, it’s quite hard to tell whether it is turning towards or away from you. Need more practise.

I also had some problems with the legs sticking in the ground (or breaking) on heavy landings. I’m making some improvements and might blog about that later.

And I stuck an old plastic takeaway container on top to protect a bit from rain and snow. Which worked well until I crash landed it today and smashed it.

IMG_1977_cropped

And today, I strapped an old Android smartphone to it and recorded a first person view of a flight. It was an old cheap phone so the video quality is poor, but it’s still exciting. I’m researching what cameras I can get to record higher definition video atm – I’ll post about that later.

Overall, it’s been quite stable and much sturdier than I’d imagined. It’s a little stressful to fly but I’ve managed to resist the urge to panic and drop throttle any time I’m not certain what is going on. I’d definitely recommend doing your test flights in a large empty grassy field (not a hard road surface), well away from people and buying quite a few spare propellers (which I did).

I’ve gathered all my videos so far into this Youtube playlist.

Quadcopter build, aluminium frame

quadcopter frame take 1

I decided very early on that I wanted to build my own frame rather than buy a kit or anything. I wanted to learn some new skills, but I also expected to be crashing this thing quite a lot and didn’t want to have to keep waiting for new parts to be shipped out (or worse, find them out of stock!).

After some research, I decided to skip carbon fiber (for now?) and use aluminium. It’s strong, lightweight, cheap and pretty easy to work with. I asked around a few local fabrication companies but there apparently aren’t any aluminium stockists in Bradford any more. I gave up and bought online from aluminiumwarehouse.co.uk which worked out nicely, except for the £15 delivery charge.

I bought some square tubing of various sizes for the arms and a length of flat for some odd jobs (perhaps the landing legs). It’s pretty cheap (especially compared to buying from a diy store) so I bought about 10 metres in total. I could build a fleet of quadcopters with this.

I looked into getting the center plates laser cut by a local firm, but it turned out slightly too expensive. £5 each for up to 10 isn’t too bad really, but I wanted quite a few plates in case of crashes and I want a bit more flexibility with the layout as I develop the design. So instead I just got some blank square plates cut to size by aluminiumwarehouse at about 50p each (for 140mm x 140mm x 2mm) and am drilling them manually. I think the 2mm is a bit overkill, and each plate weighs in at 100 grams. I reckon I could have gotten away with 1mm even.

I’m using titanium-coated drill bits; a high rotational speed is recommended for aluminium, but I’ve done just fine with my battery powered drill which isn’t that fast.

And just a reminder to clamp your plates down firmly so the drill doesn’t catch them and fling them around like blunt alloy throwing stars.

I’ve started out with the 12.7mm x 12.7mm x 1.6mm tubing for now – it seems more than solid enough. Drilling the center plate has proven a little fiddlier than I’d hoped and one of my arms isn’t mounted as square as I need. But that’s why I bought lots of extra blank plates!

I cut the tubing using a hacksaw but it came out with uneven ends which makes it difficult to measure and align things. Next time I’ll use the mitre saw (for which I bought metal cutting blades just for this purpose, doh!).

The finished arms and plates (and screws) come in at 400 grams in total. I’m planning to cut some holes in the plates which might lighten it a bit, much not much.

Open source pasta sauce

Pasta sauce

This is my pork and beef mince pasta sauce recipe, heavily inspired by my Grandma’s recipe. I cook it in a casserole dish with a lid in the oven for about 4 hours. This is not quick food, but it’s well worth the wait and this recipe makes about 6-7 big portions, suitable for freezing.

Ingredients

  • 500g pork mince
  • 500g beef mince
  • a little olive oil
  • 2 onions
  • 8 cloves of garlic
  • 4 x 400g cans of chopped tomatoes
  • 2 x 140g cans tomato purée
  • 2 teaspoons salt
  • 2 teaspoons brown sugar
  • Couple of fists full of fresh basil leaves
  • 2 bay leaves
  • 1 teaspoon ground black pepper

Process

  1. Chop the onions and fry them in the olive oil for 5 mins (don’t brown them)
  2. Finely chop and add the garlic and fry for a few more minutes
  3. Add the pork and beef mince, fry on a high heat until it’s no longer pink
  4. Tear up the basil into little bits and add to pot
  5. Add everything else, mix well and bring to boil
  6. Put lid on pot, put in pre-heated oven at 150 degrees Celsius
  7. Cook for 4 hours, stirring once an hour or so

It’s interesting to taste the sauce as it cooks – it really does get better and better the longer you cook it. I used to cook it on a regular stove top but it required almost constant stirring to avoid burning so now I cook it in the casserole dish. Maybe your stove can go lower than mine. A friend tried it with a slow cooker (after frying everything on the stove) and said it works just fine but I’ve yet to give that a go myself. My Grandma used to just sit and stir it all day.

If you like it wetter, add some passata. You can probably leave out the brown sugar – I’ve not really been able to tell a difference with or without it myself.

Serve with some pasta, with plenty of Parmesan cheese and black pepper.

UPDATE: I’ve changed the recipe from 1kg pork mince to 50/50 pork/beef mince after some feedback from friends, and some experimentation of my own. It’s a lot tastier like this and it turns out, this is actually what my grandma used to do!

UPDATE: I’ve changed the recipe, switching out the “mixed dry Italian herbs” for actual real fresh basil leaves. My mum told me that’s what my Grandma used and it really makes a major difference to the flavour.

Quadcopter build, first steps

After weeks of research, and then days of cultivating a Farnell
shopping basket, I finally handed over some cash for the first parts
for my quadcopter. Lots of nuts and bolts, cable ties, spacers and
other misc. Plus Amazon and Ebay purchases too: heat shrink stuff,
connectors, various tools and nice new variable power soldering iron
to replace my (admittedly very trusty) 25W Weller.

The frame stuff was in excess of the cost of a off-the-shelf
quadcopter frame kit, which did make me almost reconsider building my
own. A kit obviously gives you all the parts for one frame, and I have
enough parts here to rebuild my own frame 10 times over, for around
the same cost (though I’ve still to buy the aluminium, but that’s
quite cheap). From what I’ve read, frame breakage is to be expected,
especially if you’ve not flown anything before, so the idea is this
will pay for itself. It’s also going to be way more fun, and I’ve
already learned loads of new things about lots of diverse subjects!

I also ordered an Ardupilot APM 2.5+ flight controller, with the gps
addon. I went without the telemetry module for now – looking to
integrate it with my (to be chosen) transmitter’s built-in telemetry
display.

I’ve yet to choose transmitter, motors, escs, props or battery.

Plan is to get this flying and learn how to fly it before starting
down the first-person-view video setup.

I’ll try to keep up with blogging about it and file them all together here in the Quadcopter category.

Quadcopter build photo gallery

Lily suddenly not sure if toilet roll is toy

Lily eating toilet roll

Visualising the Ruby Global VM Lock

I’m working on Ruby bindings for Ceph’s RADOS client library – it’s the first native C Ruby extension I’ve written so I’m learning lots of new things.

I’m keen to ensure my extension releases Ruby’s Global VM Lock (GVL) wherever it’s waiting on IO, so that other threads can do work and I’ve written a few simple test scripts to prove to myself it’s working correctly. The result is a textual visualisation of how releasing the GVL can improve the behaviour of threads in Ruby.

For example, I just added basic read and write support to my library so you can read and write objects stored in a Ceph RADOS cluster. My first pass was written without releasing the GVL – it just blocks waiting until Ceph has completed the read or write.

My test script starts three threads, one doing rados write operations in a loop and outputting a “w” to STDOUT when they succeed, one doing rados read operations and writing a “r” and one just doing some cpu work in Ruby and writing a “.”

This is the output from the script before I added GVL releases:

As you can see, it’s almost as if Ruby is switching round-robin style between the threads, waiting for each one to complete one iteration. In some cases, the cpu worker doesn’t get a look in for several read and write iterations!

So then I extracted the blocking parts out to a separate function and called them using Ruby 1.9’s rb_thread_blocking_region function, which releases the GVL, and then reran my test script:

As you can see, the thread doing CPU work in Ruby gets considerably more work done when the GVL is released. Those network-based IO operations can block for quite some time.

It’s exactly what is expected, but it’s neat to see it in action so clearly.

The code for the library is here on github, but but it’s under heavy development at the moment and is in no way complete – I’ve only pushed it out so early so I can write this blog. And this is commit showing just where I made the read/write operations release the gvl.

Beautiful command-line interface design talk

I spoke about writing beautiful command-line interfaces at Scottish Ruby Conference back in June and they’ve published the video, which is freely available for viewing now.

The slides are available here in pdf format (if you’re interested, they were made using emacs org mode and beamer.

There were loads of great talks recorded so check out the videos of them all here on the schedule.

Domes on Mars – Pathfinder Mission

The recent NASA “Curiosity” mission that just landed reminded me of something I did the last time a robot was exploring up there.

It was July 1997, and I was 18 years old and relatively new to the Internet (having been knocking around it for only a couple of years at that point, by my recollection). I was a keen computer artist, using Lightwave 3D at the time.

So when the Mars Pathfinder robot landed and made big news, it was only natural that I rendered some domes onto the first photos they published and put them on the Internet, claiming them to be “The images NASA doesn’t want you to see”.

Much to my surprise, the counter on the free webspace I had with my Demon Internet dial-up account quickly starting increasing. Many hundreds of thousands of hits, which was a lot in those days (as it took 20 minutes just to connect to the Internet and the only way to find things was with gopher and downloading a photo was something you left running overnight and it all cost so much money, unless you used stolen “Red Hot Ant” free dialup numbers which everyone did all the time).

Anyway, long story short, it attracted lots of attention. I was interviewed live on some American crackpot Art Bell radio show (Atlanta’s WGST Planet Radio). I told them I found the images in the bins round the back of NASA). It was in magazines (well, one). And I became rich and famous and banned from ever visiting Mars.

Anyway, the Internet Archive has a copy of the text and I managed to find this one image some daft consipiracy website had kept a copy of. And here it is in all it’s glory.

And there began my long career of being a dick on the Internet.

UPDATE: The Way Back When machine is able to show my original site now and it has all my silly explanation of the origin of the photos (plus this bonus photo shows a figure stood in the distance)

UPDATE: I found an old backup of the images, plus some wireframes of the rendering I did to make the domes

UPDATE: I found an old issue of “Connect” magazine a friend gave me at the time, back when magazines still existed. Connect was basically just a list of links to funny stuff on the Internet this week and they reviewed the site in their Conspiracies section.