Page 2 of 6 FirstFirst 123456 LastLast
Results 11 to 20 of 55
  1. #11
    500+ This must be a daytime job



    Join Date
    Jul 2013
    Posts
    917
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Scaling Localiser and Glideslope Needles for HSI

    Jack

    I was expecting you to outline your logic flow and not rush into coding. I will repeat yet again, as others have tried to tell you, that firstly you must look at the overall picture and write down the sequence, conditions, parameters etc of what you want to achieve for the ENTIRE programme. If you do not do this then:-

    1) You keep having to amend code that you have written as things happen that you did not take the time to identify or consider
    2) You get bogged down writing code with no clear idea of the end result
    3) Your final code will look and work horribly - 30,000 lines of code?

    Turning to your code above, leaving the syntax error aside, have you done a dry run in your mind to check if what is happening meets your requirements? I suspect not, as it does not look correct to me. Take a known set of pot values and GS values at a certain point and work through your code to check.

    Again, I strongly counsel you to avoid the compulsive urge to start coding and concentrate on the overall logic flow. Keep at it . No pain no gain

    Regards

    David

  2. #12
    500+ This must be a daytime job Boeing 747 Flyer's Avatar
    Join Date
    Nov 2009
    Location
    England
    Posts
    635
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Scaling Localiser and Glideslope Needles for HSI

    Hi David,

    I spent just under an hour last night, interestingly with a pen and paper, planning this out.

    I appreciate there may be problems with it but the point is this is the result of my hard work.

    Firstly, I planned out what I wanted to do. Secondly, I wrote out the scripting.

    In brief, this was my plan:

    - Scale between GS and Pot
    - If this value is too low, move up. And vice versa
    - If the values are equal, don't move the motor

    Of course, what I actually wrote was much longer than this; it is just a brief.

    I appreciate there are problems but please, if you can, improve it, and point out my errors. The Value_Calc subrutine is wrong, I know. I couldn't find a scale that would work.

    Regards,

    Jack

  3. #13
    500+ This must be a daytime job



    Join Date
    Jul 2013
    Posts
    917
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Scaling Localiser and Glideslope Needles for HSI

    Jack

    I am not doubting your effort, just the direction You really need to write out your requirements etc for the whole "programme" not part of it. It is only then that you can see how to structure the code.

    A gripe if I may - why present something for me to look at if you know that the scaling is wrong, that is inconsiderate and wastes my time

    Moving on, you know both the pot and G/S values from top to middle, so it is a ratio, similar to work you have done with servos on other threads.
    I suggest you look at these previous servo codings, 737NUT gave some examples and links etc. Rightly or wrongly, I do not think the best way of helping is to write or closely peruse/troubleshoot the code for you, assuming I had the time, it is for you to learn, try, amend, correct, try again etc etc. That is the way to get to grips with SIOC. If you demonstrate this, then I will gladly help on any future stumbling blocks, assuming I have the competence

    Regards

    David

  4. #14
    500+ This must be a daytime job Boeing 747 Flyer's Avatar
    Join Date
    Nov 2009
    Location
    England
    Posts
    635
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Scaling Localiser and Glideslope Needles for HSI

    Hi David,

    No problem, I managed to figure everything out.

    This is correct:

    Code:
    Var 100 link FSUIPC_IN Length 1 Offset $023A   // seconds of FS time  (0 - 59)
    {
     CALL &Value_Calc
     CALL &Position // Call our variables that control the motor
    }
    
    Var 0005, name GS, Link FSUIPC_IN, Offset $0C49, Length 1 // FSUIPC GS Source
    
    Var 30, name Calc // Calculation holding variable
    
    Var 58, name Pot, Link USB_ANALOGIC, Input 2, PosL 0, PosC 127, PosR 250 // Potentiometer
    
    Var 3, name Value_Calc, Link SUBRUTINE // Provides a scale between GS and Pot
    {
     L0 = &Motor_1 * 2.83 
     L0 = &Motor_1 - 621.86
     &Calc = L0 * -1
    }
    
    Var 0001, name Motor_1, Link USB_DCMOTOR, Output 1 // Motor
    
    Var 0002, name Position, Link SUBRUTINE // The Calculations for driving the motor
    {
     IF &GS >= 138
     {
      IF &GS <= 254
      {
       IF &Calc > &GS
       {
        &Motor_1 = 120
       }
       ELSE
        {
         IF &Calc < &GS
         {
          &Motor_1 = 250
         }
          ELSE
          {
           IF &Calc = &GS
           {
            &Motor_1 = 128
           }
          }
        }
      }
     }
    }
    This code perfectly scales the top half of the GS motor. The bottom half is identical; it's just that it uses a different multiplier and negative value in the calculation of Var 3.

    Tell me what you think.

    Regards,

    Jack

  5. #15
    500+ This must be a daytime job



    Join Date
    Jul 2013
    Posts
    917
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Scaling Localiser and Glideslope Needles for HSI

    Jack

    Excellent - see you can do it ! Just one error that has missed your quality check

    In your scaling calcs you are using variable &motor_1 when it should be &pot.

    I will not criticise this too much, given that I wasted 2 hours last night trying to make a pot recognised by SIOC. I had cut and pasted code from another script without noticing that there are two commands for reading analogue ports. IOCARD_ANALOGIC from a USB expansion card and USB_ANALOGIC from a servo or dc motors card. I had the wrong one !!

    Regards

    David

  6. #16
    500+ This must be a daytime job Boeing 747 Flyer's Avatar
    Join Date
    Nov 2009
    Location
    England
    Posts
    635
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Scaling Localiser and Glideslope Needles for HSI

    Hi David,

    I have ran the following script with some sucess:

    Code:
    // *****************************************************************************
    // * Config_SIOC ver 3.7B1   -     By Manolo Vélez    -    www.opencockpits.com
    // *****************************************************************************
    // * FileName : Glideslope.txt
    // * Date : 6/10/2011
    
    
    
    Var 0100, Link FSUIPC_IN, Offset $023A, Length 1     // seconds of FS time  (0 - 59)
    {
      CALL &Value_Calc
      CALL &Value_Calc2
      CALL &Position     // Call our variables that control the moto
      CALL &Position2
    }
    
    Var 0005, name GS, Link FSUIPC_IN, Offset $0C49, Length 1     // FSUIPC GS Source
    
    Var 0030, name Calc     // Calculation holding variable
    
    Var 0031, name Calc2     // Calculation holding variable (2nd)
    
    Var 0058, name Pot, Link USB_ANALOGIC, Input 2, PosL 0, PosC 127, PosR 250     // Potentiometer
    
    Var 0003, name Value_Calc, Link SUBRUTINE     // Provides a scale between GS and Pot
    {
      L0 = &Pot * 2.83
      L0 = &Pot - 621.86
      &Calc = L0 * -1
    }
    
    Var 0001, name Motor_1, Link USB_DCMOTOR, Output 1     // Motor
    
    Var 0002, name Position, Link SUBRUTINE     // The Calculations for driving the motor
    {
      IF &GS >= 138
      {
        IF &GS <= 254
        {
          IF &Calc > &GS
          {
            &Motor_1 = 120    
          }
          ELSE
          {
            IF &Calc < &GS
            {
              &Motor_1 = 250   
            }
            ELSE
            {
              IF &Calc = &GS
              {
                &Motor_1 = 128    
              }
            }
          }
        }
      }
    }
    
    Var 0009, name Position2, Link SUBRUTINE     // The Calculations for driving the motor (
    {
      IF &GS >= 0
      {
        IF &GS <= 119
        {
          IF &Calc2 > &GS
          {
            &Motor_1 = 120    
          }
          ELSE
          {
            IF &Calc2 < &GS
            {
              &Motor_1 = 250    
            }
            ELSE
            {
              IF &Calc2 = &GS
              {
                &Motor_1 = 128    
              }
            }
          }
        }
      }
    }
    
    Var 0561, name Value_Calc2, Link SUBRUTINE     // Provides a scale between GS and Pot
    {
      L0 = &Pot * 3.6
      L0 = &Pot - 468.2
      &Calc2 = L0 * -1
    }
    The Calc2 variables are so forth are to cover the bottom half of the GS offset, from 0 to 119.

    The sucess was that, when the GS needle was at the top of the HSI in FSX, my needle rose top the top.

    But... That was it. Even though the GS value changed, I did not see the motor move. Looking in IOCPConsole, it is clear that the Calc variable is not changing value at all, which explains the stationary motor. The position variable also does not change value.

    Why is this happeneing? The ValueCalc variables should detect the difference between the GS offset and my pot, and should start to move the motor.

    Unfortunately, they don't for some strange reason!

    Regards,

    Jack

  7. #17
    500+ This must be a daytime job



    Join Date
    Jul 2013
    Posts
    917
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Scaling Localiser and Glideslope Needles for HSI

    Jack

    It is unclear from your post which sections are not happening correctly!

    A quick perusal, I could be wrong, but you need to re-examine your coding for the calc2 section. Earlier you said that at the "middle" section then FSX read 254 and the pot read 130. Try a dry run through your coding and I think that you will find there is an error as the result of your coding should be that at those respective positions the motor should be at zero speed ie calc2 and GS should be equal

    Also, why are you calling both calc subroutines each time? I though my earlier text logic flow suggested identifying which section of "movement " you were in and calling the appropriate and different subroutine

    Regards

    David

  8. #18
    500+ This must be a daytime job Boeing 747 Flyer's Avatar
    Join Date
    Nov 2009
    Location
    England
    Posts
    635
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Scaling Localiser and Glideslope Needles for HSI

    Hi David,

    At Pot = 130, FSX could either be at 254 or 0.

    It should be made clear that 254 and 0 are almost the same thing. The gap between the two values is negligable, and they both pretty much represent the middle. The Pot = 130 at the middle.

    EG:

    FSX = 0

    Calc = 130 * 3.6
    Calc = 468 - 468
    Calc = 0 * -1
    Calc = 0

    Pot and FSX are equal, so nothing happens

    FSX = 254

    Calc = 130 * 2.83
    Calc = 367.9 - 621.86
    Calc = -253.96 *-1
    Calc = 253.96 ROUND = 254

    As you can see, the calculations allow a smooth transition over the middle point.

    When I meant it was not working, I meant...

    When the FSX GS needle was at the very top, my needle moved all the way to the top.

    But... That was it. When the FSX needle moved down, my needle stays still. This meant that the needle was being governed by the TOP (Calc, not Calc 2) formula.

    Regards,

    Jack

  9. #19
    500+ This must be a daytime job



    Join Date
    Jul 2013
    Posts
    917
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Scaling Localiser and Glideslope Needles for HSI

    Jack

    Thanks for the explanation, though it is difficult to comment on the code - it is a bit like reading a page through a microscope when you have no external references
    Have you tried using the iocpconsole log function - that will show when the motor stops and should give you a pointer as to why

    Regards

    David

  10. #20
    500+ This must be a daytime job Boeing 747 Flyer's Avatar
    Join Date
    Nov 2009
    Location
    England
    Posts
    635
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Scaling Localiser and Glideslope Needles for HSI

    HI David,

    I have looked in the IOCPConsole and it is weird...

    Basically, whenever FSX is started, the GS value always reads 0. As a result, the motor moves to the 0 position (middle)... But keeps on going until it hits the bottom. From here, no matter what the value of GS, the motor remains motionless on the bottom of the glideslope.

    Interestingly, in IOCPConsole, SIOC is reporting values of "Calc" incorrectly. See here:

    Code:
    58=171 - Pot
    58=172 - Pot
    58=171 - Pot
    58=172 - Pot
    58=171 - Pot
    58=172 - Pot
    58=171 - Pot
    100=0 - seconds of FS time  (0 - 59)
    3=0 - Value_Calc
    30=451 - Calc
    561=0 - Value_Calc2
    31=297 - Calc2
    2=0 - Position
    9=0 - Position2
    1=120 - Motor_1
    5=0 - GS
    With the Pot at 171, how on earth can Calc be 451?

    Calc = 171 * 2.83
    Calc = 483.93 - 621.86
    Calc = -137.93
    Calc = -137.93 * -1
    Calc - 137.93 ROUND = 138

    Clearly, something is wrong. How is SIOC getting 451, it should be 138.

    Regards,

    Jack

Page 2 of 6 FirstFirst 123456 LastLast