+ Reply to Thread
Results 1 to 3 of 3

Thread: advanced Smoother in expression 2

  1. #1
    Wire Noob Skyjets's Avatar
    Join Date
    May 2009
    Posts
    15

    Default advanced Smoother in expression 2

    My code won't Work
    here is.....



    @name Ralentisseur avance (Advanced Smoother)
    @inputs Speed Acceleration Target Rate
    @outputs Active Value


    # 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)
    {
    interval(20)
    }
    }



    What's Wrong?

  2. #2
    Wire Sofaking IEF015's Avatar
    Join Date
    Feb 2008
    Location
    London, ON (Canada, eh?)
    Posts
    1,640

    Default Re: advanced Smoother in expression 2

    Code:
    @name Ralentisseur avance (Advanced Smoother)
    @inputs Speed Acceleration Target Rate
    @outputs Active Value
    @trigger all
     
    # 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) { 
             interval(20)
       }
    }
    I didn't really look at the code, but it seems fine.
    "It's my favourite country song. And I hate it."

  3. #3
    Wire Noob Skyjets's Avatar
    Join Date
    May 2009
    Posts
    15

    Default Re: advanced Smoother in expression 2

    I know but it Won't work I tried it (I am making an elevator)on my elevator.....
    but it work in expression 1 ???
    I'll try your code
    Won't Work
    Last edited by Skyjets; 05-20-2009 at 02:57 PM. Reason: code try

+ Reply to Thread

Similar Threads

  1. How To Use Advanced Smoother?
    By Jack in forum Installation and Malfunctions Support
    Replies: 4
    Last Post: 10-03-2008, 06:48 AM
  2. [REQUEST] How to make a expression gate that has a timer and a smoother function
    By funkake in forum Gate Nostalgia (Old School Wiring) Discussion & Help
    Replies: 5
    Last Post: 09-17-2008, 11:05 PM
  3. Smoother Expression
    By -=Fox=- in forum Installation and Malfunctions Support
    Replies: 1
    Last Post: 11-02-2007, 06:18 PM

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