Categories
General

Autopilot and RF hacking

This evening I got a crude (but surprisingly effective) autopilot working in Flightgear, and also cracked open my receiver and waved an oscilloscope at it. The autopilot is a separate ruby script which uses the Flightgear httpd interface to read and write values which control the plane. The plane managed to stay up in the air, despite me selecting heavy turbulence. But, to quote Susan, “I wouldn’t like to be a passenger in that plane!”. So, next I need to add a bit more complexity to the autopilot (technical version: my pid controller needs some id).

Categories
General

Progress

I managed to get a few more useful electronics bits working, which means the end is in sight for the initial electronics phase of the UAV project. I got the Atmega16 talking to a DS1820 temperature sensor over the i2c bus, which tells me that my computer cupboard is at 22 degrees C. I also figured out how to use the various modes of the inbuilt 16-bit timer, which allowed me to do PWM control of an LED (ie. the world’s most complicated light dimmer). Now I need to chop the cable of my one-and-only servo to hook it up and control its position using PWM. This will also let me use the other end of the cable to plug the RC receiver unit into my circuit as a PWM input, and experiment with sampling that. Eventually, the Atmega is going to sit inside in RC aeroplane, listening to my “suggestions” sent to it over the RC link, and deciding what actual control output to send to the servos.

So I’m getting pretty close to doing some UAV stuff rather than electronics dabbling. The main Flightgear developer has an interesting article about autopilots, although I’m still interested in finding more references. I was in Maplin today, and they sell IR thermopiles which will probably do for horizon-detecting (and therefore, attitude determination).

I’m still pondering what kind of software system to run on the plane. It’s going to have plenty of work to do – sampling RC PWM inputs, using the ADCs to measure attitude, talking to GPS over serial line, data logging, and producing PWM output for servos. It’s lots of stuff to juggle, and having some form of realtime task scheduler layer is starting to look attractive. I’ve seen other UAV systems use multiple microcontroller rather than trying to make one do everything. Kinda like communicating sequential processess …

Categories
General

The plane that flies itself

I’ve decided to dabble in hardware again. The grand plan is to turn an RC aeroplane into a semi-autonomous UAV. I’ve used PIC microcontrollers before, but this time I thought I’d switch and try one of the Atmel microcontrollers instead. Microcontrollers have got a bit nicer since the last time I used them. For example, generating PWM signals for servos used to require software bit-banging but now there is hardware support for it.

I settled on the Atmega16L which runs at 8MHz, has 16k flash ram for programs, and 1k static ram for calculations. It has onboard analogue-digital converters, which is perfect for plugging in “what angle is the plane at” sensors. It has 3 PWM outputs, which’ll be perfect for controlling the servos which move the rudder/elevator plus the electronic speed controller. Plus, it supports in-circuit programming which means you don’t have to keep dragging the chip out of the circuit and plopping it in a hardware programmer.

At first, I’m going to for something simple as proof-of-concept – automatic landing lights. An ultrasonic range sensor will point downward from the plane and switch on some super-bright LEDs when the height is below two meters. It’s nothing complicated, but it’s a good starting point to allow me to figure out how this stuff will fit into an RC plane, and how to make it robust enough to survive the inevitable crash landings.

Beyond that, I’m going to use a spare RC channels to allow me to switch an ‘autopilot mode’ on and off. After all, I want to be able to get manual control back if the software crashes! When autopilot is on, the microcontroller will take input from a range of sensors (IR horizon finding or inclinometer/gyro-combo for attitude, pressure sensor for altitude, GPS for position). It’ll figure out what it wants to do next, and move the control surfaces appropriately. Things like automatic landing modes have been done before and sound pretty possible. There are also light-weight wireless video systems which people have put into planes. And you can buy fairly cheap 433Mhz radio link chips which’d allow telemetry to be sent from the plane to a ground station.

What’s the point in this? It’s a blend between three of my interests. I’m interested in the physics/engineering aspect of flight and aerodynamic design. I enjoy doing simple hardware systems, and nowadays simple hardware systems can do lots of cool stuff. Finally, I like working on reliable/critical software systems. So, dealing with the realtime aspects of this project will be new and fun. As an aside, I’ve been reading about RTLinux and RTAI which are pretty cool. It reminds me of first time I saw the SoftICE debugger. There’s something remarkable about being able to pause an entire operating system!

On the software side, I’d be happier in a high-level language. But embedded systems are traditionally done in C, Forth or assembly in order to meet hard realtime demands. If you used a garbage collected language, a GC pause could mean that you miss a critical event. There’s been research into incremental collectors with low overhead for embedded systems though. And, typically, you have less need for dynamic memory allocation in an embedded system. But people have tried targetting high level language to embedded platform. Someone had a go at running nhc98 haskell runtime on a palm pda, and someone else did scheme on a PIC (PDF). If you were to use a high-level language in an embedded system, you’d want to have some guarantees about its time and space performance, and this is what the Hume project at St Andrews uni is looking at. And if you think that HLL can’t live on the bare metal, take a look at this Haskell OS project.

Finally, the “testing” side of this project is pretty interesting. I can obviously unit test the software before it goes onboard the plane. But how do you do integration testing? One answer is to place your flight-control software into a virtual world and make it think that it is actually flying. To achieve this, you can take advantage of the fact that Flightgear can send information about the plane (position, inclination, speed etc) out on a network port. You can grab this information, repackage it and send it to the flight-control software running inside a simulator (no hardware involved). The flight control software ultimately sends signals to servo, so you need to read these signal, map them back into flightgear-speak and push them across the network to flightgear. This way, you can see how the flight-control software behaves in high winds without risking the model plane itself!

Ah, that’s all for now. I’m well aware that I often start projects with grand plans and then get distracted by Other Things. This project is pretty amenable to the old ‘put it on the shelf for a few months’ treatment. It’s not “all or nothing” like some of my previous projects. So I am pretty hopeful of building something k3wl over the next few months and having a semi-autonomous plane buzzing around the skies.

Categories
General

Hardware cool

Looks like Sony are finally going to launch a new e-ink based book reader onto the western market. The “Sony Reader” is a successor to the japanese-only Librie (which I pined for a year ago). I don’t understand why there hasn’t been more products based on the e-ink technology yet. It obviously works fine, and the rest of the hardware is pretty vanilla stuff. What’s the holdup?

Categories
General

Now is then when then is now

Zeitgeist, through the medium of tools and bookmarks:

The tools I couldn’t live without in 2005: mythtv / web developer toolbar / live headers / nxml-mode / aliasadd / sed/grep/sort/uniq / unison / freemind

Neat stuff I found this year: iftop / dnstop / dbtoy / wmctrl / metalog / clamav

Thank you delicious and bloglines for that magic “where did those 3 hours go?” effect.

Quote of the year: “I’m very excited. I’m just hiding it well.”

And, courtesy of firefox’s “sort by add date” in bookmark manager:

January: DIY high-altitude glider
February: Edinburgh in 1844
March: Continuations for the web
April: Looping over filenames-with-spaces in bash
May: The world is not round
June: South Pole blog
July: Student’s T distribution
August: The Hammock wiki
September: Francis Crick profile
October: High-speed video of pool shots
November: Bad cookies in firefox
December: Programmers need to learn statistic, or I will kill them all