+ Reply to Thread
Results 1 to 7 of 7

Thread: A spazz detector in need of some love.

  1. #1
    Wirererer cadde's Avatar
    Join Date
    Oct 2007
    Location
    Sweden
    Posts
    266

    Default A spazz detector in need of some love.

    I have made a working spazz detector (it will detect if an object is behaving abnormal) and i have made a mess of the code. it works but it's not OPTIMAL.

    I would really appreciate some criticism on the code and replacement code for it to look nicer.
    I'm not expecting anyone to rewrite the whole thing but just give me some small bit's to shorten and clean up the code. Or alternate ways of solving the same issue.

    Here's the code:
    Code:
    N@Spazz Detector
    I@TargetP TargetR TargetY PWR RESET Tick
    O@PVS PDS PSA YVS YDS YSA RVS RDS RSA
    RESET -> LastPVS = 0, LastPDS = 0, PSA = 0;
    RESET -> LastYVS = 0, LastYDS = 0, YSA = 0;
    RESET -> LastRVS = 0, LastRDS = 0, RSA = 0;
    STime = 0.3
    SMaxDelta = 10
    SMaxDiffDelta = 3
    SDeltaCount = 3
    
    CurP = extangp(), PDiff = angnorm(CurP - TargetP)
    CurY = extangy(), YDiff = angnorm(CurY - TargetY)
    CurR = extangr(), RDiff = angnorm(CurR - TargetR)
    
    PDelta = $PDiff
    abs(PDelta) < SMaxDelta & Tick - LastPVS > STime -> PVS = 0;
    abs(PDelta) > SMaxDelta & abs(PDelta) < 170  -> PVS = 1, LastPVS = Tick;
    PVS == 1 -> PSA = PDelta - SMaxDelta;
    PDeltaDiff = 0
    LastPDelta > 0 & PDelta < 0 -> PDeltaDiff = LastPDelta - PDelta;
    LastPDelta < 0 & PDelta > 0 -> PDeltaDiff = PDelta - LastPDelta;
    PDeltaDiff < SMaxDiffDelta & Tick - LastPDS > STime -> PDS = 0, PDSC = 0;
    PDeltaDiff > SMaxDiffDelta -> PDSC += 1;
    PDSC == SDeltaCount -> PSA = PDeltaDiff - SMaxDiffDelta, PDS = 1, LastPDS = Tick;
    LastPDelta = PDelta
    
    YDelta = $YDiff
    abs(YDelta) < SMaxDelta & Tick - LastYVS > STime -> YVS = 0;
    abs(YDelta) > SMaxDelta & abs(YDelta) < 170  -> YVS = 1, LastYVS = Tick;
    YVS == 1 -> YSA = YDelta - SMaxDelta;
    YDeltaDiff = 0
    LastYDelta > 0 & YDelta < 0 -> YDeltaDiff = LastYDelta - YDelta;
    LastYDelta < 0 & YDelta > 0 -> YDeltaDiff = YDelta - LastYDelta;
    YDeltaDiff < SMaxDiffDelta & Tick - LastYDS > STime -> YDS = 0, YDSC = 0;
    YDeltaDiff > SMaxDiffDelta -> YDSC += 1;
    YDSC == SDeltaCount -> YSA = YDeltaDiff - SMaxDiffDelta, YDS = 1, LastYDS = Tick;
    LastYDelta = YDelta
    
    RDelta = $RDiff
    abs(RDelta) < SMaxDelta & Tick - LastRVS > STime -> RVS = 0;
    abs(RDelta) > SMaxDelta & abs(RDelta) < 170 -> RVS = 1, LastRVS = Tick;
    RVS == 1 -> RSA = RDelta - SMaxDelta;
    RDeltaDiff = 0
    LastRDelta > 0 & RDelta < 0 -> RDeltaDiff = LastRDelta - RDelta;
    LastRDelta < 0 & RDelta > 0 -> RDeltaDiff = RDelta - LastRDelta;
    RDeltaDiff < SMaxDiffDelta & Tick - LastRDS > STime -> RDS = 0, RDSC = 0;
    RDeltaDiff > SMaxDiffDelta -> RDSC += 1;
    RDSC == SDeltaCount -> RSA = RDeltaDiff - SMaxDiffDelta, RDS = 1, LastRDS = Tick;
    LastRDelta = RDelta
    First, i will try to explain the purpose of this E-Gate.

    1. It will detect if an object is rotating too fast. (higher than 10 delta)
    2. It will detect if an object is rotating back and forth, the tell of a "spazz".

    Objective 1 is just so that we can detect if the object is moving faster than it needs to or should. This will prevent damage to eyes and connected objects.

    Objective 2 is what it really comes down to, detecting if the force applied to an object is exceeding the limits and the object is "spazzing".

    With this information i can take appropriate action to prevent "spazzing" on thruster stabilized platforms where i balance the platform according to pitch/yaw/roll target angles.

    For starters i know that "Target_P/Y/R" is not needed and should be stripped.
    And "P/Y/R_Diff" should go with it.
    What I'm really looking for is some more efficient conditionals and smarter solutions to the problem.

    Need more? Please ask!

    Thanks for any help!

  2. #2
    Wirererer cadde's Avatar
    Join Date
    Oct 2007
    Location
    Sweden
    Posts
    266

    Default Re: A spazz detector in need of some love.

    And i will add this for readability of the script...
    Any solo uppercase letters correspond to the following:

    P = Pitch
    Y = Yaw
    R = Roll

    S = Spazz (Any variable that has to do with the detection of spazz)

    V = Velocity (A velocity spazz)
    D = Delta (Mostly used to explain a "delta" spazz, where the delta goes from positive to negative in one tick)

  3. #3
    Wirererer cadde's Avatar
    Join Date
    Oct 2007
    Location
    Sweden
    Posts
    266

    Default Re: A spazz detector in need of some love.

    13 Reads and no posts, not even a "Piss off" or "You stink".

    Well, as usual. When looking for quick assistance you better assist yourself so i did and here is the result...

    -----------------------------------------------------------
    N@Spazz Detector V2
    I@RESET Tick
    O@PS PSA YS YSA RS RSA
    RESET -> LastPS = 0, PSA = 0;
    RESET -> LastYS = 0, YSA = 0;
    RESET -> LastRS = 0, RSA = 0;

    STime = 0.3
    SMaxDiff = 170
    SMinDiff = 3
    SDiffC = 3

    CurP = extangp()
    CurY = extangy()
    CurR = extangr()

    PV = $CurP
    PDiff = 0
    LPV > 0 & PV < 0 -> PDiff = LPV - PV;
    LPV < 0 & PV > 0 -> PDiff = PV - LPV;
    PDiff > SMaxDiff -> PDiff = 0;
    PDiff < SMinDiff & Tick - LastPS > STime -> PS = (PSC >= SDiffC ? 1 : 0), PSC -= (PSC > 0 ? 1 : 0);
    PDiff >= SMinDiff -> PSA = abs(PDiff) - SMinDiff, PSC += 1, LastPS = Tick;
    PSC >= SDiffC -> PS = 1, PSC = SDiffC;
    LPV = PV

    YV = $CurY
    YDiff = 0
    LYV > 0 & YV < 0 -> PDiff = LYV - YV;
    LYV < 0 & YV > 0 -> YDiff = YV - LYV;
    YDiff > SMaxDiff -> YDiff = 0;
    YDiff < SMinDiff & Tick - LastYS > STime -> YS = (YSC >= SDiffC ? 1 : 0), YSC -= (YSC > 0 ? 1 : 0);
    YDiff >= SMinDiff -> YSA = abs(YDiff) - SMinDiff, YSC += 1, LastYS = Tick;
    YSC >= SDiffC -> YS = 1, YSC = SDiffC;
    LYV = YV

    RV = $CurR
    RDiff = 0
    LRV > 0 & RV < 0 -> RDiff = LRV - RV;
    LRV < 0 & RV > 0 -> RDiff = RV - LRV;
    RDiff > SMaxDiff -> RDiff = 0;
    RDiff < SMinDiff & Tick - LastRS > STime -> RS = (RSC >= SDiffC ? 1 : 0), RSC -= (RSC > 0 ? 1 : 0);
    RDiff >= SMinDiff -> RSA = abs(RDiff) - SMinDiff, RSC += 1, LastRS = Tick;
    RSC >= SDiffC -> RS = 1, RSC = SDiffC;
    LRV = RV
    -----------------------------------------------------------

    I dropped the delta velocity detection, thinking about it i wont need that functionality as much as i need the real spazz detection.

    I would still love to hear some pointers on how i can optimize the script in size and speed.
    So far the script will detect a spazz just as quick as i can.
    And i have learned that a spazz usually starts really small and then increase with exponential power.
    Also, a spazz will stabilize itself to a certain degree. Meaning that if you have a constant force on one axis and restrict the other two, the spazz will remain stable to the decimal. If i let the other two axis go however the spazz will kind of "travel" across the other two, even though the origin of the spazz is due to the force applied on the third axis.


    EDIT: The $ "dollar" signed delta vars in the script got dropped under code tags. Dunno whats up with that.
    Last edited by cadde; 03-16-2008 at 11:34 PM. Reason: What's up with the $

  4. #4
    Wirererer seth1010's Avatar
    Join Date
    Feb 2008
    Posts
    204

    Default Re: A spazz detector in need of some love.

    could this be used with a toggle weld so that when something starts "spazzing out" it gets welded to world and then automaticly unwelds when the ss
    spazzing is done?

  5. #5
    Wirererer cadde's Avatar
    Join Date
    Oct 2007
    Location
    Sweden
    Posts
    266

    Default Re: A spazz detector in need of some love.

    Quote Originally Posted by seth1010 View Post
    could this be used with a toggle weld so that when something starts "spazzing out" it gets welded to world and then automaticly unwelds when the ss
    spazzing is done?

    Well yes but the whole point of the spazz detector is to not interfere with the operation of a stabilized platform. Only make sure that the platform can use as much force as possible without any spazzing.

    And imagine having a weld to world on a plane for instance. You are cruising along nicely at 100 MpH and BAM! You are welded to the world for a short time because you spazzed a little.
    Not to mention that the spazzing would most likely resume once unwelded in that sitation.


    EDIT: Oh and when i tested this in conjunction with a balancer i could apply any outside force i wanted and the balancer would do it's best to keep up with that load. Automatically and hardly noticeable once stabilized.

  6. #6
    Wire Sofaking Hitman271's Avatar
    Join Date
    Feb 2008
    Location
    Why? You looking for somebody?
    Posts
    731

    Default Re: A spazz detector in need of some love.

    Try adding weight to the main part of whatever you are building.Or a central VERY heavy prop in the middle of the contraption and weld everything to that.
    Quote Originally Posted by Anticept View Post
    This is not some place where you can toss your dick around and expect people to suck it.
    Community Gpu Thread. Post Yours!

    Bouncy Ball

  7. #7
    Wirererer cadde's Avatar
    Join Date
    Oct 2007
    Location
    Sweden
    Posts
    266

    Default Re: A spazz detector in need of some love.

    Quote Originally Posted by Hitman271 View Post
    Try adding weight to the main part of whatever you are building.Or a central VERY heavy prop in the middle of the contraption and weld everything to that.
    Thanks but that's not the purpose though. I know all about weight in GMod and no matter how high you set the weight on a prop it will eventually spazz when subjected to enough force.

    The purpose here is to take ANY object with ANY weight and give it the optimal thrust before it spazz out. It's working fine for me right now.

    But if anyone has any suggestions on CODE optimization i am very happy to receive your thoughts!


    Cheers!

+ Reply to Thread

Similar Threads

  1. No Wire-Love
    By Mobius in forum Installation and Malfunctions Support
    Replies: 12
    Last Post: 07-01-2008, 05:00 AM
  2. Mass Detector lag
    By andy1976uk in forum Bug Reports Archive
    Replies: 8
    Last Post: 02-12-2008, 01:06 PM
  3. Health Detector?
    By cpf in forum Ideas & Suggestions
    Replies: 4
    Last Post: 11-15-2007, 12:12 PM
  4. A letter confessing my love to vista
    By miron in forum Off-Topic
    Replies: 44
    Last Post: 09-07-2007, 05:32 AM
  5. More detector tools
    By andy1976uk in forum Ideas & Suggestions
    Replies: 4
    Last Post: 07-17-2007, 02:42 PM

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