automation - My PID Controller in Java is not operating correctly -
i looking implementation of pid controller in java , found one:
so, understand using way:
package lol.feedback; public class dsfdsf { public static void main(string[] args) throws interruptedexception { final pidcontroller pidcontroller = new pidcontroller(1, 1, 1); pidcontroller.setinputrange(0, 200); // input limits pidcontroller.setoutputrange(50, 100); // output limits pidcontroller.setsetpoint(120); // target value (pid should minimize error between input , value) pidcontroller.enable(); double input = 0; double output = 0; while (true) { input = output + 30; pidcontroller.getinput(input); output = pidcontroller.performpid(); system.out.println("input: " + input + " | output: " + output + " | error: " + pidcontroller.geterror()); thread.sleep(1000); } } }
but never stabilizes. doesn't behave pid @ all... output get:
input: 30.0 | output: 100.0 | error: 90.0 input: 130.0 | output: 50.0 | error: -10.0 input: 80.0 | output: 100.0 | error: 40.0 input: 130.0 | output: 50.0 | error: -10.0 input: 80.0 | output: 100.0 | error: 40.0 input: 130.0 | output: 50.0 | error: -10.0 input: 80.0 | output: 100.0 | error: 40.0 input: 130.0 | output: 50.0 | error: -10.0 input: 80.0 | output: 100.0 | error: 40.0 input: 130.0 | output: 50.0 | error: -10.0 input: 80.0 | output: 100.0 | error: 40.0 input: 130.0 | output: 50.0 | error: -10.0 input: 80.0 | output: 100.0 | error: 40.0 input: 130.0 | output: 50.0 | error: -10.0 input: 80.0 | output: 100.0 | error: 40.0 input: 130.0 | output: 50.0 | error: -10.0 input: 80.0 | output: 100.0 | error: 40.0 input: 130.0 | output: 50.0 | error: -10.0 input: 80.0 | output: 100.0 | error: 40.0 input: 130.0 | output: 50.0 | error: -10.0 input: 80.0 | output: 100.0 | error: 40.0 input: 130.0 | output: 50.0 | error: -10.0 input: 80.0 | output: 100.0 | error: 40.0 input: 130.0 | output: 50.0 | error: -10.0 input: 80.0 | output: 100.0 | error: 40.0 input: 130.0 | output: 50.0 | error: -10.0 input: 80.0 | output: 100.0 | error: 40.0 input: 130.0 | output: 50.0 | error: -10.0 input: 80.0 | output: 100.0 | error: 40.0 input: 130.0 | output: 50.0 | error: -10.0 input: 80.0 | output: 100.0 | error: 40.0 input: 130.0 | output: 50.0 | error: -10.0 input: 80.0 | output: 100.0 | error: 40.0 input: 130.0 | output: 50.0 | error: -10.0 input: 80.0 | output: 100.0 | error: 40.0 input: 130.0 | output: 50.0 | error: -10.0 input: 80.0 | output: 100.0 | error: 40.0 input: 130.0 | output: 50.0 | error: -10.0 input: 80.0 | output: 100.0 | error: 40.0 input: 130.0 | output: 50.0 | error: -10.0 input: 80.0 | output: 100.0 | error: 40.0 input: 130.0 | output: 50.0 | error: -10.0 input: 80.0 | output: 100.0 | error: 40.0 input: 130.0 | output: 50.0 | error: -10.0 input: 80.0 | output: 100.0 | error: 40.0 input: 130.0 | output: 50.0 | error: -10.0 input: 80.0 | output: 100.0 | error: 40.0 input: 130.0 | output: 50.0 | error: -10.0 input: 80.0 | output: 100.0 | error: 40.0 input: 130.0 | output: 50.0 | error: -10.0 input: 80.0 | output: 100.0 | error: 40.0 input: 130.0 | output: 50.0 | error: -10.0 input: 80.0 | output: 100.0 | error: 40.0 input: 130.0 | output: 50.0 | error: -10.0 input: 80.0 | output: 100.0 | error: 40.0 input: 130.0 | output: 50.0 | error: -10.0 input: 80.0 | output: 100.0 | error: 40.0 input: 130.0 | output: 50.0 | error: -10.0 input: 80.0 | output: 100.0 | error: 40.0 input: 130.0 | output: 50.0 | error: -10.0 input: 80.0 | output: 100.0 | error: 40.0 input: 130.0 | output: 50.0 | error: -10.0 input: 80.0 | output: 100.0 | error: 40.0 input: 130.0 | output: 50.0 | error: -10.0 input: 80.0 | output: 100.0 | error: 40.0 input: 130.0 | output: 50.0 | error: -10.0 input: 80.0 | output: 100.0 | error: 40.0 input: 130.0 | output: 50.0 | error: -10.0 input: 80.0 | output: 100.0 | error: 40.0 input: 130.0 | output: 50.0 | error: -10.0 input: 80.0 | output: 100.0 | error: 40.0 input: 130.0 | output: 50.0 | error: -10.0 input: 80.0 | output: 100.0 | error: 40.0 input: 130.0 | output: 50.0 | error: -10.0 input: 80.0 | output: 100.0 | error: 40.0 input: 130.0 | output: 50.0 | error: -10.0 input: 80.0 | output: 100.0 | error: 40.0 input: 130.0 | output: 50.0 | error: -10.0 input: 80.0 | output: 100.0 | error: 40.0 input: 130.0 | output: 50.0 | error: -10.0 input: 80.0 | output: 100.0 | error: 40.0 input: 130.0 | output: 50.0 | error: -10.0 input: 80.0 | output: 100.0 | error: 40.0 input: 130.0 | output: 50.0 | error: -10.0 input: 80.0 | output: 100.0 | error: 40.0 input: 130.0 | output: 50.0 | error: -10.0 input: 80.0 | output: 100.0 | error: 40.0 input: 130.0 | output: 50.0 | error: -10.0 input: 80.0 | output: 100.0 | error: 40.0 input: 130.0 | output: 50.0 | error: -10.0 input: 80.0 | output: 100.0 | error: 40.0 input: 130.0 | output: 50.0 | error: -10.0
can me tell me missing?
thank you!
firstly, try set of pid parameters - example final pidcontroller pidcontroller = new pidcontroller(10, 1, 0.5); first parameter responsible gain of closed-loop system. second responsible eliminate fixed error on output. third responsible dynamic of control.
second thing - possible real signal output out of limit, takes minimum/maximum value.
thirdly, why add 30 output , assign input?