I've edited out most of the content I had previously written because your code does work (except for the mis-matched parenthesis), but it threw me off because this is not really a complimentary filter. You have a hodge-podge here that is confusing to look at initially.
First you have a lag filter on the accelerometer output:
alpha = 0.98;
filteredAccelerometer = alpha*filteredAccelerometer + (1-alpha)*rawAccelerometer;
Then, instead of doing proper numeric integration on the gyro, which would look something like:
gyroAngle = gyroAngle + gyroAngleVelocityArray.Pitch*deltaTime;
You instead are substituting in the filtered accelerometer measurement as the "accumulated" angle:
gyroAngle = filteredAccelerometer + gyroAngleVelocityArray.Pitch*deltaTime;
and you are calling all of this a "complimentary filter", such that:
pitchAngleCF = alpha*pitchAngleCF + (1-alpha)*angleAccelArray.Pitch + gyroAngleVelocityArray.Pitch*deltaTime;
However, this isn't really a complimentary filter because there's "option" or "setting" to blend the gyro and accelerometer outputs. I would suggest converting both sensors to a common unit (degres, for instance), then using the complimentary filter to combine the two measurements, then filter that if you find that anything needs filtering.
So, following your schema:
accelVelocityArray.Pitch = accelVelocityArray.Pitch + accelAccelArray.Pitch*deltaTime;
accelAngleArray.Pitch = accelAngleArray.Pitch + accelVelocityArray.Pitch*deltaTime;
gyroAngleArray.Pitch = gryoVelocityArray.Pitch*deltaTime;
alpha = 0.95;
pitchCF = alpha*gyroAngleArray.Pitch + (1-alpha)*accelAngleArray.Pitch;
THIS is the output of a complimentary filter. Now if you find that your craft is not responsive enough you can increase
alpha (take more of the reading from the gyro), or if you find that there is too much drift you can decrease
alpha (take more of the reading from the accelerometer). If you find that the reading is too noisy, then you can put this through a lag filter:
beta = 0.9;
filteredPitch = beta*pitchCF + (1-beta)*filteredPitch;
NOW you adjust
beta to determine how smooth you want the combined pitch reading to be.
I hope this clarifies things for you.
Now, regarding your actual question, I don't think it's possible to give a quality answer with the (lack of) data you have provided.
It is true that, for a real system with inertia, if you set the proportional gain too high the system will oscillate. However, it is not clear if you are only using a proportional gain (if you have kI and kD set to zero). Also, because the craft is tethered and you are holding it, it's not clear if the craft is responding to its own controller or if it's responding to the external forces (you and the tether).
I'm also not sure how stable your control loop timing is and/or how you are determining what
deltaTime should be. If you're interested in manual tuning of a PID controller, first be sure that you are processing your sensor output correctly (see my above comments regarding sensor fusion and filtering), then give the Ziegler-Nichols tuning method a try:
- Set kP, kI, and kD to zero.
- Increase kP until the system achieves consistent oscillations.
- Record kP (as the "ultimate" gain, kU), and the oscillation period.
- Set kP, kI, and kD to values based on the ultimate gain and oscillation period.