def pid_pg_comb(set_point, *, Kp, Ki, Kd, Nfilt, plant): pid = pidtf(Kp, Ki, Kd, Nfilt) plant_out = Intf(Float) pid_in = set_point - plant_out pid_out = pid_in \ | lti(name='pid', sys=pid, init_x=0) plant_out |= pid_out \ | lti(name='plant', sys=plant, init_x=0) return plant_out
def pid_lti_feedback(set_point, *, Kp, Ki, Kd, Nfilt, plant): pid = pidtf(Kp, Ki, Kd, Nfilt) plant = tf([1], [1, 10, 20]) sys = feedback(pid * plant) return set_point | lti(sys=sys, init_x=0)
def test_rc(): R = 100 C = 1e-6 clk_freq = 1e6 # Hz seq = [1] * 1000 + [0] * 1000 drv(t=Float, seq=seq) \ | lti(num=[1], den=[R*C, 1], init_x=0, clk_freq=clk_freq) \ | scope sim(timeout=len(seq))
def pid_lti_comb(set_point, *, Kp, Ki, Kd, Nfilt, plant): pid = pidtf(Kp, Ki, Kd, Nfilt) sys = plant * pid plant_out = Intf(Float) pid_in = set_point - plant_out plant_out |= pid_in \ | lti(sys=sys, init_x=0) \ return plant_out
def test_pid(): Kp = 350 Ki = 300 Kd = 50 clk_freq = 10 # Hz seq = [1.] * 500 + [0.] * 500 drv(t=Float, seq=seq) \ | lti(num=[Kd, Kp, Ki], den=[1, (10 + Kd), (20 + Kp), Ki], init_x=0, clk_freq=clk_freq) \ | scope sim(timeout=len(seq))
def hdl_pid_sys(set_point, *, Kp, Ki, Kd, plant): plant_out = Intf(Float) pid_in = set_point - plant_out pid_in | scope(title="PID Input") pid_in = pid_in | Fixp[2, 22] pid_out = pid_in | hdl_pid(Kp=Kp, Ki=Ki, Kd=Kd, sim_cls=SimVerilated) pid_out = pid_out | Float plant_out |= pid_out \ | lti(name='plant', sys=plant, init_x=0) return plant_out