I'm working on an Mechatronics project where i access current(Amps) data from multiple sources and have to calculate a response(fed to mechanical system) based on changing value trend within and among (increasing/decreasing values and increasing/decreasing relative differences). There are many a conditions to access (unique or mixed response to each) and many a variables they are dependent on, so i'm left with lots of nested if-elif-else
statements each evaluating multiple conditions and flags thus taking time to respond while data flows in fast (as much as 85 Hz).
The module is part of larger project and needs to be done using Python only. Here's how that part of my current code looks like -
def function(args):
if flag1 and flag2 and condition1 and not condition2:
if condition3 and not flag3:
response += var1
flag4 = True
elif -- :
response = var2
flag3 = False
elif -- :
------------
else :
------------
if not flag_n and flag_m and condition_p and condition_q and not condition_r:
if.. elif ... else :
flags... response changes..
more IFs
i need is a better and effecient way of doing this or a completely different approach e.g. some machine learning or deep learning algorithm or framework suitable for above kind of usage.