Code redundancy?

This forum is dedicated to software development related to MultiWii.
It is not the right place to submit a setup problem.
Software download
Post Reply
happul3
Posts: 44
Joined: Mon Apr 21, 2014 1:54 am

Code redundancy?

Post by happul3 »

Isn't there a redundancy in the following MW code?

Code: Select all

    delta          = imu.gyroData[axis] - lastGyro[axis];  // 16 bits is ok here, the dif between 2 consecutive gyro reads is limited to 800
    lastGyro[axis] = imu.gyroData[axis];
    DTerm          = delta1[axis]+delta2[axis]+delta;
    delta2[axis]   = delta1[axis];
    delta1[axis]   = delta;


The intermediate deltas are irrelevant, only current value and a single value 3 samples ago factor into DTerm. Unless I am missing something painfully obvious, the following would be shorter and more logical but still yield exactly the same answer:

Code: Select all

    Dterm = imu.gyroData[axis] - last3Gyro[axis];
    last3Gyro[axis] =  last2Gyro[axis];
    last2Gyro[axis] = lastGyro[axis];
    lastGyro[axis] = imu.gyroData[axis];

Alexinparis
Posts: 1630
Joined: Wed Jan 19, 2011 9:07 pm

Re: Code redundancy?

Post by Alexinparis »

good catch
I agree, it's equivalent and shorter

Post Reply