Forums > MaxMSP

PID controller in max?

Jun 01 2011 | 10:39 pm

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?

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
error = setpoint – actual_position
integral = integral + (error*dt)
derivative = (error – previous_error)/dt
output = (Kp*error) + (Ki*integral) + (Kd*derivative)
previous_error = error
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.

— Pasted Max Patch, click to expand. —

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.


Viewing 7 posts - 1 through 7 (of 7 total)

Forums > MaxMSP