Skip to content

Commit

Permalink
Renaming q_lin to q_mpc
Browse files Browse the repository at this point in the history
  • Loading branch information
Federico-PizarroBejarano committed Oct 29, 2024
1 parent 27e0d41 commit 9bb7088
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
safety_filter: linear_mpsc
sf_config:
# LQR controller parameters
r_lin:
r_mpc:
- 0.1
q_lin:
q_mpc:
- 1
- 0.1
- 1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
safety_filter: linear_mpsc
sf_config:
# LQR controller parameters
r_lin:
r_mpc:
- 0.1
q_lin:
q_mpc:
- 1
- 0.1
- 1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
safety_filter: linear_mpsc
sf_config:
# LQR controller parameters
r_lin:
r_mpc:
- 0.1
q_lin:
q_mpc:
- 1
- 1
- 1
Expand Down
4 changes: 2 additions & 2 deletions examples/mpsc/config_overrides/cartpole/lqr_cartpole.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
algo: lqr
algo_config:
# Cost parameters
r_lin:
r_mpc:
- 0.1
q_lin:
q_mpc:
- 1
- 1
- 1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
safety_filter: linear_mpsc
sf_config:
# LQR controller parameters
r_lin:
r_mpc:
- 0.1
q_lin:
q_mpc:
- 1
- 1
- 1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
algo: lqr
algo_config:
# Cost parameters
r_lin:
r_mpc:
- 0.1
q_lin:
q_mpc:
- 1
- 1
- 1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
safety_filter: linear_mpsc
sf_config:
# LQR controller parameters
r_lin:
r_mpc:
- 0.1
q_lin:
q_mpc:
- 0.01
- 0.01
- 0.01
Expand Down
8 changes: 4 additions & 4 deletions safe_control_gym/safety_filters/mpsc/linear_mpsc.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class LINEAR_MPSC(MPSC):
def __init__(self,
env_func,
horizon: int = 10,
q_lin: list = None,
r_lin: list = None,
q_mpc: list = None,
r_mpc: list = None,
integration_algo: str = 'rk4',
n_samples: int = 600,
n_samples_terminal_set: int = 100,
Expand All @@ -51,7 +51,7 @@ def __init__(self,
Args:
env_func (partial gym.Env): Environment for the task.
horizon (int): The MPC horizon.
q_lin, r_lin (list): Q and R gain matrices for linear controller.
q_mpc, r_mpc (list): Q and R gain matrices for linear controller.
integration_algo (str): The algorithm used for integrating the dynamics,
either 'LTI', 'rk4', 'rk', or 'cvodes'.
n_samples (int): Number of samples to create W set.
Expand All @@ -71,7 +71,7 @@ def __init__(self,
if key != 'self' and key != 'kwargs' and '__' not in key:
self.__dict__[key] = value

super().__init__(env_func, horizon, q_lin, r_lin, integration_algo, warmstart, additional_constraints, use_terminal_set, cost_function, mpsc_cost_horizon, decay_factor, **kwargs)
super().__init__(env_func, horizon, q_mpc, r_mpc, integration_algo, warmstart, additional_constraints, use_terminal_set, cost_function, mpsc_cost_horizon, decay_factor, **kwargs)

self.terminal_set_verts = None

Expand Down
12 changes: 6 additions & 6 deletions safe_control_gym/safety_filters/mpsc/mpsc.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class MPSC(BaseSafetyFilter, ABC):
def __init__(self,
env_func,
horizon: int = 10,
q_lin: list = None,
r_lin: list = None,
q_mpc: list = None,
r_mpc: list = None,
integration_algo: str = 'rk4',
warmstart: bool = True,
additional_constraints: list = None,
Expand All @@ -44,7 +44,7 @@ def __init__(self,
Args:
env_func (partial BenchmarkEnv): Environment for the task.
horizon (int): The MPC horizon.
q_lin, r_lin (list): Q and R gain matrices for linear controller.
q_mpc, r_mpc (list): Q and R gain matrices for linear controller.
integration_algo (str): The algorithm used for integrating the dynamics,
either 'LTI', 'rk4', 'rk', or 'cvodes'.
warmstart (bool): If the previous MPC soln should be used to warmstart the next mpc step.
Expand Down Expand Up @@ -74,8 +74,8 @@ def __init__(self,
# Setup attributes.
self.reset()
self.dt = self.model.dt
self.Q = get_cost_weight_matrix(q_lin, self.model.nx)
self.R = get_cost_weight_matrix(r_lin, self.model.nu)
self.Q = get_cost_weight_matrix(q_mpc, self.model.nx)
self.R = get_cost_weight_matrix(r_mpc, self.model.nu)

self.X_EQ = np.zeros(self.model.nx)
self.U_EQ = self.model.U_EQ
Expand Down Expand Up @@ -244,7 +244,7 @@ def solve_acados_optimization(self,
try:
action = ocp_solver.solve_for_x0(x0_bar=obs)
self.cost_prev = ocp_solver.get_cost()
self.slack_prev = np.zeros((self.horizon, self.p))
self.slack_prev = np.zeros((self.horizon, self.model.nx + self.model.nu))
x_val = np.zeros((self.horizon + 1, self.model.nx))
u_val = np.zeros((self.horizon, self.model.nu))
for i in range(self.horizon):
Expand Down
4 changes: 2 additions & 2 deletions safe_control_gym/safety_filters/mpsc/mpsc.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# LQR controller parameters
r_lin:
r_mpc:
- 1.
q_lin:
q_mpc:
- 1.

# MPC Parameters
Expand Down
6 changes: 3 additions & 3 deletions safe_control_gym/safety_filters/mpsc/nl_mpsc.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class NL_MPSC(MPSC):
def __init__(self,
env_func,
horizon: int = 10,
q_lin: list = None,
r_lin: list = None,
q_mpc: list = None,
r_mpc: list = None,
integration_algo: str = 'rk4',
warmstart: bool = True,
additional_constraints: list = None,
Expand Down Expand Up @@ -66,7 +66,7 @@ def __init__(self,
'''

self.model_bias = None
super().__init__(env_func, horizon, q_lin, r_lin, integration_algo, warmstart, additional_constraints, use_terminal_set, cost_function, mpsc_cost_horizon, decay_factor, **kwargs)
super().__init__(env_func, horizon, q_mpc, r_mpc, integration_algo, warmstart, additional_constraints, use_terminal_set, cost_function, mpsc_cost_horizon, decay_factor, **kwargs)

self.n_samples = n_samples
self.soften_constraints = soften_constraints
Expand Down

0 comments on commit 9bb7088

Please sign in to comment.