@@ -549,29 +549,31 @@ def updateClosedLoop(self):
549549
550550 # Default is standard PID
551551 feedforward = ctrl .TransferFunction ([kff ], [1 ], dt , inputs = 'rd' , outputs = 'ff_out' )
552- 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: s = 2(z-1)/(dt(z+1))
552+ i_control = ctrl .TransferFunction ([ki * dt , ki * dt ], [2 , - 2 ], dt , inputs = 'e' , outputs = 'i_out' ) # Integrator discretized using bilinear transform: s = 2(z-1)/(dt(z+1))
554553
555554 # Derivative with 1st order LPF (discretized using Euler method: s = (z-1)/dt)
556555 derivative_cutoff_freq = 10.0 # Hz
557556 tau = 1 / (2 * np .pi * derivative_cutoff_freq )
558- derivative_num = np .array ([kc * kd , - kc * kd ])
557+ derivative_num = np .array ([kd , - kd ])
559558 derivative_den = np .array ([tau , - tau + dt ])
560559 d_control = ctrl .TransferFunction (derivative_num , derivative_den , dt , inputs = 'e' , outputs = 'd_out' )
561- sum_control = ctrl .summing_junction (inputs = ['ff_out' , 'p_out' , 'i_out' , 'd_out' ], output = 'u' )
560+
561+ id_control = ctrl .summing_junction (inputs = ['e' , 'i_out' , 'd_out' ], output = 'id_out' )
562+ p_control = ctrl .TransferFunction ([kc ], [1 ], dt , inputs = 'id_out' , outputs = 'pid_out' )
563+ sum_control = ctrl .summing_junction (inputs = ['pid_out' , 'ff_out' ], output = 'u' )
562564
563565 remove_zero = False
564566 no_derivative_kick = True
565567
566568 if remove_zero :
567569 # P on feedback only to remove zero (3-loop autopilot style)
568- p_control = ctrl .TransferFunction ([ - kc ], [ 1 ], dt , inputs = 'y' , outputs = 'p_out ' )
570+ id_control = ctrl .summing_junction ( inputs = [ '-y' , 'i_out' , 'd_out' ], output = 'id_out ' )
569571
570572 if no_derivative_kick :
571573 # Derivative on feedback only to remove the "derivative kick"
572574 d_control = ctrl .TransferFunction (- derivative_num , derivative_den , dt , inputs = 'y' , outputs = 'd_out' )
573575
574- closed_loop = ctrl .interconnect ([delays , sampler , sum_feedback , feedforward , sum_control , p_control , i_control , d_control , plant ], inputs = 'r' , outputs = 'y' )
576+ closed_loop = ctrl .interconnect ([delays , sampler , sum_feedback , feedforward , sum_control , p_control , i_control , d_control , id_control , plant ], inputs = 'r' , outputs = 'y' )
575577
576578 t_out ,y_out = ctrl .step_response (closed_loop , T = np .arange (0 ,1 ,dt ))
577579 self .plotClosedLoop (t_out , y_out )
0 commit comments