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!
Bookmarks