Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify damping task and remove its lm_damping parameter #108

Merged
merged 2 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ All notable changes to this project will be documented in this file.

### Changed

- **Breaking:** remove ``lm_damping`` parameter from DampingTask where it wasn't used
- CICD: Update ruff to 0.4.3
- Configuration accepts list of Control Barrier Functions
- DampingTask: Simplify implementation
- Update to Pinocchio 3 with 2.7 backward compatibility

### Fixed
Expand Down
44 changes: 9 additions & 35 deletions pink/tasks/damping_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,70 +7,44 @@
"""Damping task."""

import numpy as np
import pinocchio as pin

from ..configuration import Configuration
from ..utils import get_root_joint_dim
from .posture_task import PostureTask


class DampingTask(PostureTask):
r"""Minimize joint velocities.

The word "damping" is used here by analogy with forces that fight against
motion, and bring the robot to a rest if nothing else drives it.
The damping task minimizes :math:`\| v \|` with :math:`v` the velocity
output of the differential IK. The word "damping" is used here by analogy
with forces that fight against motion, and bring the robot to a rest if
nothing else drives it.

Note:
The damping task is implemented as a special case of the posture task
where the gain $\alpha$ is zero.
"""

def __init__(self, cost: float, lm_damping: float = 0.0) -> None:
def __init__(self, cost: float) -> None:
r"""Initialize task.

Args:
cost: joint angular velocity cost, in
:math:`[\mathrm{cost}] [\mathrm{s}] / [\mathrm{rad}]`.
lm_damping: Unitless scale of the Levenberg-Marquardt (only when
the error is large) regularization term, which helps when
targets are unfeasible. Increase this value if the task is too
jerky under unfeasible targets, but beware that too large a
damping can slow down the task.
"""
super().__init__(cost=cost, gain=0.0, lm_damping=lm_damping)
super().__init__(cost=cost, gain=0.0, lm_damping=0.0)

def compute_error(self, configuration: Configuration) -> np.ndarray:
r"""Compute damping task error.

The damping task error is defined as:

.. math::

e(q) = q_0 \ominus q,

where :math:`q_0` is the neutral configuration of the robot. The
damping task error is not relevant in itself, as the gain $\alpha$ of a
damping task is always zero. (Yet we still calculate it properly so
that the Jacobian is the derivative of the error, as unit tested.) See
:func:`Task.compute_error` for more context.

Args:
configuration: Robot configuration :math:`q`.

Returns:
Posture task error :math:`e(q)`.
Damping task error :math:`e(q) = 0`.
"""
_, nv = get_root_joint_dim(configuration.model)
return pin.difference(
configuration.model,
configuration.q,
pin.neutral(configuration.model),
)[nv:]
return np.zeros(configuration.model.nv)

def __repr__(self):
"""Human-readable representation of the task."""
return (
"DampingTask("
f"cost={self.cost}, "
f"lm_damping={self.lm_damping})"
)
return f"DampingTask(cost={self.cost})"
Loading