I've been fluffing around with excel trying to make up a spreadsheet that works suitably for an auto pilot for a boat. (the spreadsheet is only used to test the formula so I can then write some code following)
I'm using a CMPS03 module with I2C and got that part working well, my problem comes is that my maths is very poor and cant figure out a simple set of rules to make it work well. If for example the set course is 180deg and the boat gets kicked off to 160deg I know I have to correct to the right by 20 degress, and correct to the left for 20 degrees if it gets kicked off to 200 degrees.
However if it's set to say a 10 degree course and it gets knocked left 20 degrees will leave the compass reading 350 then with my current maths ability it will have to do a full loop around the wrong way to come back to 10 degrees.
I was thinking about trying to make a conversion number to add to convert the set point and all subsequent readings relative to 180 deg, then I know if it's higher than 180 I turn left and lower I turn the servo right. But after 2 days of playing with ideas I havent managed it - sigh. I've nearly got it, but then I get issues with -ve numbers and slight aberrations around that 0/360 line -
Any ideas would be greatfully received
Thanks
Bookmarks