Hi Guys,

Thanks for the responses, I do appreciate the help.

IMM's points about max turn rates etc are very valid here and are one of my own nightmares. The definitive data on criteria like that is just not available, so I am having to make some initial assumptions, (educated guesses). From the nature of the activity, which involves towing very long lines of kit behind a boat, the craft is going to be very restricted in its turning ability. I have assumed something like 1deg/sec max. This does free us up to use a very simple approach. More of that later.

After more digging around after posting I found a very obscure site with a discussion on a similar topic, and IMM's other suggestion was talked about there. Using the sine of the bearing angle would allow us a continuous function but can be ambiguous. For example, increasing our heading to 90deg would give a situation where it was impossible to tell whether the craft had continued on up to 91deg, or started back down to 89deg when we converted the sine back to an angle. However

- if we store both the sine and cosine we have a situation where the 2 pieces of information would allow us to decipher accurately in every case. This would work I think in my situation. But wait for the final solution before deciding on this one.

Dealing with the difference as OBP suggests was something which I tried and rejected early on. It would work. To a point! But then the constant conversions for the statistical data which I am having to calculate and keep became ponderous.

Jimmy's point was one which I had assumed I would have to take into account when I first looked at the problem. The issue here is that, imagine you cross from 1deg to 359deg. You subtract 360 from then on down. (It is worth noting here that I am having to hold a user defined number of historical data readings which may be up to a couple of hundred!) If the system continues turning anticlockwise until it eventually returns to 1deg, (now -359deg), and again crosses the North line, to assure continuity we are now subtracting 720deg. It would work but not in this case.

The solution I came up with and have working is very basic but effective, (simple was in the remit!) I detect zero crossing by testing every new bearing, (B[n]), as it comes in against the last one, (B[n-1]), with:

abs(B[n] - B[n-1]) > 300

If this falls true I have crossed the North line. This covers movement in both directions. (And 300 is only an arbitrary big number, anything larger than the largest single difference between consecutive points would do.)

When zero crossing has been detected, I go into a mode where any new bearing below 45deg has 360deg added to it. This effectively gives me continuity within a band from 45deg around to 405deg which I am now well within. The first time only, I then go into the historic data array and update every reading of under 45deg in the same way. Finally I recalculate the statistical data with the updated values and the system works in "High Mode" from then on. The stats do not care if they are in one mode or another as long as there is continuity within their base data set.

I then continue as normal but monitoring the readings coming in to detect the first one which falls either <330deg or >390deg, (have to be careful with how I do that as they are not exclusive), this means that the system has moved far enough away from North to be reset. I simply reconvert the history and stats to their original form and stop adding 360deg.

The actual values within the programme are not seen by the user at any time, only the result of a test performed internally with it. So as long as this gives the correct outcome, which it does, the crudeness of the system is not a problem.

I like simple solutions. They are easy to code, easy to maintain, and easily accessible to other who may come after. Many thanks for your support, and I hope it stirred the grey matter in a positive way.