Skip to content

[fix] Generalize variable stiffness interface#51

Open
domrachev03 wants to merge 4 commits intolearnsyslab:mainfrom
KAIST-IRiS-Haptics-Telerobotics:fix/variable_stiffness
Open

[fix] Generalize variable stiffness interface#51
domrachev03 wants to merge 4 commits intolearnsyslab:mainfrom
KAIST-IRiS-Haptics-Telerobotics:fix/variable_stiffness

Conversation

@domrachev03
Copy link
Copy Markdown
Contributor

Variable stiffness: support full 6×6 matrix (back-compatible)

Summary

During the use of the new feature, I quickly realised that exposing only the diagonal elements of the stiffness matrix is very limiting. This PR extends the variable stiffness topic interface in both CartesianController (impedance) and CartesianAdmittanceController to accept a full 6×6 matrix in addition to the existing 6-element diagonal form. Adds symmetry validation and per-block magnitude bounds for the new path.

Topic protocol

target_stiffness and target_admittance_stiffness (std_msgs/Float64MultiArray) now accept either:

Size Interpretation Validation
6 Diagonal stiffness [k_pos_x, k_pos_y, k_pos_z, k_rot_x, k_rot_y, k_rot_z] (unchanged from main) Per-axis clamp
36 Row-major 6×6 matrix Symmetry check + per-block clamp
other dropped with throttled warning

6x6 checks & clamping

  1. Symmetry check — reject if max |K - K^T| > 1e-6 (logs the deviation and tolerance). Downstream code can assume K is symmetric.

  2. Per-element clamp — every entry is clamped according to its block:

    j < 3 (trans) j ≥ 3 (rot)
    i < 3 (trans) variable_max_*_stiffness.translational variable_max_*_stiffness.cross
    i ≥ 3 (rot) variable_max_*_stiffness.cross variable_max_*_stiffness.rotational
    • Diagonal entries clamped to [0, max] (stiffness must be non-negative).
    • Off-diagonals clamped to [-max, max] (coupling can be negative; magnitude bounded).
    • Bounds are symmetric in (i,j) / (j,i), so clamping preserves the symmetry check.

New YAML parameters

A single new cross field added to each existing stiffness-bound block. Defaults are conservative; existing diagonal-only configs are unaffected.

Controller Block New param Default
cartesian_controller variable_max_stiffness .cross 500.0
cartesian_admittance_controller variable_max_impedance_stiffness .cross 500.0
cartesian_admittance_controller variable_max_admittance_stiffness .cross 100.0

All three accept the bound [0, 5000].

Comment on lines +821 to +833
// Full 6x6 path: 36-element row-major matrix.
if (msg->data.size() == 36) {
Eigen::Matrix<double, 6, 6> K =
Eigen::Map<const Eigen::Matrix<double, 6, 6, Eigen::RowMajor>>(msg->data.data());

// Enforce symmetry: a physical stiffness matrix must satisfy K == K^T.
constexpr double kSymmetryTolerance = 1e-6;
const double max_asym = (K - K.transpose()).cwiseAbs().maxCoeff();
if (max_asym > kSymmetryTolerance) {
RCLCPP_WARN_THROTTLE(get_node()->get_logger(), *get_node()->get_clock(), 100,
"Topic impedance stiffness[%d]=%.1f out of [0, %.1f], clamping.", i, vals[i], max_k_rot);
vals[i] = std::clamp(vals[i], 0.0, max_k_rot);
"Topic impedance stiffness matrix not symmetric (max |K - K^T|=%.3g > %.1g), ignoring.",
max_asym, kSymmetryTolerance);
return;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of publishing 36 we could publish 21 elements and then we dont need an extra check. We are always sure that the matrix would be fine but this is more of an aesthetic thing

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could start adding a few common functions to these calls (like previously discussed) e.g. under utils/stiffness_processing.hpp (even if having a utils module is an antipattern but this is a different topic...) and have a function that handles the symmetry check (if we stick to doing symmetry check) and one for clamping stiffness values. As a small step to get common utils between controllers

Copy link
Copy Markdown
Collaborator

@danielsanjosepro danielsanjosepro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you a lot for this new contribution! I left a few comments fill free to contradict my request if you think differently :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants