Help with implementing sin


Today 06:42
Forum: Proton Plus Compiler v3
Starter: shantanu@india
Views: 0
Replies: 10
Yesterday 20:20
Forum: Absolute Beginners Section
Starter: moonshadow
Views: 0
Replies: 0
+ Reply to Thread
Results 1 to 3 of 3

Thread: Help with implementing sin4 days old

  1. #1
    Junior Member SCV's Avatar
    Join Date
    Nov 2015
    Posts
    39
    Thumbs Up
    Received: 0
    Given: 1
    Total Downloaded
    466.67 MB

    0 Not allowed!

    Default Help with implementing sin

    Greetings all, I have some confusion over the P24 implementation of sine.

    The example in the manual uses the figure of 123 but doesn't give what the result would be. Is sin (123) calculated as (sine 123 = 0.8386) x pi = 2.634?

    Aim of the project...
    I have a camera mounted on the Z axis of a gimble and this axis is mounted inside the Y axis. Using a gyro on the Y axis, I detect rotation in the Z axis (0 +/-32767).
    When the Y axis is at 90 degrees (horizontal) the Z gyro gain will be 1. When the Y axis is at 0 or 180 deg (vertical) the Z gyro gain will be 0 because roll inputs would translate to corrupt the horizon.

    What I wish to do is reduce the magnitude of Z gyro at a sinusoidal rate according to the Y angle (0-90) from the horizon.

    Would this work?

    GYRO_GAIN = (sin(Y_ANGLE)) / 3.1415
    GYRO_Z = GYRO_Z * GYRO_GAIN

    Thanks,

  2. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  3. #2
    Fanatical Contributor Les's Avatar
    Join Date
    Feb 2002
    Posts
    3,193
    Thumbs Up
    Received: 367
    Given: 132
    Total Downloaded
    1.56 GB

    0 Not allowed!

    Default Re: Help with implementing sin

    The Sin function works in Radians, so the value placed into it needs to be converted from degrees to radians. For example, the procedures below will do the trick with triginometry:

    Code:
    '-----------------------------------------------
    ' Convert Radians to Degrees
    ' Input     : pRadians holds the value in radians
    ' Output    : Returns the equivalent in degrees
    ' Notes     : The equations is: pRadians * 180 / PI 
    '
    Proc RadToDeg(pRadians As Float), Float
        Result = pRadians * 57.2958
    EndProc
    '-----------------------------------------------
    ' Convert Degrees to Radians
    ' Input     : pDegrees holds the value in degrees
    ' Output    : Returns the equivalent in radians
    ' Notes     : The equations is: pDegees  PI / 180
    '
    Proc DegToRad(pDegrees As Float), Float
        Result = pDegrees * 0.0174533
    EndProc
    
    '-----------------------------------------------
        Dim Floatin As Float            ' Holds the value to Sin
        Dim Floatout As Float           ' Holds the result of the Sin
    
        Floatin = DegToRad(123)         ' Convert the degree value of 123 into radians
        Floatout = Sin(Floatin)         ' Extract the Sine of the value
        HRSOutLn "Sine of 123 = ", Dec Floatout ' Display the result on a serial terminal
    The resulting value from the demo of a Sine of 123 degrees is 0.838, which is correct.

    Or, using procedures, you can create a Sine function that will operate in degrees:

    Code:
    '-----------------------------------------------
    ' Perform a Sine calculation using degrees
    ' Input     : pDegrees holds the value in degrees
    ' Output    : Returns the sine of pDegrees
    ' Notes     : None
    '
    Proc SineDeg(pDegrees As Float), Float
        Result = Sin(pDegrees * 0.0174533)
    EndProc
    
        Dim Floatin As Float    ' Holds the value to Sin
        Dim Floatout As Float   ' Holds the result of the Sin
      
        For Floatin = -10 To 10
            Floatout = SineDeg(Floatin)
            HRSOutLn "Sine of ", Dec Floatin, " = ", Dec Floatout  ' Display the result
        Next
    The above demo produces these values on the serial terminal:

    Sine of -10.000 = -0.173
    Sine of -9.000 = -0.156
    Sine of -8.000 = -0.139
    Sine of -7.000 = -0.121
    Sine of -6.000 = -0.104
    Sine of -5.000 = -0.087
    Sine of -4.000 = -0.069
    Sine of -3.000 = -0.052
    Sine of -2.000 = -0.034
    Sine of -1.000 = -0.017
    Sine of 0.000 = 0.000
    Sine of 1.000 = 0.017
    Sine of 2.000 = 0.034
    Sine of 3.000 = 0.052
    Sine of 4.000 = 0.069
    Sine of 5.000 = 0.087
    Sine of 6.000 = 0.104
    Sine of 7.000 = 0.121
    Sine of 8.000 = 0.139
    Sine of 9.000 = 0.156
    Sine of 10.000 = 0.173

    If you want more accuracy, use Double variables instead of Float and the dSin function. This will use 64-bit floating point.
    Last edited by Les; 14th May 2019 at 17:34.
    For more example programs for Proton and Proton24 or updates, please visit: Proton WIKI or Proton Files

  4. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  5. #3
    Junior Member SCV's Avatar
    Join Date
    Nov 2015
    Posts
    39
    Thumbs Up
    Received: 0
    Given: 1
    Total Downloaded
    466.67 MB

    0 Not allowed!

    Default Re: Help with implementing sin

    Thankyou Les.
    Might be worth copying this answer into the P24 manual.

  6. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. [SOLVED !] how to calculate sin function
    By minssss in forum Proton Plus Compiler v3
    Replies: 1
    Last Post: 4th July 2010, 23:19
  2. The ultimate sin
    By ADLIN SYSTEMS in forum Proton Plus Compiler v3
    Replies: 11
    Last Post: 23rd September 2008, 10:27
  3. sin cos inputs et al
    By Kapitan in forum Proton Plus Compiler v3
    Replies: 5
    Last Post: 22nd November 2007, 14:16
  4. Implementing a DEF FN in P+
    By J. Mark Wolf in forum Proton Plus Compiler v3
    Replies: 0
    Last Post: 31st January 2007, 15:36
  5. SIN Command
    By VikingDrink in forum Wish List / Product Feedback
    Replies: 0
    Last Post: 13th February 2003, 18:45

Posting Permissions

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