Thursday, May 10, 2012

Compass Maths II

The arrangement of our fans determines how finely we can control our direction.  With eight evenly spaced radial fans, we can create motion in sixteen unique directions using simple on-off control.  We can either turn on four fans at once, which gives us eight useful combinations, or three fans at once, which gives us eight more distinct combinations, for a total of sixteen drive directions.  More resolution would require fine PWM control and a lot more math.  At present, I'm happy with sixteen. 

The direct result of this known resolution in drive means that we need to be able to determine compass heading to the same depth of resolution.  The figure below includes a table of the different values expected from the compass if we could receive a noise-free signal at each of 16 different headings.

However, this direct interpretation of results is very sensitive to small distortions in signal.  As you can see from the second table, distinguishing between the maximum signal strength and the signal strength from a slightly off axis reading requires distinguishing between 1 and .92.  And determining where to make the decision as to whether the signal is a 1 or a .92 is not in itself straightforward.  One could simply split the difference between the two, but that imposes a linear assumption on a function that is markedly curved at that point.  Since it's a sine wave, you could split it at the angle halfway between the two readings, and this is what I've done in the smaller table above.  However, this only leaves the signal between .98 and 1 as a legitimate "1" value, requiring stable signal resolution down to 1% of the full range.  This is not ideal.  Additionally, since 9 distinct values show up in both tables, it's also over-kill.  Two 9-valued inputs have 81 distinct combinations - we only need 16. 

The solution I've come up with is to make coarser distinctions between values.  Ideally, we could cut the possible inputs into four ranges in such a way that our outputs would span all 16 unique combinations.  However, I have not yet found a convenient way to do that.  I did find a way to split the signal inputs into 5 ranges, making cuts in the places where the slope of the function was steepest and the distinctions were clearest.  In this model, all values above .55 are lumped together as "++", all values betwen .55 and .20 are "+", all values between .20 and -.20 are "0", all values between -.20 and -.55 are "-", and any signals below .55 are "--".  As you can see from the corresponding tables below, this makes for much broader, less noise-sensitive detection bands while still creating a unique map from signal in to direction out at a resolution of 16 headings/revolution.


So, there you go ... compass maths produces 16 unique headings.  Now that we have those headings, we can map a heading input to which engines should be turned on.  The following table shows which engines need to be turned on based on a goal direction from the controller (top row) and a knowledge of the boat's current heading (left column). 



It looks intimidating, but it turns out to follow an extremely simple and predictable pattern, which is summarized in the table below.



And that's the current state of the art for compass maths.  Next task - combine x-y accelerometer data and controller compass heading information to produce North-South and West-East 8 bit transmission values.


No comments:

Post a Comment