@@ -550,8 +550,14 @@ def updateClosedLoop(self):
550550 # Default is standard PID
551551 feedforward = ctrl .TransferFunction ([kff ], [1 ], dt , inputs = 'rd' , outputs = 'ff_out' )
552552 p_control = ctrl .TransferFunction ([kc ], [1 ], dt , inputs = 'e' , outputs = 'p_out' )
553- i_control = ctrl .TransferFunction ([kc * ki * dt , kc * ki * dt ], [2 , - 2 ], dt , inputs = 'e' , outputs = 'i_out' ) # Integrator discretized using bilinear transform
554- d_control = ctrl .TransferFunction ([2 * kc * kd , - 2 * kc * kd ], [dt , dt ], dt , inputs = 'e' , outputs = 'd_out' )
553+ i_control = ctrl .TransferFunction ([kc * ki * dt , kc * ki * dt ], [2 , - 2 ], dt , inputs = 'e' , outputs = 'i_out' ) # Integrator discretized using bilinear transform: s = 2(z-1)/(dt(z+1))
554+
555+ # Derivative with 1st order LPF (discretized using Euler method: s = (z-1)/dt)
556+ derivative_cutoff_freq = 10.0 # Hz
557+ tau = 1 / (2 * np .pi * derivative_cutoff_freq )
558+ derivative_num = np .array ([kc * kd , - kc * kd ])
559+ derivative_den = np .array ([tau , - tau + dt ])
560+ d_control = ctrl .TransferFunction (derivative_num , derivative_den , dt , inputs = 'e' , outputs = 'd_out' )
555561 sum_control = ctrl .summing_junction (inputs = ['ff_out' , 'p_out' , 'i_out' , 'd_out' ], output = 'u' )
556562
557563 remove_zero = False
@@ -563,7 +569,7 @@ def updateClosedLoop(self):
563569
564570 if no_derivative_kick :
565571 # Derivative on feedback only to remove the "derivative kick"
566- d_control = ctrl .TransferFunction ([ - 2 * kc * kd , 2 * kc * kd ], [ dt , dt ] , dt , inputs = 'y' , outputs = 'd_out' )
572+ d_control = ctrl .TransferFunction (- derivative_num , derivative_den , dt , inputs = 'y' , outputs = 'd_out' )
567573
568574 closed_loop = ctrl .interconnect ([delays , sampler , sum_feedback , feedforward , sum_control , p_control , i_control , d_control , plant ], inputs = 'r' , outputs = 'y' )
569575
0 commit comments