Page 1 of 2 12 LastLast
Results 1 to 10 of 15
  1. #1
    25+ Posting Member
    Join Date
    Jan 2008
    Location
    Sydney, Australia
    Posts
    29
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    SIOC and Encoders (ROTATE function, etc)

    Hi guys, I'm trying to understand the way SIOC handles rotary encoders in the variable processing function.

    Say I bind a function to changes of encoder value, what value does it take as I turn the encoder?

    Is it the successive increments starting at 0 e.g. 0 -> 1 -> 2 -> "+inf" and to "-inf" as encoder is turned the other way? If so then acceleration attribute makes sense as defining the speed sioc goes through the sequence.
    Why then in the scripts for, say, MCP the heading value is directly assigned from the encoder?

    e.g. MCP_HEADING = ROTATE 0 to 360, ENCODER_VALUE
    That doesn't quite make sense to me... unless the MCP_HEADING takes the delta, adjusting the real heading somewhere?

    Can someone clarify exactly what values are coming in from the hardware(into SIOC variable)?

    Cheers!

  2. #2
    500+ This must be a daytime job
    Join Date
    Jul 2013
    Posts
    948
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: SIOC and Encoders (ROTATE function, etc)

    Try this site for excellent sioc coding advice. Also elswhere on the site is an example of using encoders in a nav1 example

    http://www.lekseecon.nl/howto.html#rotaryencode

  3. #3
    25+ Posting Member
    Join Date
    Jan 2008
    Location
    Sydney, Australia
    Posts
    29
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: SIOC and Encoders (ROTATE function, etc)

    Quote Originally Posted by fordgt40 View Post
    Try this site for excellent sioc coding advice. Also elswhere on the site is an example of using encoders in a nav1 example

    http://www.lekseecon.nl/howto.html#rotaryencode
    Hi, thanks for you reply, but I have seen Nico's website and it doesn't answer the question. Neither does the help file coming with SIOC. I really want a doco stating exactly how the hardware interfacing works
    So far what I've see are "working" examples... Problem is they don't work for me and the way I ended up writing my event processing function is by incrementing current value, say:

    heading = heading + &ENCODER_VALUE.

    Now that suggest to me that ENCODER_VALUE is the change in encoder's position and not absolute value

    And here's Nico's example:
    Code:
    Var 1 Link IOCARD_ENCODER Input 40 Aceleration 2 Type 2
      { 
         L0 = v1 // * -1 turning clockwise should be plus
         v2 = ROTATE 0 359 L0
      }
    
      Var 2 // heading (0 .. 359)
    Notice how v2 is assigned the value directly from the encoder? How does that work if encoder value is not absolute?
    Is var2 taking a change in value and not the value itself?

    Hope I explain my problem clear enough.

  4. #4
    500+ This must be a daytime job
    Join Date
    Jul 2013
    Posts
    948
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: SIOC and Encoders (ROTATE function, etc)

    In the example you quote above

    Var 1 only provides the direction of encoder travel, it has no absolute value
    Var 2 has the absolute value of the heading.
    When the encoder moves then Var 2 value is inc/dec according to the direction of travel within the range of 0 to 360.
    Var 2 does not receive an absolute value from the encoder. Var 2 will get its initial value from either a definition, or as a result of an arguement within another function

    If you use the IOCPconsole within the main SIOC window you will see the variables within your script and their changing values arising from your h/w changes

  5. #5
    25+ Posting Member
    Join Date
    Jan 2008
    Location
    Sydney, Australia
    Posts
    29
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: SIOC and Encoders (ROTATE function, etc)

    Quote Originally Posted by fordgt40 View Post
    In the example you quote above
    When the encoder moves then Var 2 value is inc/dec according to the direction of travel within the range of 0 to 360.
    Var 2 does not receive an absolute value from the encoder.
    That's what I don't get. I see assignment statement v2 = (Expression), where Expression is result of ROTATE function
    Now how does rotate function get from increment/decrement to absolute heading??? It must return absolute value because its result is assigned to v2..
    Now unless I'm missing something obvious here..
    Thanks for your help though, I appreciate it.


    Edit:
    When the encoder moves then Var 2 value is inc/dec
    Just to be emphasize the point here. You say Var2 is incremented or decrements which implies dependency on current value which I don't see in ROTATE.

    In other C++ you'd write: var2 += (var1), and note var2 = ROTATE(var1), because ROTATE doesn't know anything about var1 in this case.

  6. #6
    500+ This must be a daytime job
    Join Date
    Jul 2013
    Posts
    948
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: SIOC and Encoders (ROTATE function, etc)

    var 2 does not get an absolute value from the rotate function. Think in terms of Var 2 equals its current value inc or dec by the encoder movement direction within the range (for Var 2) of 0 to 359. The Rotate command does not have a persistent or global value.

  7. #7
    25+ Posting Member
    Join Date
    Jan 2008
    Location
    Sydney, Australia
    Posts
    29
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: SIOC and Encoders (ROTATE function, etc)

    So hold on...
    When I write var2=blah
    does it mean var = var + blah? It doesn't make sense... Either var2=blah or var2 = var2 + blah, can't be both..
    And I know that var2 = blah acts as assignment operator because if I hardcode var2 = 123 for example I get 123 and not var2 incremented by 123 every time.

    Edit:
    Is it maybe just special handling of variable assignment in the encoder routine?

    PS: Sorry, I work as a programmer, so can't just accept some code without understanding

  8. #8
    25+ Posting Member
    Join Date
    Jan 2008
    Location
    Sydney, Australia
    Posts
    29
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: SIOC and Encoders (ROTATE function, etc)

    Ah! I think some "global variable" magic happens with ROTATE and LIMIT functions!
    I'm experimenting right now and what I see is when I use LIMIT function, var2 does not exceed certain value, so that means that either LIMIT keeps track of the actual value and doesn't let it drift outside the limits or some magic happens during assignment

  9. #9
    150+ Forum Groupie pdpo's Avatar
    Join Date
    Nov 2005
    Location
    belgium
    Posts
    280
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: SIOC and Encoders (ROTATE function, etc)

    nope,

    var2 = blah does set the value of blah in var2
    however, the ROTATE function will take the value of var2 and increment it with the increment value (which can be positive or negative) and then it will check the limits as stated in the first two parameters.
    using the value of the encoder directly in the rotate function will allow to jump some values if you turn the rotary fast.
    if you do not want that then you have to condition the encoder value to be +1 if >=0 and -1 if <= -1.

    Greetz Peter
    FS9+PM+AST+opencockpits

  10. Thanks aVaTar thanked for this post
  11. #10
    500+ This must be a daytime job
    Join Date
    Jul 2013
    Posts
    948
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: SIOC and Encoders (ROTATE function, etc)

    Peter

    Precisely

    David

Page 1 of 2 12 LastLast

Tags for this Thread