Files
Mujoco_WASM/test/user/user_composite_test.cc
T
Yuval Tassa a264d0bc8b Add geom adhesion: contacts that pull, via translated friction cones.
https://youtu.be/GioWwB36XHI

The new geom attribute adhesion (units of force, signed; pair-level
override) translates the contact friction cone along its normal so
that the force origin lies strictly inside it. Consequences: each
contact can pull with up to the given force before breaking, and the
tangential friction budget becomes mu*(f_N + adhesion) -- the
Mohr-Coulomb yield condition with cohesion c = mu*adhesion -- so
lightly-squeezed grasps retain a guaranteed friction floor.

A translated cone factors exactly into {constant attractive force}
+ {original cone}, so no solver kernels change. The implementation is
this factorization: a constant attraction along contact normals
accumulated into the new mjData.qfrc_adhesion (summed into
qfrc_passive), plus a bias of adhesive contact rows' reference
acceleration (aref += R*adhesion), which makes resting penetration
exactly independent of adhesion. Contacts of adhesive pairs remain
active throughout the gap zone, producing rows with positive violation
whose reference acceleration pulls: a tether that resists pull-off
smoothly, captures objects released within the band into steady
contact, and detaches at the specified force. Adhesion values of the
two geoms combine by sum; explicit pairs override.

mj_contactForce reports the net interface force (cone force minus the
adhesive pull), whose normal component can now be negative. Negative
adhesion is allowed and produces a repulsive offset (air hockey).

PiperOrigin-RevId: 950858148
Change-Id: I879c08eba7ae501e5c0f8c2f807167344da4c2bc
2026-07-20 08:35:45 -07:00

114 lines
3.2 KiB
C++

// Copyright 2021 DeepMind Technologies Limited
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Tests for user/user_model.cc.
#include <array>
#include <cstddef>
#include <string>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <absl/strings/str_format.h>
#include "src/cc/array_safety.h"
#include <mujoco/mjdata.h>
#include <mujoco/mjmodel.h>
#include <mujoco/mujoco.h>
#include "test/fixture.h"
namespace mujoco {
namespace {
using ::testing::IsNull;
using ::testing::NotNull;
using ::testing::HasSubstr;
using UserCompositeTest = MujocoTest;
// ------------------------ cable tests ---------------------------------------
TEST_F(UserCompositeTest, ShapeCanBeOmitted) {
static constexpr char xml[] = R"(
<mujoco>
<worldbody>
<composite type="cable" count="100 1 1" curve="s">
<geom type="box" size="1 1 1"/>
</composite>
</worldbody>
</mujoco>
)";
std::array<char, 1024> error;
MjModelPtr m = LoadModelFromString(xml, error.data(), error.size());
EXPECT_THAT(m.get(), NotNull()) << error.data();
}
TEST_F(UserCompositeTest, GeomSurfacevel) {
static constexpr char xml[] = R"(
<mujoco>
<worldbody>
<composite type="cable" count="5 1 1" curve="s">
<geom type="capsule" size=".02" surfacevel="0 0 0 0 0 3"/>
</composite>
</worldbody>
</mujoco>
)";
std::array<char, 1024> error;
MjModelPtr m = LoadModelFromString(xml, error.data(), error.size());
ASSERT_THAT(m.get(), NotNull()) << error.data();
for (int g = 0; g < m->ngeom; g++) {
if (m->geom_type[g] == mjGEOM_CAPSULE) {
EXPECT_EQ(m->geom_surfacevel[6*g + 5], 3);
}
}
}
TEST_F(UserCompositeTest, GeomAdhesion) {
static constexpr char xml[] = R"(
<mujoco>
<worldbody>
<composite type="cable" count="5 1 1" curve="s">
<geom type="capsule" size=".02" adhesion="2"/>
</composite>
</worldbody>
</mujoco>
)";
std::array<char, 1024> error;
MjModelPtr m = LoadModelFromString(xml, error.data(), error.size());
ASSERT_THAT(m.get(), NotNull()) << error.data();
for (int g = 0; g < m->ngeom; g++) {
if (m->geom_type[g] == mjGEOM_CAPSULE) {
EXPECT_EQ(m->geom_adhesion[g], 2);
}
}
}
TEST_F(UserCompositeTest, InvalidShape) {
static constexpr char xml[] = R"(
<mujoco>
<worldbody>
<composite type="cable" count="100 1 1" curve="s s exp">
<geom type="box" size="1 1 1"/>
</composite>
</worldbody>
</mujoco>
)";
std::array<char, 1024> error;
MjModelPtr m = LoadModelFromString(xml, error.data(), error.size());
EXPECT_THAT(m.get(), IsNull()) << error.data();
EXPECT_THAT(error.data(),
HasSubstr("The curve array contains an invalid shape"));
}
} // namespace
} // namespace mujoco