Unverified Commit b8222335 authored by Mayank Mittal's avatar Mayank Mittal Committed by GitHub

Fixes parsing of damping configuration in ActuatorBase (#247)

# Description

Previously, there was a bug that was setting stiffness to damping values
when configuration was passed as dictionaries. This MR fixes this issue.

## Type of change

- Bug fix (non-breaking change which fixes an issue)

## Checklist

- [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with
`./orbit.sh --format`
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [x] I have updated the changelog and the corresponding version in the
extension's `config/extension.toml` file
- [x] I have added my name to the `CONTRIBUTORS.md` or my name already
exists there
parent 46f1d976
[package] [package]
# Note: Semantic Versioning is used: https://semver.org/ # Note: Semantic Versioning is used: https://semver.org/
version = "0.9.41" version = "0.9.42"
# Description # Description
title = "ORBIT framework for Robot Learning" title = "ORBIT framework for Robot Learning"
......
Changelog Changelog
--------- ---------
0.9.42 (2023-11-16)
~~~~~~~~~~~~~~~~~~~
Fixed
^^^^^
* Fixed setting of damping values from the configuration for :class:`ActuatorBase` class. Earlier,
the stiffness values were being set into damping when a dictionary configuration was passed to the
actuator model.
* Added dealing with :class:`int` and :class:`float` values in the configurations of :class:`ActuatorBase`.
Earlier, a type-error was thrown when integer values were passed to the actuator model.
0.9.41 (2023-11-16) 0.9.41 (2023-11-16)
~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~
......
...@@ -78,21 +78,21 @@ class ActuatorBase(ABC): ...@@ -78,21 +78,21 @@ class ActuatorBase(ABC):
# parse joint stiffness and damping # parse joint stiffness and damping
# -- stiffness # -- stiffness
if self.cfg.stiffness is not None: if self.cfg.stiffness is not None:
if isinstance(self.cfg.stiffness, float): if isinstance(self.cfg.stiffness, (float, int)):
# if float, then use the same value for all joints # if float, then use the same value for all joints
self.stiffness[:] = self.cfg.stiffness self.stiffness[:] = float(self.cfg.stiffness)
else: else:
# if dict, then parse the regular expression # if dict, then parse the regular expression
indices, _, values = string_utils.resolve_matching_names_values(self.cfg.stiffness, self.joint_names) indices, _, values = string_utils.resolve_matching_names_values(self.cfg.stiffness, self.joint_names)
self.stiffness[:, indices] = torch.tensor(values, device=self._device) self.stiffness[:, indices] = torch.tensor(values, device=self._device)
# -- damping # -- damping
if self.cfg.damping is not None: if self.cfg.damping is not None:
if isinstance(self.cfg.damping, float): if isinstance(self.cfg.damping, (float, int)):
# if float, then use the same value for all joints # if float, then use the same value for all joints
self.damping[:] = self.cfg.damping self.damping[:] = float(self.cfg.damping)
else: else:
# if dict, then parse the regular expression # if dict, then parse the regular expression
indices, _, values = string_utils.resolve_matching_names_values(self.cfg.stiffness, self.joint_names) indices, _, values = string_utils.resolve_matching_names_values(self.cfg.damping, self.joint_names)
self.damping[:, indices] = torch.tensor(values, device=self._device) self.damping[:, indices] = torch.tensor(values, device=self._device)
def __str__(self) -> str: def __str__(self) -> str:
......
...@@ -72,8 +72,8 @@ class JointAction(ActionTerm): ...@@ -72,8 +72,8 @@ class JointAction(ActionTerm):
self._processed_actions = torch.zeros_like(self.raw_actions) self._processed_actions = torch.zeros_like(self.raw_actions)
# parse scale # parse scale
if isinstance(cfg.scale, float): if isinstance(cfg.scale, (float, int)):
self._scale = cfg.scale self._scale = float(cfg.scale)
elif isinstance(cfg.scale, dict): elif isinstance(cfg.scale, dict):
self._scale = torch.ones(1.0, self.action_dim, device=self.device) self._scale = torch.ones(1.0, self.action_dim, device=self.device)
# resolve the dictionary config # resolve the dictionary config
...@@ -82,8 +82,8 @@ class JointAction(ActionTerm): ...@@ -82,8 +82,8 @@ class JointAction(ActionTerm):
else: else:
raise ValueError(f"Unsupported scale type: {type(cfg.scale)}") raise ValueError(f"Unsupported scale type: {type(cfg.scale)}")
# parse offset # parse offset
if isinstance(cfg.offset, float): if isinstance(cfg.offset, (float, int)):
self._offset = cfg.offset self._offset = float(cfg.offset)
elif isinstance(cfg.offset, dict): elif isinstance(cfg.offset, dict):
self._offset = torch.zeros_like(self._raw_actions) self._offset = torch.zeros_like(self._raw_actions)
# resolve the dictionary config # resolve the dictionary config
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment