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
UAV

Flies with eyes

After being waylaid a bit by stomach bugs, I got a lot more hardware stuff working over the last two days. I got my ultrasonic range finder board wired up to the main microcontroller. It figures out distance using the method which bats use – emit a chirp, and then listen for the echo. In terms of coding, this means I’ve got external interrupts and 16-bit timer stuff working pretty well. I’ve been putting all of the code into a class “MyLibrary” … a bundle of code I hope to reuse in the future. Anyway, on with the pretty photos …

Range sensors

This is the ultrasonic range-finder board, with the emitter/listener pair.


Range circuit
This is my main microcontroller circuit. The Atmega16L is the big chip in the foreground, with 8Mhz timer crystal, reset circuitry and in-circuit programming connector. A couple of super-bright green LED’s are there to increase the blinkenlight coefficient. In the background, a MAX232 uses a capacitor charge-pump to convert the voltage levels so that the Atmega chip can talk to the serial port on my PC. And at the back-right, there’s a simple 5v power supply with filtering caps.


IR sensors
There are coming up next. They’re infrared thermopiles, which detect IR radiation and are a simple and effective way of detecting where the horizon is. More importantly, they’re very shiny. 🙂

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
UAV

UAV talks serial

I’ve managed to get the Atmega16 chip talking to my PC over an RS232 serial link. The Atmega has a built in UART, which makes serial comms easy. You just write the data you want to send into a register and the chip does the rest. A MAX232 chip converts from the 5v levels used by the atmega into +10/-10v used in RS232. I can leave my circuit plugged into the serial line and the in-circuit-programming cable and control everything from my PC. I had to work through a few problems with a logic probe to figure out what was going wrong, which made me think that an oscilloscope would be a Fine Idea. So, a quick trip to ebay resulted in a purchase of a basic but very useful oscilloscope, yay!

I’m trying to get Avrforth running at the moment. It runs okay, but whenever I try to store anything to memory, it hangs. I’m going to dig a bit more into this, but it’s not really directly relevant to the UAV project so I’m not going to spend ages on it.

Next task is to get to grips with timers and PWM input. This will let me use my ultrasonic range finder board, which indicates distance by varying the pulse-width. As ever, there is plenty of information out there about this. I also found an old i2c temperature sensor IC which I might try using too.

Categories
UAV

Different flavours of microcontrollers

Tim‘s friend Tony Cole wrote this list of various microcontrollers and what they’re suitable for. It’s really interesting .. much more useful than a dry list of technical specs. So, many thanks to Tony for his expertise and wisdom:

For very small tasks look at the MicroChip PIC, I think there is a GNU C
compiler for it now, but I use Hi-Tech C Compiler.
A very fast PIC copy is the Scenix.
Others: Zilog Z8 - I think this has free C Compiler and network stack.



For small tasks look at the Atmel AVR 8-bit micro controllers:
http://www.atmel.com/dyn/products/devices.asp?family_id=607


The one I use is the ATmega128 128-Kbyte self-programming Flash Program
Memory, 4-Kbyte SRAM, 4-Kbyte EEPROM, 8 Channel 10-bit A/D-converter.
JTAG interface for on-chip-debug. Up to 16 MIPS throughput at 16 MHz.
2.7 - 5.5 Volt operation. 

You can get a in-circuit programmers from Kanda
http://www.kanda.com/index.php3?cs=1&
or the chip manufacturer/distributors.

For RTOSes C Compilers and other tools for the AVR look at
www.avrfreaks.net


###########

For bigger/faster tasks the Atmel AT91 SAM 32-bit ARM processors are
very good, I've used the AT91SAM7S64 Atmel's AT91SAM7S64 is a member of
a series of low pincount Flash microcontrollers based on the 32-bit ARM
RISC processor. It features a 64 Kbyte high-speed Flash and an 16 Kbyte
SRAM, a large set of peripherals, including a USB 2.0 device, and a
complete set of system functions minimizing the number of external
components. The device is an ideal migration path for 8-bit
microcontroller users looking for additional performance and extended
memory.  

The AT91SAM7S256 has 256 Kbyte high-speed Flash and a 64 Kbyte SRAM:

http://www.atmel.com/dyn/products/devices.asp?family_id=605


Look at:
The AT91SAM7S64-IAR bundles the AT91SAM7S-EK evaluation board, a USB
JTAG ICE and a 32 KB limited IAR KickStart toolchain. It enables the
evaluation of and code development for applications running on an
AT91SAM7Sxx device. 

This only cost about £100 and is a good starting point.


ECOS RTOS might be worth looking at: http://ecos.sourceware.org/ there
is also a book on this ROTS.

Or search the web for a free RTOS: e.g. http://www.freertos.org/



###########

Unfortunately, all the above will not realistically run interpreted
languages, such as python, java, scheme, lisp - but you could search the
web, someone might have done it!. These sorts of languages require an OS
like Linux.



If you want to run Linux look at the many embedded PCs available, or the
Atmel AT91RM9200 microcontroller (ARM9 CPU with MMU). The AT91RM9200-EK
Evaluation Kit supports the AT91RM9200 ARM9-based 32-bit RISC
microcontroller and enables real-time code development and evaluation.
http://www.atmel.com/products/AT91/

It has 32MBytes of SDRAM and runs at 200MHz:
The AT91RM9200-EK Evaluation Board
The board consists of an AT91RM9200 together with the following:
! 8 Mbytes of parallel Flash memory
! Four banks of 2M x 32-bit SDRAM
! DataFlash® or SD/MMC memory expansion socket
! Additional DataFlash memory expansion socket
! Digital-to-Analog Converter (DAC) for a stereo audio signal
! Four communication ports (USB host and device, Ethernet, serial and
DBGU)
! Graphic controller with output to a standard VGA monitor
! JTAG/ICE, ETM and code test port interface
! Expansion connector
! Onboard prototype area

I have a working Linux tree and GNU C Compilers for the AT91RM9200-EK,
you can do a lot on this baby. It is well supported see
http://www.arm.linux.org.uk/