diff --git a/src/rl_sar/library/rl_sdk/rl_sdk.cpp b/src/rl_sar/library/rl_sdk/rl_sdk.cpp index 78a9bd8..c374f71 100644 --- a/src/rl_sar/library/rl_sdk/rl_sdk.cpp +++ b/src/rl_sar/library/rl_sdk/rl_sdk.cpp @@ -397,8 +397,16 @@ void RL::ReadYaml(std::string robot_name) this->params.num_observations = config["num_observations"].as(); this->params.observations = ReadVectorFromYaml(config["observations"]); this->params.clip_obs = config["clip_obs"].as(); - this->params.clip_actions_upper = torch::tensor(ReadVectorFromYaml(config["clip_actions_upper"], this->params.framework, rows, cols)).view({1, -1}); - this->params.clip_actions_lower = torch::tensor(ReadVectorFromYaml(config["clip_actions_lower"], this->params.framework, rows, cols)).view({1, -1}); + if(config["clip_actions_lower"] && config["clip_actions_upper"]) + { + this->params.clip_actions_upper = torch::tensor(ReadVectorFromYaml(config["clip_actions_upper"], this->params.framework, rows, cols)).view({1, -1}); + this->params.clip_actions_lower = torch::tensor(ReadVectorFromYaml(config["clip_actions_lower"], this->params.framework, rows, cols)).view({1, -1}); + } + else + { + this->params.clip_actions_upper = torch::tensor({}).view({1, -1}); + this->params.clip_actions_lower = torch::tensor({}).view({1, -1}); + } this->params.action_scale = config["action_scale"].as(); this->params.hip_scale_reduction = config["hip_scale_reduction"].as(); this->params.hip_scale_reduction_indices = ReadVectorFromYaml(config["hip_scale_reduction_indices"]); diff --git a/src/rl_sar/scripts/rl_sdk.py b/src/rl_sar/scripts/rl_sdk.py index 69556b5..bfa4946 100644 --- a/src/rl_sar/scripts/rl_sdk.py +++ b/src/rl_sar/scripts/rl_sdk.py @@ -387,8 +387,12 @@ def ReadYaml(self, robot_name): self.params.action_scale = config["action_scale"] self.params.hip_scale_reduction = config["hip_scale_reduction"] self.params.hip_scale_reduction_indices = config["hip_scale_reduction_indices"] - self.params.clip_actions_upper = torch.tensor(self.ReadVectorFromYaml(config["clip_actions_upper"], self.params.framework, rows, cols)).view(1, -1) - self.params.clip_actions_lower = torch.tensor(self.ReadVectorFromYaml(config["clip_actions_lower"], self.params.framework, rows, cols)).view(1, -1) + if config["clip_actions_upper"] and config["clip_actions_upper"]: + self.params.clip_actions_upper = torch.tensor(self.ReadVectorFromYaml(config["clip_actions_upper"], self.params.framework, rows, cols)).view(1, -1) + self.params.clip_actions_lower = torch.tensor(self.ReadVectorFromYaml(config["clip_actions_lower"], self.params.framework, rows, cols)).view(1, -1) + else: + self.params.clip_actions_upper = None + self.params.clip_actions_lower = None self.params.num_of_dofs = config["num_of_dofs"] self.params.lin_vel_scale = config["lin_vel_scale"] self.params.ang_vel_scale = config["ang_vel_scale"] diff --git a/src/rl_sar/scripts/rl_sim.py b/src/rl_sar/scripts/rl_sim.py index f9fde79..22803ac 100644 --- a/src/rl_sar/scripts/rl_sim.py +++ b/src/rl_sar/scripts/rl_sim.py @@ -208,8 +208,10 @@ def Forward(self): actions = self.model.forward(history_obs) else: actions = self.model.forward(clamped_obs) - clamped_actions = torch.clamp(actions, self.params.clip_actions_lower, self.params.clip_actions_upper) - return clamped_actions + if self.params.clip_actions_lower is not None and self.params.clip_actions_upper is not None: + return torch.clamp(actions, self.params.clip_actions_lower, self.params.clip_actions_upper) + else: + return actions def ThreadControl(self): thread_period = self.params.dt diff --git a/src/rl_sar/src/rl_real_a1.cpp b/src/rl_sar/src/rl_real_a1.cpp index 4a9f98f..6d6c57e 100644 --- a/src/rl_sar/src/rl_real_a1.cpp +++ b/src/rl_sar/src/rl_real_a1.cpp @@ -181,9 +181,14 @@ torch::Tensor RL_Real::Forward() torch::Tensor actions = this->model.forward({this->history_obs}).toTensor(); - torch::Tensor clamped_actions = torch::clamp(actions, this->params.clip_actions_lower, this->params.clip_actions_upper); - - return clamped_actions; + if(this->params.clip_actions_upper.numel() != 0 && this->params.clip_actions_lower.numel() != 0) + { + return torch::clamp(actions, this->params.clip_actions_lower, this->params.clip_actions_upper); + } + else + { + return actions; + } } void RL_Real::Plot() diff --git a/src/rl_sar/src/rl_sim.cpp b/src/rl_sar/src/rl_sim.cpp index fd3ea09..2b06672 100644 --- a/src/rl_sar/src/rl_sim.cpp +++ b/src/rl_sar/src/rl_sim.cpp @@ -259,8 +259,14 @@ torch::Tensor RL_Sim::Forward() actions = this->model.forward({clamped_obs}).toTensor(); } - torch::Tensor clamped_actions = torch::clamp(actions, this->params.clip_actions_lower, this->params.clip_actions_upper); - return clamped_actions; + if(this->params.clip_actions_upper.numel() != 0 && this->params.clip_actions_lower.numel() != 0) + { + return torch::clamp(actions, this->params.clip_actions_lower, this->params.clip_actions_upper); + } + else + { + return actions; + } } void RL_Sim::Plot()