Added tensorflow example to first order simulation.

This commit is contained in:
Andru Liu
2024-10-07 22:02:37 -07:00
parent d4820ceada
commit b501cf0bd1

View File

@@ -1,8 +1,11 @@
import matplotlib.pyplot as plt
import numpy as np
import tensorflow as tf
from RBF_numpy import RBFNetwork
from aPID import AdaptivePIDNP
from aPID_numpy import AdaptivePIDNP
from RBF_tf import RBFAdaptiveModel
from aPID_tf import AdaptivePIDTf
def simulate_system(controller, target, dt, T):
""" Simulate control model as first order system.
@@ -36,6 +39,7 @@ def simulate_system(controller, target, dt, T):
return time, measurements
if __name__ == "__main__":
# numpy implementation
np.random.seed(20)
rbf_np = RBFNetwork(input_dim=3, n_centers=5)
@@ -50,8 +54,27 @@ if __name__ == "__main__":
plt.axhline(y=target, color="r", linestyle="--", label="Target")
plt.xlabel("Time (s)")
plt.ylabel("Output")
plt.title("Adaptive RBF Neural PID Controller")
plt.title("Adaptive RBF Neural PID Controller Numpy")
plt.legend()
plt.grid()
plt.show()
# tensorflow implementation
rbf_tf = RBFAdaptiveModel(n_centers=5, input_dim=3)
rbf_tf.compile(optimizer="adam", loss="mean_squared_error")
apid_tf = AdaptivePIDTf(Kp=7.0, Ki=0.5, Kd=0.01, rbf_model=rbf_tf)
target = 1.0
dt = 0.1
T = 10.0
time, measurements = simulate_system(apid_tf, target, dt, T)
plt.plot(time, measurements, label="Measured Value")
plt.axhline(y=target, color="r", linestyle="--", label="Target")
plt.xlabel("Time (s)")
plt.ylabel("Output")
plt.title("Adaptive RBF Neural PID Controller TF")
plt.legend()
plt.grid()
plt.show()