From edcb2b87cd14e28eab485eb82644e36b0c899c3e Mon Sep 17 00:00:00 2001 From: Tue Herlau <tuhe@dtu.dk> Date: Thu, 13 Mar 2025 15:25:17 +0100 Subject: [PATCH] More solutions files --- solutions/ex06/boeing_lqr_TODO_1.py | 1 + solutions/ex06/boeing_lqr_TODO_2.py | 1 + solutions/ex06/boeing_lqr_TODO_3.py | 3 +++ solutions/ex06/boeing_lqr_TODO_4.py | 2 ++ solutions/ex06/dlqr_TODO_1.py | 2 ++ solutions/ex06/dlqr_TODO_2.py | 1 + solutions/ex06/dlqr_TODO_3.py | 4 ++++ solutions/ex06/lqr_agent_TODO_1.py | 1 + solutions/ex06/lqr_agent_TODO_2.py | 1 + solutions/ex06/lqr_pid_TODO_1.py | 3 +++ solutions/ex06/lqr_pid_TODO_2.py | 1 + 11 files changed, 20 insertions(+) create mode 100644 solutions/ex06/boeing_lqr_TODO_1.py create mode 100644 solutions/ex06/boeing_lqr_TODO_2.py create mode 100644 solutions/ex06/boeing_lqr_TODO_3.py create mode 100644 solutions/ex06/boeing_lqr_TODO_4.py create mode 100644 solutions/ex06/dlqr_TODO_1.py create mode 100644 solutions/ex06/dlqr_TODO_2.py create mode 100644 solutions/ex06/dlqr_TODO_3.py create mode 100644 solutions/ex06/lqr_agent_TODO_1.py create mode 100644 solutions/ex06/lqr_agent_TODO_2.py create mode 100644 solutions/ex06/lqr_pid_TODO_1.py create mode 100644 solutions/ex06/lqr_pid_TODO_2.py diff --git a/solutions/ex06/boeing_lqr_TODO_1.py b/solutions/ex06/boeing_lqr_TODO_1.py new file mode 100644 index 0000000..649101b --- /dev/null +++ b/solutions/ex06/boeing_lqr_TODO_1.py @@ -0,0 +1 @@ + Q, R, q = compute_Q_R_q(model, dt) \ No newline at end of file diff --git a/solutions/ex06/boeing_lqr_TODO_2.py b/solutions/ex06/boeing_lqr_TODO_2.py new file mode 100644 index 0000000..ba3dbc6 --- /dev/null +++ b/solutions/ex06/boeing_lqr_TODO_2.py @@ -0,0 +1 @@ + agent = LQRAgent(env, A=A, B=B, d=d, Q=Q, R=R, q=q) \ No newline at end of file diff --git a/solutions/ex06/boeing_lqr_TODO_3.py b/solutions/ex06/boeing_lqr_TODO_3.py new file mode 100644 index 0000000..e5328ff --- /dev/null +++ b/solutions/ex06/boeing_lqr_TODO_3.py @@ -0,0 +1,3 @@ + Q = cost.Q * dt + R = cost.R * dt + q = cost.q * dt \ No newline at end of file diff --git a/solutions/ex06/boeing_lqr_TODO_4.py b/solutions/ex06/boeing_lqr_TODO_4.py new file mode 100644 index 0000000..5100172 --- /dev/null +++ b/solutions/ex06/boeing_lqr_TODO_4.py @@ -0,0 +1,2 @@ + B_discrete = scipy.linalg.inv(model.A) @ (A_discrete - np.eye(model.A.shape[0])) @ model.B + d_discrete = scipy.linalg.inv(model.A) @ (A_discrete - np.eye(model.A.shape[0])) @ d \ No newline at end of file diff --git a/solutions/ex06/dlqr_TODO_1.py b/solutions/ex06/dlqr_TODO_1.py new file mode 100644 index 0000000..7615471 --- /dev/null +++ b/solutions/ex06/dlqr_TODO_1.py @@ -0,0 +1,2 @@ +import matplotlib +matplotlib.use('agg') \ No newline at end of file diff --git a/solutions/ex06/dlqr_TODO_2.py b/solutions/ex06/dlqr_TODO_2.py new file mode 100644 index 0000000..f34eec8 --- /dev/null +++ b/solutions/ex06/dlqr_TODO_2.py @@ -0,0 +1 @@ + V[N], v[N], vc[N] = QN, qN, qcN \ No newline at end of file diff --git a/solutions/ex06/dlqr_TODO_3.py b/solutions/ex06/dlqr_TODO_3.py new file mode 100644 index 0000000..14bb8ad --- /dev/null +++ b/solutions/ex06/dlqr_TODO_3.py @@ -0,0 +1,4 @@ + Suu = R[k] + B[k].T @ (V[k+1] + mu * In) @ B[k] + Sux = H[k] + B[k].T @ (V[k+1] + mu * In) @ A[k] + Su = r[k] + B[k].T @ v[k + 1] + B[k].T @ V[k + 1] @ d[k] + L[k] = -np.linalg.solve(Suu, Sux) \ No newline at end of file diff --git a/solutions/ex06/lqr_agent_TODO_1.py b/solutions/ex06/lqr_agent_TODO_1.py new file mode 100644 index 0000000..f82d69e --- /dev/null +++ b/solutions/ex06/lqr_agent_TODO_1.py @@ -0,0 +1 @@ + (self.L, self.l), _ = LQR(A=[A]*N, B=[B]*N, d=[d]*N if d is not None else None, Q=[Q]*N, q=[q]*N if q is not None else None, R=[R]*N) \ No newline at end of file diff --git a/solutions/ex06/lqr_agent_TODO_2.py b/solutions/ex06/lqr_agent_TODO_2.py new file mode 100644 index 0000000..e8994b0 --- /dev/null +++ b/solutions/ex06/lqr_agent_TODO_2.py @@ -0,0 +1 @@ + u = self.L[k] @ x + self.l[k] \ No newline at end of file diff --git a/solutions/ex06/lqr_pid_TODO_1.py b/solutions/ex06/lqr_pid_TODO_1.py new file mode 100644 index 0000000..920d0e7 --- /dev/null +++ b/solutions/ex06/lqr_pid_TODO_1.py @@ -0,0 +1,3 @@ + def pi(self,x, k, info=None): + action = self.L[0] @ x + self.l[0] + return action \ No newline at end of file diff --git a/solutions/ex06/lqr_pid_TODO_2.py b/solutions/ex06/lqr_pid_TODO_2.py new file mode 100644 index 0000000..2f1ad2a --- /dev/null +++ b/solutions/ex06/lqr_pid_TODO_2.py @@ -0,0 +1 @@ + Kp, Kd = (-L0).flat \ No newline at end of file -- GitLab