Skip to content

Commit

Permalink
Minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Federico-PizarroBejarano committed Dec 6, 2024
1 parent 7c43d8a commit 076393f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
safety_filter: nl_mpsc
safety_filter: mpsc_acados
sf_config:
# LQR controller parameters
q_mpc: [18, 0.1, 18, 0.5, 0.5, 0.0001]
Expand Down
18 changes: 10 additions & 8 deletions safe_control_gym/controllers/ppo/ppo.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def __init__(self,
self.sf_penalty = 1
self.use_safe_reset = False
super().__init__(env_func, training, checkpoint_path, output_dir, use_gpu, seed, **kwargs)

# Task.
if self.training:
# Training and testing.
Expand Down Expand Up @@ -237,14 +238,15 @@ def run(self,
action = self.select_action(obs=obs, info=info)

# Adding safety filter
success = False
physical_action = env.denormalize_action(action)
unextended_obs = np.squeeze(true_obs)[:env.symbolic.nx]
certified_action, success = self.safety_filter.certify_action(unextended_obs, physical_action, info)
if success:
action = env.normalize_action(certified_action)
else:
self.safety_filter.ocp_solver.reset()
if self.safety_filter is not None:
success = False
physical_action = env.denormalize_action(action)
unextended_obs = np.squeeze(true_obs)[:env.symbolic.nx]
certified_action, success = self.safety_filter.certify_action(unextended_obs, physical_action, info)
if success:
action = env.normalize_action(certified_action)
else:
self.safety_filter.ocp_solver.reset()

action = np.atleast_2d(np.squeeze([action]))
obs, rew, done, info = env.step(action)
Expand Down

0 comments on commit 076393f

Please sign in to comment.