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]
# Note: Semantic Versioning is used: https://semver.org/
version = "0.9.41"
version = "0.9.42"
# Description
title = "ORBIT framework for Robot Learning"
......
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)
~~~~~~~~~~~~~~~~~~~
......
......@@ -78,21 +78,21 @@ class ActuatorBase(ABC):
# parse joint stiffness and damping
# -- stiffness
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
self.stiffness[:] = self.cfg.stiffness
self.stiffness[:] = float(self.cfg.stiffness)
else:
# if dict, then parse the regular expression
indices, _, values = string_utils.resolve_matching_names_values(self.cfg.stiffness, self.joint_names)
self.stiffness[:, indices] = torch.tensor(values, device=self._device)
# -- damping
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
self.damping[:] = self.cfg.damping
self.damping[:] = float(self.cfg.damping)
else:
# 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)
def __str__(self) -> str:
......
......@@ -72,8 +72,8 @@ class JointAction(ActionTerm):
self._processed_actions = torch.zeros_like(self.raw_actions)
# parse scale
if isinstance(cfg.scale, float):
self._scale = cfg.scale
if isinstance(cfg.scale, (float, int)):
self._scale = float(cfg.scale)
elif isinstance(cfg.scale, dict):
self._scale = torch.ones(1.0, self.action_dim, device=self.device)
# resolve the dictionary config
......@@ -82,8 +82,8 @@ class JointAction(ActionTerm):
else:
raise ValueError(f"Unsupported scale type: {type(cfg.scale)}")
# parse offset
if isinstance(cfg.offset, float):
self._offset = cfg.offset
if isinstance(cfg.offset, (float, int)):
self._offset = float(cfg.offset)
elif isinstance(cfg.offset, dict):
self._offset = torch.zeros_like(self._raw_actions)
# 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