|
Re: arm-limitting gyro PD loop producing some strange results
I see three problems:
1) It IS positive feedback. You have error = desired - actual. Therefore, your arm PWM should be pwm_temp = pwm_temp + 0.01*p + 0*d (not -0.01*P etc.). By subtracting the control terms, you are turning your loop back into a positive feedback loop.
2) Your derivative will not work. You must declare error_old to be static or else the value will be lost every time the function ends. You should also initialize it to zero to avoid strange behavior in the first loop. Declare it as: static float error_old = 0;
3) You control gains are set such that the controller does nothing. Your desired desired angular rate is limited to +/- 30 deg/sec. Your actual is limited to +/- 75 deg/sec. The most error you can ever achieve is 105 deg/s For example:
let desired_rate = 30
let actual_rate = -75
this implies: error_new = 105
thus, pwm_temp = 127 + 0.01*105 = 128.05
when you type cast that to an int, it becomes 128. Therefore, the most your controller can output is 1 count worth of PWM. The Victor 884 has a +/- 10 count deadzone. Therefore, your controller is doing nothing.
You should at least guarantee full PWM ouput over your control range. Therefore, 105 deg/sec error should result in at least 127 counts of PWM output. Therfore, the minimum your gain should be is 127/105 which equals 1.21. Using 0.01 for the control gain isn't nearly enough.
Other helpful notes:
1) you probably won't need derivative control. The angular rate sensor signal is pretty noisy so the derivative is not very reliable. If you do need D control, filter the angular rate signal (with a low-pass filter) before you take the derivative.
2) Don't expect your arm to be stationary (unless it is driven by a non-backdrivable motor OR you're using dynamic braking). Since there is no integral control you can expect your arm to move slowly due to gravity when you're not touching the joysticks. Integral control will eliminate that.
__________________
-
An ounce of perception is worth a pound of obscure.
|