PID controller in max?
Hi!
I'm trying to control a remote controlled helicopter with max. Tracking with a camera works and sending new coordinates works but the helicopter always overshoots and ends up circling around the target destination. so I was wondering if anybody had implemented a PID controller in Max?
Thanks!
PID eh, that takes me back.... Haven't touched that since toying with vacuum furnace temperature controls! I think I still remember the maths behind them, simple JS code too I reckon. I'll see what I can come up with
according to wikipedia, the pseudocode for a PID looks like that, not sure how to implement it tough:
previous_error = setpoint - actual_position
integral = 0
start:
error = setpoint - actual_position
integral = integral + (error*dt)
derivative = (error - previous_error)/dt
output = (Kp*error) + (Ki*integral) + (Kd*derivative)
previous_error = error
wait(dt)
goto start
Yeah that's pretty much the form. Try this on for size - I've just fed the output into an accumulator to drive the *actualposition* value for test purposes though how you're choosing to use the error output is down to you. The JS code is attached to a comment box.
I'd like to see if anyone else has any suggestions or improvements to this or my JS coding purely for my own learning benefit!
Thanks! I'll give this a try!
Just so you know, I encountered a few initialisation problems where the numbers started coming out of the JS waaaaay too big and causing errors elsewhere - can be rectified by carefully initialising the patch. It does work though :)
Hi Hugobox, did you fix your problem ?
I'm looking for a subpatch for a PID thing to control a position of a motor, and 'im not very good with math, the equation PID is very complicated for me...
Have you something working ?
Regards, thanks.
Strophe.