I'd like to see your code @kakou19.
I apologize that it is difficult to understand. I'm sorry, I can see why. Maybe I shouldn't have included the PID example first. Can we discuss my code instead of the theoretical example?
int ft, wasft, gain, wasthrottle, dt;
ft=get_altitude();
set_throttle((wasft-ft)*gain+wasthrottle); //gain is Kp
wasft=ft;
delay(dt);
Let me define my variables:
ft is altitude in feet from BMP085 sensor.
wasft is last time around loop
wasthrottle is last time around 1000-2000us
gain is usually about 10
dt is around 500ms
It's better than the example because I implemented it in the real world with a sensor and servos instead of just unitless theory.
The sampling rate would need to be higher if I wanted it to stay level, but the KK board is already doing that. The temp comp is already handled by my sensor on board. An Accelerometer doesn't help much with altitude only leveling? I'm not sure how sampling the barometer at 50hz would help since it's usually the same reading for many seconds. The code I listed is complete for altitude hold except obviously get_altitude() and set_throttle() which do exactly what they say. set_throttle sends the specified parameter to the throttle input of the KK board. I'm not sure if filtering the sensor would help because it is already clean data. It stays at the same value 99% of the time when it's not moving. Every once in awhile it'll tick up or down 1ft. Over time it will change as the weather changes but that is not relevant here. I appreciate your input which makes me think of things I haven't considered yet. Please continue. I encourage you to disagree that's how we learn.