Skip to content

Commit

Permalink
Safety in RL #101 started with condensed matrices
Browse files Browse the repository at this point in the history
  • Loading branch information
Webbah committed Jul 13, 2023
1 parent 290288e commit 557c32c
Showing 1 changed file with 134 additions and 0 deletions.
134 changes: 134 additions & 0 deletions examples/scripts/Safeguard_test.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
using ElectricGrid

CM = [ 0. 0. 1.
0. 0. 2.
-1. -2. 0.]

#R_load, L_load, _, _ = ParallelLoadImpedance(50e3, 0.95, 230)

parameters =
Dict{Any, Any}(
"source" => Any[
Dict{Any, Any}(
"pwr" => 200e3,
"fltr" => "LCL",
"L1" => 70e-6,
"R1" => 1.1e-3,
"C" => 300e-6,
"R_C" => 7e-3,
"control_type" => "classic",
"mode" => "Droop",),
],
"load" => Any[
Dict{Any, Any}(
"impedance" => "R",
"R" => 100,
"v_limit" => 1e4,
"i_limit" => 1e4)
],
"grid" => Dict{Any, Any}(
"phase" => 1,
"ramp_end" => 0.04,)
)



env = ElectricGridEnv(
#CM = CM,
parameters = parameters,
t_end = 1,
action_delay = 0,
verbosity = 0)


env.A

#= To exclude the cable C from matrix and conpare result with matlab:
- LCL filter, only use LC (not 2nd L) for SG calculation, since we have no cable in matlab
- Matrix look to be the same -> A_P10
- Caculate condensed system A_N and B_N
- Same?
- Calcuate G and E,...
- Same?
- Calcuate Polyhedron
- Same?
- Use it to ensure safety
=#

A_P10 = env.A[1:2,1:2]
B_P10 = env.B[1:2]

W_u = [-1; 1]
omega_u = [
env.nc.parameters["source"][1]["vdc"];
env.nc.parameters["source"][1]["vdc"]
]


W_x = [
-1 0;
1 0;
0 -1
0 1
]

omega_x = [
env.nc.parameters["source"][1]["i_limit"];
env.nc.parameters["source"][1]["i_limit"];
env.nc.parameters["source"][1]["v_limit"];
env.nc.parameters["source"][1]["v_limit"]
]

A_sqare = A_P10^2

N = 4 # maximum number of iteration

m = 1 # number of inputs to the system,
n = size(B_P10)[1]
#TODO: get from B -> here has (2,) dim and not (2,1), why?
# better: (n, m) = size(B_P10)

global A_N = 1* Matrix(I, size(A_P10)[1], size(A_P10)[1])
global B_N = zeros(n, m*N)

for ii = 1:N

global A_N = [A_N; A_P10^ii]



B_N_newline = A_P10^(ii-1)*B_P10
println("First:")
println(B_N_newline)
println("")

for jj in 2:ii
println("First:")
println(A_P10^(ii-jj)*B_P10)
println("")
B_N_newline = hcat(B_N_newline, A_P10^(ii-jj)*B_P10)

println("")
println(jj)
println("")
println(B_N_newline)
println("")
end
B_N_newline = hcat(B_N_newline, zeros(n, m*(N-ii)))
println("Last:")
println(B_N_newline)
println("")



global B_N = [B_N; B_N_newline]



end

println("")
println(A_N)
println("")
println(B_N)
println("")

0 comments on commit 557c32c

Please sign in to comment.