# MAV-blog

Stuff related to MAV's (and UAV's) from a hobbyist's point of view. Info

## New autopilot hardware

I needed more RAM, more flash to store my autopilot code on. Unfortunately, 44 pins PICs don’t have such big amounts of memory. So I had no other option than to design a PCB for a 64 pins SMD chip. But I quickly admitted that my PCB fabrication skills (and tools) are not good enough to make such fine pitch prints. Luckily, there are some great cheap PCB fab companies. I decided to use Olimex. Four PCB’s arrived on my doorstep 15 days later: two for the Pic32, and two for the dsPic33 (I still haven’t decided which Pic to use in the future…).

Main features:
Common:

• Choice between PPM in or PWM in
• 5 Servo outs. Software and a “daughter board” could always add additional servo outputs.
• 2 axis-compass module (3 axis in the future) using I²C
• digital barometer using SPI

dsPIC33 version:

• Powered using the BEC
• Atmel flash chip for data logging

PIC32 version:

• Switched power supply
• Micro-SD socket for data logging

Because everbody loves pictures (dsPic33 version):

Populated with the sensors:

This weekend I implemented a straightforward method for navigating around a circle. For the first day in like a 2 weeks, the weather was also nice enough to take my funjet for a testride. And yes, it worked quite well! I should check GPS logging to see how well in followed the circular path, but from the ground it looked fine.

### How does it work

First we calculate which point on the circle we are currently closest to:

The closest point on the circle is the one at angle radians:
Lon = LonCircleCenter + sin( alpha ) * radius
Lat = LatCircleCenter + cos( alpha ) * radius

Of course we don’t need the point that is currently closest to us, but the one that is “within reasonable range”.
We calculate:
How much radians (circle radians) per second the UAV flies (if he would be on the circle):
(meter per second) / (radians per meter in circle)
vAngular = [radians per second] = UavSpeed / ( (2 * PI) / (2 * PI * radius) ) = UavSpeed / radius

Now comes the tricky part: we need to decide to which point on the circle we want to fly to. We calculate a new angle alpha2:
alpha2 = alpha + vAngular * tSeconds

We calculate the angle on the circle we should be at in tSeconds .

So we need to aim for the point on the circle tSeconds ahead of us:
Lon = LonCircleCenter + sin( alpha2 ) * radius
Lat = LatCircleCenter + cos( alpha2 ) * radius

How do we choose tSeconds? Good question. I quess it depends on how responsive your UAV is. I took 2 seconds on my first attempt. In the future I will experiment with other values.

### Too far from the circle

One exception case should still be handled: What if we are too far from the circle? With the above algorithm, we would fly straight at the circle. This would be a huge problem because we might arrive at the circle with a heading that is perpendicular to the desired heading! In this case we could choose:
angle2 = angle + PI/2

The point at angle2 is the point on the circle where we would “touch” (and not cross) the circle if we were flying straight at it from a point far away from the circle. This is not optimal, because:
1. In most cases we are still quite close to the circle
2. In case of a big circle, we would not take the shortest route towards the circle
As a basic solution we can pick a smaller angle:
angle2 = angle + PI/4

Depending on the UAV’s agility, speed,current heading and distance from the circle, we could come up with a formula that yields an angle between 0 and PI/2. This still needs to be investigated. In a paper by Nathan D. Rasmussen, I found the following interesting yet visually trivial vector field for circle navigation:

As a conclusion: complex solutions exist, but simple solutions work good enough in most cases!

## Artificial horizon

Despite of the lack of fresh messages on my weblog (no, I’m not abandoning the hobby UAV scene :-) ), I still get a lot of emails with questions and requests.
Some people emailed me for the code of the artificial horizon I published some time ago. Unfortunately that one was a quick hack and I was planning to rewrite it in clean and well documented .Net code and post them on my weblog. But honestly, so far it works for me and probably will for you, so why should I put more time into it? :-)

So: here’s the VB.net code: ArtificialHorizon.zip
Usage: Build it, drag the user component on your form, update pitch and roll properties.