+ Reply to Thread
Results 1 to 8 of 8

Thread: advanced smoother E1 to E2

  1. #1
    Wire Noob RCT3Manie's Avatar
    Join Date
    Feb 2010
    Location
    The Netherlands
    Posts
    15

    Question advanced smoother E1 to E2

    He all.
    In the past there was a code for the Expression1. It called Adv Smoother.
    Code E1:
    Code:
    n@Advanced_Smoother
    i@Target Speed Acceleration
    o@Value Active
    
    # Activate when target has been set
    ~Target -> Active = 1;
    
    # Main computation loop
    first() | clk() ->
    # Precomputation of inputs
        !Acceleration -> Acceleration = Speed * 50 * 2;
        AccLength = Speed^2 / Acceleration / 2
        AccRate = min(Speed, Acceleration / 50)
    # Precomputation of variables
        Distance = Target - Value
        Direction = Distance >= 0 ? 1 : -1
    # Calculate ideal speed modifier
        IdealRate = Speed * Direction
        abs(Distance) <= AccLength ->
            IdealRate *= sqrt(abs(Distance - Rate / 50) / AccLength);
    # Calculate final speed for iteration
        Rate += clamp(IdealRate - Rate, -Acceleration / 50, Acceleration / 50)
        Value += Rate / 50
    # Check if value has reached target
        Active = abs(Rate) > AccRate
                    | abs(Distance) > AccRate / 50
        !Active -> Rate = 0, Value = Target;;
    
    # Schedule the main loop if active
    Active -> interval(20);
    Because E1 no longer exists i want to make it E2
    Well...
    Code E2:
    Code:
    @name Advanced Smoother
    @inputs Target Speed Acceleration
    @outputs Value Active 
    @persist  AccRate AccLength Distance Direction Rate IdealRate
    
    # Activate when target has been set
    if(~Target) {Active=1}
    
    # Main computation loop
    if(first() | clk()){
    # Precomputation of inputs
        if(!Acceleration){
            Acceleration = Speed * 50 * 2
            AccLength = Speed^2 / Acceleration / 2
            AccRate = min(Speed, Acceleration / 50)
        }
        
        # Precomputation of variables
        Distance = Target - Value
        Direction = (Distance >= 0 ? 1 : -1)
        
        # Calculate ideal speed modifier
        IdealRate = Speed * Direction
        if(abs(Distance) <= AccLength){
            IdealRate *= sqrt(abs(Distance - Rate / 50) / AccLength)
        }
            
        # Calculate final speed for iteration
        Rate += clamp(IdealRate - Rate, -Acceleration / 50, Acceleration / 50)
        Value += Rate / 50
        
        # Check if value has reached target
        Active = ((abs(Rate) > AccRate)|(abs(Distance) > AccRate / 50))
        if(!Active){
            Rate = 0
            Value = Target
        }
    }
        
    # Schedule the main loop if active
    if(Active==1){interval(20)}
    Well the code worked so far.
    But the only thing is that the hydrolics don't stop!
    if the target is 50 then it swings between 40 and 60.
    It don't stop.
    if the target is 0 its the same.!

    Can someone help me?`

    Q: Why you use not the Gate Time - Smoother
    A: Becouse its not that smooth then the old E1 Adv Smoother
    Last edited by RCT3Manie; 08-21-2010 at 05:51 AM.

  2. #2
    Wire Noob RCT3Manie's Avatar
    Join Date
    Feb 2010
    Location
    The Netherlands
    Posts
    15

    Default Re: advanced smoother E1 to E2

    Well oke i found the solution:
    Code:
    @name Advanced Smoother
    @inputs Target Speed Acceleration
    @outputs Value Active 
    @persist  AccRate AccLength Distance Direction Rate IdealRate
    
    # Activate when target has been set
    if(~Target) {Active = 1}
    
    # Main computation loop
    if(first() | clk()){
     
     # Precomputation of inputs
        if(!Acceleration){
            Acceleration = Speed * 50 * 2
            AccLength = Speed^2 / Acceleration / 2
            AccRate = min(Speed, Acceleration / 50)
        }
        
     # Precomputation of variables
        Distance = Target - Value
        Direction = (Distance >= 0 ? 1 : -1)
        
     # Calculate ideal speed modifier
        IdealRate = Speed * Direction
        if(abs(Distance) <= AccLength){
            IdealRate *= sqrt(abs(Distance - Rate / 50) / AccLength)
        }
            
     # Calculate final speed for iteration
        Rate += clamp(IdealRate - Rate, -Acceleration / 50, Acceleration / 50)
        Value += Rate / 50
    
    # Check if value has reached target
        Active = ( (abs(Rate) > AccRate) & (abs(Distance) > AccRate / 50) )
        #Instade of a | i placed a &
    
        if(!Active){Rate = 0, Value = Target}
    }
    
    # Schedule the main loop if active
    if(Active==1){interval(20)}
    Well it stops now but not smooth.
    Can someone help me now?

  3. #3
    Spucatum Tauri Bull's Avatar
    Join Date
    Jun 2008
    Location
    Finland
    Posts
    6,009

    Default Re: advanced smoother E1 to E2

    You really need to explain where these are wired to:
    Target Speed Acceleration
    Constant value, speedometer?

    Also, how do you want it to react exactly?
    The change rate capped according the difference between the current value and the target?

    That code looks extremely complicated for something quite easy.
    My signature has a point.
    Quote Originally Posted by Squeakyneb View Post
    when l3ulletje says do it, do it.
    That

    Quote Originally Posted by Anticept View Post
    By the way, Bull is in charge.

  4. #4
    Wire Sofaking Jack37's Avatar
    Join Date
    Jul 2009
    Location
    In front of Tatra T6A5
    Posts
    779

    Default Re: advanced smoother E1 to E2

    It's from elevator by Steven-91. I also wanted this. Did you try to use Expression1-Expression2 Converter or [Release] E1 to E2 converter?


    Wanna add me?:


    My Apps: Adv. Dupe -> E2 Code

  5. #5
    Wire Noob RCT3Manie's Avatar
    Join Date
    Feb 2010
    Location
    The Netherlands
    Posts
    15

    Default Re: advanced smoother E1 to E2

    Quote Originally Posted by Jack37 View Post
    It's from elevator by Steven-91. I also wanted this. Did you try to use Expression1-Expression2 Converter or [Release] E1 to E2 converter?

    no at all. just my brain ^_^
    Mey be use a tool to confurt it.
    Thx for the tip.

  6. #6
    Wire Noob RCT3Manie's Avatar
    Join Date
    Feb 2010
    Location
    The Netherlands
    Posts
    15

    Default Re: advanced smoother E1 to E2

    Quote Originally Posted by Jack37 View Post
    It's from elevator by Steven-91. I also wanted this. Did you try to use Expression1-Expression2 Converter or [Release] E1 to E2 converter?
    No mey be a good idee.
    The code above is from my brain ^_^

  7. #7
    Wire Noob RCT3Manie's Avatar
    Join Date
    Feb 2010
    Location
    The Netherlands
    Posts
    15

    Default Re: advanced smoother E1 to E2

    Quote Originally Posted by Bull View Post
    You really need to explain where these are wired to:
    Target Speed Acceleration
    Constant value, speedometer?

    Also, how do you want it to react exactly?
    The change rate capped according the difference between the current value and the target?

    That code looks extremely complicated for something quite easy.
    Well if you know the older version.

    Inputs
    Target = We value where it must go. Just a button.
    Speed = How fast it must go (like the rate of the time - smoother). Constant Value
    Acceleration = The rate to go to the speed. Constant Value

    Outputs
    Value = The output. Starts slow then go to the Speed.
    Active = if the value is not yet the target. 1/0

    As a wiremodder you must use the expression1 chip insted of the e2 in the beginning of wire mod.
    So it is simular to the Wire Controle > Gate - Time > Smoother
    But more advanced.

    Quote Originally Posted by Jack37 View Post
    It's from elevator by Steven-91. I also wanted this. Did you try to use Expression1-Expression2 Converter or [Release] E1 to E2 converter?
    i dont used a tool like that. i didn't even know!
    but mey be i going to use that.
    Thx for the tip

    Edit:
    Littel update for the script
    Code:
    @name Advanced Smoother
    @inputs Target Speed Acceleration
    @outputs Value Active 
    @persist  AccRate AccLength Distance Direction Rate IdealRate
    
    
    # Activate when target has been set
    if(Target) {Active = 1}
    
    # Main computation loop
    if(first() | clk()){
     # Precomputation of inputs
        if(!Acceleration){Acceleration = (Speed * 50 * 2)}
        AccLength = Speed ^ 2 / Acceleration / 2
        AccRate = min(Speed, Acceleration / 50)
        
     # Precomputation of variables
        Distance = Target - Value
        Direction = (Distance >= 0 ? 1 : -1)
        
     # Calculate ideal speed modifier
        IdealRate = Speed * Direction
        if(abs(Distance) <= AccLength){
            IdealRate *= sqrt(abs(Distance - Rate / 50) / AccLength)
        }
            
     # Calculate final speed for iteration
        Rate += clamp(IdealRate - Rate, -Acceleration / 50, Acceleration / 50)
       #  0  += clamp(   50     -   0 , -    5000     / 50,     5000     / 50)
       #  0  += clamp(        50      ,      -100         ,       100        )
        Value += Rate / 50
     
     # Check if value has reached target
        Active = abs(Rate) > AccRate | abs(Distance) > AccRate / 50
    
        if(!Active){Rate = 0, Value = Target}
    }
    
    # Schedule the main loop if active
    if(Active==1){interval(20)}
    It stops now but not smooth.
    Last edited by RCT3Manie; 08-21-2010 at 01:15 PM.

  8. #8
    Wire Noob RCT3Manie's Avatar
    Join Date
    Feb 2010
    Location
    The Netherlands
    Posts
    15

    Default Re: advanced smoother E1 to E2

    Well thx Wiremode!

    Here my final code and it works!

    Code:
    @name Advanced Smoother
    @inputs Speed Acceleration Target 
    @outputs Active Value   
    @persist Rate Acceleration Speed Distance AccLength AccRate Direction IdealRate
    @trigger all
    
    if(first()) {
        Value = Target
    }
    
    # Activate when target has been set
    if(~Target) { 
        Active = 1
    }
     
    # Main computation loop
    if(first() | clk()) {
    # Precomputation of inputs
        if(!Speed){
            Speed = 10
        }        
        if(!Acceleration) {
            Acceleration = Speed * 50 * 2
        }
        AccLength = ((Speed^2) / Acceleration) / 2
        AccRate = min(Speed, (Acceleration / 50))
    # Precomputation of variables
        Distance = Target - Value
        Direction = (Distance == 0 ? 0 : (Distance >= 0 ? 1 : -1))
    # Calculate ideal speed modifier
        IdealRate = (Speed * 2) * Direction
        if(Distance <= Target) {
            IdealRate *= sqrt(abs((Distance - Rate) / 50) / AccLength)
    # Calculate final speed for iteration
            Rate += clamp(IdealRate - Rate, -Acceleration / 50, Acceleration / 50)
            Value += Rate / 50
    # Check if value has reached target
            Active = (abs(Rate) >= AccRate) | ((abs(Distance) >= AccRate) / 50)
            if(!Active) {
                Rate = 0
                Value = Target
            }
        }
    # Schedule the main loop if active
        interval(20)
    }

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
proceed-collector
proceed-collector
proceed-collector
proceed-collector
linguistic-parrots
linguistic-parrots
linguistic-parrots
linguistic-parrots