PID controller in max?

    MaxMSP

    Hugobox's icon
    Hugobox's icon
    Hugobox
    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!

    • mr_mapes's icon
      mr_mapes's icon
      mr_mapes
      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
      Share
    • Hugobox's icon
      Hugobox's icon
      Hugobox
      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
    • mr_mapes's icon
      mr_mapes's icon
      mr_mapes
      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.
      Max Patcher
      In Max, select New From Clipboard.
      Show Text
      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!
    • Hugobox's icon
      Hugobox's icon
      Hugobox
      Jun 06 2011 | 5:35 pm
      Thanks! I'll give this a try!
    • mr_mapes's icon
      mr_mapes's icon
      mr_mapes
      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 :)
    • Strophe's icon
      Strophe's icon
      Strophe
      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.
      Strophe.