@@ -543,13 +543,17 @@ def updateClosedLoop(self):
543543 kd = self .kd
544544 kff = self .kff
545545
546+ airspeed = 40.0
547+ airspeed_trim = 38.0
548+ airspeed_scale = airspeed_trim / airspeed
546549 delays = ctrl .TransferFunction ([1 ], np .append ([1 ], np .zeros (self .sys_id_delays )), dt , inputs = 'r' , outputs = 'rd' )
547550 plant = ctrl .TransferFunction (num , den , dt , inputs = 'u' , outputs = 'plant_out' )
548551 sampler = ctrl .TransferFunction ([1 ], [1 , 0 ], dt , inputs = 'plant_out' , outputs = 'y' )
549552 sum_feedback = ctrl .summing_junction (inputs = ['rd' , '-y' ], output = 'e' )
550553
551554 # Default is standard PID
552555 feedforward = ctrl .TransferFunction ([kff ], [1 ], dt , inputs = 'rd' , outputs = 'ff_out' )
556+ ff_scale = ctrl .TransferFunction ([airspeed_scale ], [1 ], inputs = 'ff_out' , outputs = 'ff_out_scaled' )
553557 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))
554558
555559 # Derivative with 1st order LPF (discretized using Euler method: s = (z-1)/dt)
@@ -561,7 +565,8 @@ def updateClosedLoop(self):
561565
562566 id_control = ctrl .summing_junction (inputs = ['e' , 'i_out' , 'd_out' ], output = 'id_out' )
563567 p_control = ctrl .TransferFunction ([kc ], [1 ], dt , inputs = 'id_out' , outputs = 'pid_out' )
564- sum_control = ctrl .summing_junction (inputs = ['pid_out' , 'ff_out' ], output = 'u' )
568+ pid_scale = ctrl .TransferFunction ([airspeed_scale ** 2 ], [1 ], inputs = 'pid_out' , outputs = 'pid_out_scaled' )
569+ sum_control = ctrl .summing_junction (inputs = ['pid_out_scaled' , 'ff_out_scaled' ], output = 'u' )
565570
566571 remove_zero = False
567572 no_derivative_kick = True
@@ -574,7 +579,7 @@ def updateClosedLoop(self):
574579 # Derivative on feedback only to remove the "derivative kick"
575580 d_control = ctrl .TransferFunction (- derivative_num , derivative_den , dt , inputs = 'y' , outputs = 'd_out' )
576581
577- closed_loop = ctrl .interconnect ([delays , sampler , sum_feedback , feedforward , sum_control , p_control , i_control , d_control , id_control , plant ], inputs = 'r' , outputs = 'y' )
582+ closed_loop = ctrl .interconnect ([delays , sampler , sum_feedback , feedforward , sum_control , p_control , i_control , d_control , id_control , pid_scale , ff_scale , plant ], inputs = 'r' , outputs = 'y' )
578583
579584 t_out ,y_out = ctrl .step_response (closed_loop , T = np .arange (0 ,1 ,dt ))
580585 self .plotClosedLoop (t_out , y_out )
0 commit comments