Wednesday, November 28, 2012

Test flight with attitude stabilization

See the video here

After the hardware was "completed", I was finally able to focus on the software side of things. The linked video shows the first test flight of an attitude stabilizer, that will later on become my autopilot.

I mounted the navigation board and my RC receiver v2 (both discussed in previous posts) on my Graupner Elektro Rookie plane (I'll be later moving this stuff to my Skywalker, but I want to make sure everything works before I do that).

A simplified description of how the stabilizer works:

  • The RC transmitter is used to set target roll and pitch angles (aileron and elevator sticks).
  • The navigation board reads measurements from a gyroscope and a magnetometer, and uses those measurements to track the plane's attitude.
  • The RC receiver reads the attitude from the navigation board and compares the measured roll and pitch angles to the target roll and pitch angles. Ailerons and the elevator are then adjusted to correct for the error.
The sensor fusion algorithm used in the navigation board is explained in a previous post. The attitude control itself is done just by a P-controller (which was set for too much gain in the video). I'll probably be adding a derivative term as well, just to get a slightly faster response to turbulence. I'm guessing I won't be needing an integral term though, as I'm relatively sure the steady state errors in the roll and pitch will not be significant compared with other navigation errors.

Now to implement an autopilot, all I'll have to do is to change the way I set the target roll and pitch. I'm again planning on using just a P-controller at first. As the plane is (I hope) mostly flying quite level, the roll and pitch angles correspond with changes in heading and changes in altitude respectively. A GPS receiver, which is already on-board, provides the heading of the plane. The target heading (to the next waypoint) is computed and the roll angle is set according to the heading error. The same thing is done with the altitude and pitch angle. An important caveat, however, is that the roll and pitch angles should be kept relatively small even if the heading or altitude errors are large. I plan to address this by simply having a fairly low saturation value for the target angles.

Tuesday, November 27, 2012

Navigation board build

As I explained in a previous post, I want the plane to be able to track its attitude. The receiver is already doing a time critical function in software (namely the servo updates), so it would be quite a strain on it also to read all the different sensors and to filter the data. I thus ended up building these functions on a separate board, which interfaces with the receiver through UART.

The IMU module I ended up using
The IMU sensor board I'll be using has a gyroscope, a magnetometer and an accelerometer. The sensors are all read through I2C, which is nice as the microcontroller I thought of using (Atmega328) has built in I2C hardware support. However, in addition to these three I2C sensors, I need also to connect a GPS receiver. This presents a problem, because the microcontroller only has one hardware UART, and that is already in use for communication with the receiver. I could change my choice of microcontroller, to something that has two hardware UART ports. On the other hand, I could go with a software UART as I already have several Atmega328s in my components bin. I decided on the cheaper option, and went with an Atmega328 and software UART. I was fairly certain that this choice would bite me in the ass later on (which it did, in the form of timing issues in the code).

I ordered the IMU board from ebay and was so eager to get this thing built as fast as possible that I took measurements of the board dimensions from the photo on ebay and started the design. The board is very straightforward and there is nothing special about it what-so-ever, as can be seen in the schematics and the layout.
Unfortunately I screwed up measuring the dimensions from the photo, and as a result the mounting hole of the IMU board doesn't match up with the hole on my board. It doesn't really matter, as now I just hold the board steady with double sided tape :-).

Top side of the board after etching and drilling.

Bottom side of the board after connecting the vias
I have recently investigated the possibility of doing through hole plating for the vias, but it seems to be quite a bit more involved than what I'm currently doing. I guess I'll have to continue soldering short pins through the vias to connect them.

Top side almost completed
The hardware UART port is used to communicate with the RC receiver whereas the software UART port connects to the GPS receiver. I put in the external I2C port for the possibility to add a barometric pressure sensor later on, although now you can buy cheap sensor boards that already contain a pressure sensor.

Bottom side almost completed

While assembling the board, it turned out I had run out of 20 MHz crystals. I picked up some the next day, but I didn't take new photos of the board.