PID controller in max?

    Jun 01 2011 | 10:39 pm
    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!

    • Jun 01 2011 | 11:50 pm
      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
    • Jun 02 2011 | 4:10 pm
      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
    • Jun 03 2011 | 11:59 pm
      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!
    • Jun 06 2011 | 5:35 pm
      Thanks! I'll give this a try!
    • Jun 06 2011 | 11:05 pm
      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 :)
    • Mar 10 2013 | 3:54 pm
      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.