Results 1 to 7 of 7

Thread: rotational compass counter

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2020
    Posts
    24

    rotational compass counter

    Hi, I have a control on VB.net that indicates the heading between 0-360 degree (only shows positive value).
    I need to calculate the number of turn counter in clockwise or counterclockwise.
    for example if the compass needle (with value) has made 2 consecutive rotation, the indicator/label will show 2.

    I don't know how to start, thinking how to take care the +ve and -ve rotation.

    Appreciate any help.

  2. #2
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,116

    Re: rotational compass counter

    Is this a control that you have the source code for? Or is it a closed source 3rd party control.

    Assuming that the control raises an event when the heading changes, you would simply need to store previous heading values and add some logic in that event to watch for the heading either "rolling over" from 359 to 0, or "rolling back" from 0 to 359, and then properly increment/decrement a rotational counter.

    That assumes that the changes in heading are continuous integers, in other words, to go from 0 to 20, it would go from 0 to 1, then 1 to 2, then 2 to 3, ... and so on.
    Because if that isn't the case, you would have no way of knowing if the heading instantly changed from 0 to 355, did it change by 5 degrees or by 355 degrees? In the end, the heading is the same, but if you are trying to account for rotational direction, it matters.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jul 2020
    Posts
    24

    Re: rotational compass counter

    It's a 3rd party control. okay, i think I can do like this:

    that quite tough because my compass value not stable at all. it may jump from any value by any increment (not necessary 1)

  4. #4
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,116

    Re: rotational compass counter

    So, as a thought experiment, if it reads 0 one instant, and 0 the next instant, how would you know if it had:

    A. Not moved at all
    B. Moved n*360 degrees clockwise, where n is an integer > 0
    C. Moved n*360 degrees counter-clockwise, where n is an integer > 0

    Basically, if you can't distinguish those possible movements, then I can't think of a way to accomplish what your end goal is.

    It might help if you provided details of this third party control (name, website, documentation, etc) so that perhaps there are events, properties, etc. that can help determine the level of detail sought.

    Good luck.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jul 2020
    Posts
    24

    Re: rotational compass counter

    that is my problem now, if just clockwise rotation, I have no issue.

    I got the control from this site: https://www.advancedhmi.com/forum/in...p?topic=2840.0
    it is the rotational indicator control in the package.

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: rotational compass counter

    As with all programming problems, the first thing you should do is forget that it's a programming problem. How would you do it if it was a completely manual process? If you put some thought into that then you can determine the logic required and then you can write code to implement that logic specifically. You should not be writing code to solve a problem. You should solve the problem first, then write code to implement that solution. Beginners always forget that first step and then wonder why they can't write code to do a thing when they don't know what that thing is. Knowing the end result you want is a small part of the problem. It's knowing the steps to get there you need in order to write code that performs those steps.

  7. #7
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: rotational compass counter

    Quote Originally Posted by Zumbie View Post
    It's a 3rd party control. okay, i think I can do like this:

    that quite tough because my compass value not stable at all. it may jump from any value by any increment (not necessary 1)
    I guess the question is what the limit of "any increment" is?
    Surely something is feeding the angle/heading value that the control is displaying, and the update is quick enough to give some semblance of motion as opposed to a randomly pointing arrow.

    If the angle change from one update to another can change by more than 180 degrees, then I think you're technically out of luck.

    If the angle change (not angle value change) from one update to another will never exceed 180 degrees, then it seems like it would be a simple matter of subtracting the previous angle from the current angle.
    If the Absolute difference between the two angles is greater than 180 degrees you have passed the 0 degree mark.
    If the value is negative then you've passed it clockwise, e.g. 350 degrees going to 20 degrees would be 20 - 350 = -330
    If the value is positive then you've passed it counter-clockwise, e.g. 20 degrees to 350 would be 350 - 20 = 330.
    "Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930

Posting Permissions

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



Click Here to Expand Forum to Full Width