Skip to content

Commit

Permalink
Fixing minor issue in MPSC and CBF
Browse files Browse the repository at this point in the history
  • Loading branch information
Federico-PizarroBejarano committed May 10, 2023
1 parent a7500bb commit 1645efd
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
7 changes: 4 additions & 3 deletions experiments/mpsc/mpsc_experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import numpy as np

from safe_control_gym.experiments.base_experiment import BaseExperiment
from safe_control_gym.experiments.base_experiment import BaseExperiment, MetricExtractor
from safe_control_gym.utils.registration import make
from safe_control_gym.utils.configuration import ConfigFactory
from safe_control_gym.envs.benchmark_env import Task, Cost, Environment
Expand Down Expand Up @@ -426,8 +426,9 @@ def run_multiple(plot=True):
all_uncert_results[key].append(uncert_results[key][0])
all_cert_results[key].append(cert_results[key][0])

uncert_metrics = BaseExperiment.compute_metrics(all_uncert_results)
cert_metrics = BaseExperiment.compute_metrics(all_cert_results)
met = MetricExtractor()
uncert_metrics = met.compute_metrics(data=all_uncert_results)
cert_metrics = met.compute_metrics(data=all_cert_results)

all_results = {'uncert_results': all_uncert_results,
'uncert_metrics': uncert_metrics,
Expand Down
2 changes: 2 additions & 0 deletions safe_control_gym/safety_filters/cbf/cbf.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,11 @@ def certify_action(self,
success (bool): Whether the safety filtering was successful or not.
'''

uncertified_action = np.clip(uncertified_action, self.env.physical_action_bounds[0], self.env.physical_action_bounds[1])
self.results_dict['uncertified_action'].append(uncertified_action)
certified_action, success = self.solve_optimization(current_state, uncertified_action)
self.results_dict['feasible'].append(success)
certified_action = np.squeeze(np.array(certified_action))
self.results_dict['certified_action'].append(certified_action)
self.results_dict['correction'].append(np.linalg.norm(certified_action - uncertified_action))

Expand Down
1 change: 1 addition & 0 deletions safe_control_gym/safety_filters/mpsc/mpsc.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ def certify_action(self,
success = False
certified_action = clipped_action

certified_action = np.squeeze(np.array(certified_action))
self.results_dict['kinf'].append(self.kinf)
self.results_dict['certified_action'].append(certified_action)
self.results_dict['correction'].append(np.linalg.norm(certified_action - uncertified_action))
Expand Down

0 comments on commit 1645efd

Please sign in to comment.