Autopilot compass help


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2005
    Location
    New Zealand
    Posts
    171

    Default Autopilot compass help

    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

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Some interesting possiblities ...

    Math help - rolling average Wind Direction
    http://www.picbasic.co.uk/forum/showthread.php?t=6650
    <br>
    DT

  3. #3
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    This is part of the code that does that for the RCAP autopilot. I think it will help you. If you still have problems, let me know.

    Code:
    'b2dest is bearing to destination ie direction to assigned waypoint
    'cmg course made good, in this case from a gps, current course direction of vehicle
    'offcourse is the difference between b2dest and cmg
    'dir_steer : which direction to steer the servo
    
            IF cmg > b2dest Then    'IF cmg > b2dest Then
                dir_steer = 1
                offcourse = cmg - b2dest        'offcourse = cmg - b2dest
            Else
                dir_steer = 0
                offcourse = b2dest - cmg           'offcourse = b2dest - cmg
            EndIF
                                     
            offcourse = offcourse / 10 ' Get rid of the fraction
    
            'If more than 180 degrees offcourse change direction 
            'to take the shortest turn to our course
            IF offcourse > 180 Then             
                 dir_steer = dir_steer ^ %1    'switch direction to steer servo               
                 offcourse = 360 - offcourse
            EndIF
    Last edited by ScaleRobotics; - 6th May 2009 at 06:45.
    http://www.scalerobotics.com

  4. #4
    Join Date
    Oct 2005
    Location
    New Zealand
    Posts
    171


    Did you find this post helpful? Yes | No

    Default

    Thanks heaps guys just what I needed - a slightly different approach works a treat.

  5. #5
    Join Date
    Oct 2005
    Location
    New Zealand
    Posts
    171


    Did you find this post helpful? Yes | No

    Default

    I cant believe how simple that is - I must be getting senile dementia!

Similar Threads

  1. I2C Comm with Digital Compass HMC6352
    By jihlein in forum Serial
    Replies: 10
    Last Post: - 9th April 2008, 22:25
  2. Compass module and I2C bus
    By vladimir059@hot in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 26th December 2006, 20:29
  3. Chipselect Var PORTD,Vecto4X Compass
    By shawn in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 13th April 2006, 01:50
  4. Digital Compass Project
    By BJSmith in forum Serial
    Replies: 2
    Last Post: - 7th April 2006, 19:32
  5. I2C compass - Philips KMZ51
    By barkerben in forum General
    Replies: 0
    Last Post: - 25th December 2005, 20:10

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts